31# define UINT_MAX 0xFFFFFFFF
33#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
40 return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var));
46 return ((params->byteorder==PTP_DL_LE)?htole32(var):htobe32(var));
50htod16ap (
PTPParams *params,
unsigned char *a, uint16_t val)
52 if (params->byteorder==PTP_DL_LE)
59htod32ap (
PTPParams *params,
unsigned char *a, uint32_t val)
61 if (params->byteorder==PTP_DL_LE)
68htod64ap (
PTPParams *params,
unsigned char *a, uint64_t val)
70 if (params->byteorder==PTP_DL_LE)
79 return ((params->byteorder==PTP_DL_LE)?le16toh(var):be16toh(var));
85 return ((params->byteorder==PTP_DL_LE)?le32toh(var):be32toh(var));
91 return ((params->byteorder==PTP_DL_LE)?le64toh(var):be64toh(var));
95dtoh16ap (
PTPParams *params,
const unsigned char *a)
97 return ((params->byteorder==PTP_DL_LE)?le16atoh(a):be16atoh(a));
100static inline uint32_t
101dtoh32ap (
PTPParams *params,
const unsigned char *a)
103 return ((params->byteorder==PTP_DL_LE)?le32atoh(a):be32atoh(a));
106static inline uint64_t
107dtoh64ap (
PTPParams *params,
const unsigned char *a)
109 return ((params->byteorder==PTP_DL_LE)?le64atoh(a):be64atoh(a));
112#define htod8a(a,x) *(uint8_t*)(a) = x
113#define htod16a(a,x) htod16ap(params,a,x)
114#define htod32a(a,x) htod32ap(params,a,x)
115#define htod64a(a,x) htod64ap(params,a,x)
116#define htod16(x) htod16p(params,x)
117#define htod32(x) htod32p(params,x)
118#define htod64(x) htod64p(params,x)
120#define dtoh8a(x) (*(uint8_t*)(x))
121#define dtoh16a(a) dtoh16ap(params,a)
122#define dtoh32a(a) dtoh32ap(params,a)
123#define dtoh64a(a) dtoh64ap(params,a)
124#define dtoh16(x) dtoh16p(params,x)
125#define dtoh32(x) dtoh32p(params,x)
126#define dtoh64(x) dtoh64p(params,x)
137ptp_unpack_string(
PTPParams *params,
unsigned char* data, uint16_t offset, uint32_t total, uint8_t *len,
char **retstr)
140 uint16_t
string[PTP_MAXSTRLEN+1];
142 char loclstr[PTP_MAXSTRLEN*3+1];
143 size_t nconv, srclen, destlen;
149 if (offset + 1 > total)
152 length = dtoh8a(&data[offset]);
158 if (offset + 1 + length*
sizeof(
string[0]) > total)
164 memcpy(
string, &data[offset+1], length *
sizeof(
string[0]));
165 string[length] = 0x0000U;
169 src = (
char *)
string;
170 srclen = length *
sizeof(
string[0]);
172 destlen =
sizeof(loclstr)-1;
174#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
175 if (params->cd_ucs2_to_locale != (iconv_t)-1)
176 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, &destlen);
178 if (nconv == (
size_t) -1) {
181 for (i=0;i<length;i++) {
182 if (dtoh16a(&data[offset+1+2*i])>127)
185 loclstr[i] = dtoh16a(&data[offset+1+2*i]);
187 dest = loclstr+length;
190 loclstr[
sizeof(loclstr)-1] =
'\0';
191 *retstr = strdup(loclstr);
196ucs2strlen(uint16_t
const *
const unicstr)
201 for(length = 0; unicstr[length] != 0x0000U; length ++);
207ptp_pack_string(
PTPParams *params,
char *
string,
unsigned char* data, uint16_t offset, uint8_t *len)
210 uint16_t ucs2str[PTP_MAXSTRLEN+1];
211 char *ucs2strp = (
char *) ucs2str;
212 size_t convlen = strlen(
string);
215 memset(ucs2strp, 0,
sizeof(ucs2str));
216#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
217 if (params->cd_locale_to_ucs2 != (iconv_t)-1) {
219 size_t convmax = PTP_MAXSTRLEN * 2;
220 char *stringp = string;
222 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen,
223 &ucs2strp, &convmax);
224 if (nconv == (
size_t) -1)
225 ucs2str[0] = 0x0000U;
231 for (i=0;i<convlen;i++) {
232 ucs2str[i] =
string[i];
234 ucs2str[convlen] = 0;
240 packedlen = ucs2strlen(ucs2str);
241 if (packedlen > PTP_MAXSTRLEN-1) {
247 htod8a(&data[offset],packedlen+1);
248 memcpy(&data[offset+1], &ucs2str[0], packedlen *
sizeof(ucs2str[0]));
249 htod16a(&data[offset+packedlen*2+1], 0x0000);
252 *len = (uint8_t) packedlen+1;
255static inline unsigned char *
256ptp_get_packed_stringcopy(
PTPParams *params,
char *
string, uint32_t *packed_size)
258 uint8_t packed[PTP_MAXSTRLEN*2+3], len;
260 unsigned char *retcopy = NULL;
263 ptp_pack_string(params,
"", (
unsigned char*) packed, 0, &len);
265 ptp_pack_string(params,
string, (
unsigned char*) packed, 0, &len);
270 retcopy = malloc(plen);
275 memcpy(retcopy, packed, plen);
280static inline uint32_t
281ptp_unpack_uint32_t_array(
PTPParams *params,
unsigned char* data,
unsigned int offset,
unsigned int datalen, uint32_t **array)
288 if (offset >= datalen)
291 if (offset +
sizeof(uint32_t) > datalen)
295 n=dtoh32a(&data[offset]);
296 if (n >= UINT_MAX/
sizeof(uint32_t))
301 if (offset +
sizeof(uint32_t)*(n+1) > datalen) {
302 ptp_debug (params ,
"array runs over datalen bufferend (%d vs %d)", offset +
sizeof(uint32_t)*(n+1) , datalen);
306 *array = malloc (n*
sizeof(uint32_t));
310 (*array)[i]=dtoh32a(&data[offset+(
sizeof(uint32_t)*(i+1))]);
314static inline uint32_t
315ptp_pack_uint32_t_array(
PTPParams *params, uint32_t *array, uint32_t arraylen,
unsigned char **data )
319 *data = malloc ((arraylen+1)*
sizeof(uint32_t));
322 htod32a(&(*data)[0],arraylen);
323 for (i=0;i<arraylen;i++)
324 htod32a(&(*data)[
sizeof(uint32_t)*(i+1)], array[i]);
325 return (arraylen+1)*
sizeof(uint32_t);
328static inline uint32_t
329ptp_unpack_uint16_t_array(
PTPParams *params,
unsigned char* data,
unsigned int offset,
unsigned int datalen, uint16_t **array)
337 if (datalen - offset <
sizeof(uint32_t))
339 n=dtoh32a(&data[offset]);
341 if (n >= (UINT_MAX - offset -
sizeof(uint32_t))/
sizeof(uint16_t))
345 if (offset +
sizeof(uint32_t) > datalen)
347 if (offset +
sizeof(uint32_t)+
sizeof(uint16_t)*n > datalen) {
348 ptp_debug (params ,
"array runs over datalen bufferend (%d vs %d)", offset +
sizeof(uint32_t)+n*
sizeof(uint16_t) , datalen);
351 *array = malloc (n*
sizeof(uint16_t));
355 (*array)[i]=dtoh16a(&data[offset+(
sizeof(uint16_t)*(i+2))]);
361#define PTP_di_StandardVersion 0
362#define PTP_di_VendorExtensionID 2
363#define PTP_di_VendorExtensionVersion 6
364#define PTP_di_VendorExtensionDesc 8
365#define PTP_di_FunctionalMode 8
366#define PTP_di_OperationsSupported 10
372 unsigned int totallen;
375 if (datalen < 12)
return 0;
376 memset (di, 0,
sizeof(*di));
377 di->StandardVersion = dtoh16a(&data[PTP_di_StandardVersion]);
378 di->VendorExtensionID =
379 dtoh32a(&data[PTP_di_VendorExtensionID]);
380 di->VendorExtensionVersion =
381 dtoh16a(&data[PTP_di_VendorExtensionVersion]);
382 if (!ptp_unpack_string(params, data,
383 PTP_di_VendorExtensionDesc,
386 &di->VendorExtensionDesc)
390 if (datalen <= totallen + PTP_di_FunctionalMode +
sizeof(uint16_t)) {
391 ptp_debug (params,
"datalen %d <= totallen + PTP_di_FunctionalMode + sizeof(uint16_t) %d", datalen, totallen + PTP_di_FunctionalMode +
sizeof(uint16_t));
395 dtoh16a(&data[PTP_di_FunctionalMode+totallen]);
396 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data,
397 PTP_di_OperationsSupported+totallen,
399 &di->OperationsSupported);
400 totallen=totallen+di->OperationsSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
401 if (datalen <= totallen+PTP_di_OperationsSupported) {
402 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 1", datalen, totallen+PTP_di_OperationsSupported);
405 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data,
406 PTP_di_OperationsSupported+totallen,
408 &di->EventsSupported);
409 totallen=totallen+di->EventsSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
410 if (datalen <= totallen+PTP_di_OperationsSupported) {
411 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 2", datalen, totallen+PTP_di_OperationsSupported);
414 di->DevicePropertiesSupported_len =
415 ptp_unpack_uint16_t_array(params, data,
416 PTP_di_OperationsSupported+totallen,
418 &di->DevicePropertiesSupported);
419 totallen=totallen+di->DevicePropertiesSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
420 if (datalen <= totallen+PTP_di_OperationsSupported) {
421 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 3", datalen, totallen+PTP_di_OperationsSupported);
424 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data,
425 PTP_di_OperationsSupported+totallen,
427 &di->CaptureFormats);
428 totallen=totallen+di->CaptureFormats_len*
sizeof(uint16_t)+
sizeof(uint32_t);
429 if (datalen <= totallen+PTP_di_OperationsSupported) {
430 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 4", datalen, totallen+PTP_di_OperationsSupported);
433 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data,
434 PTP_di_OperationsSupported+totallen,
437 totallen=totallen+di->ImageFormats_len*
sizeof(uint16_t)+
sizeof(uint32_t);
438 if (datalen <= totallen+PTP_di_OperationsSupported) {
439 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 5", datalen, totallen+PTP_di_OperationsSupported);
442 if (!ptp_unpack_string(params, data,
443 PTP_di_OperationsSupported+totallen,
451 if (datalen <= totallen+PTP_di_OperationsSupported) {
452 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 6", datalen, totallen+PTP_di_OperationsSupported);
455 if (!ptp_unpack_string(params, data,
456 PTP_di_OperationsSupported+totallen,
464 if (datalen <= totallen+PTP_di_OperationsSupported) {
465 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 7", datalen, totallen+PTP_di_OperationsSupported);
468 if (!ptp_unpack_string(params, data,
469 PTP_di_OperationsSupported+totallen,
477 if (datalen <= totallen+PTP_di_OperationsSupported) {
478 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 8", datalen, totallen+PTP_di_OperationsSupported);
481 if (!ptp_unpack_string(params, data,
482 PTP_di_OperationsSupported+totallen,
493 free (di->SerialNumber);
494 free (di->DeviceVersion);
496 free (di->Manufacturer);
497 free (di->ImageFormats);
498 free (di->CaptureFormats);
499 free (di->VendorExtensionDesc);
500 free (di->OperationsSupported);
501 free (di->EventsSupported);
502 free (di->DevicePropertiesSupported);
503 memset(di, 0,
sizeof(*di));
510 unsigned int totallen = 4;
512 memset (di,0,
sizeof(*di));
513 if (datalen < 8)
return 0;
516 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data,
517 totallen, datalen, &di->EventsSupported);
518 if (!di->EventsSupported)
return 0;
519 totallen += di->EventsSupported_len*
sizeof(uint32_t)+4;
520 if (totallen >= datalen)
return 0;
522 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, data,
523 totallen, datalen, &di->DevicePropertiesSupported);
524 if (!di->DevicePropertiesSupported)
return 0;
525 totallen += di->DevicePropertiesSupported_len*
sizeof(uint32_t)+4;
526 if (totallen >= datalen)
return 0;
528 di->unk_len = ptp_unpack_uint32_t_array(params, data,
529 totallen, datalen, &di->unk);
530 if (!di->unk)
return 0;
531 totallen += di->unk_len*
sizeof(uint32_t)+4;
538 free (di->EventsSupported);
539 free (di->DevicePropertiesSupported);
551 oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, len, &oh->Handler);
566 sids->Storage = NULL;
571 sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids, len, &sids->Storage);
576#define PTP_si_StorageType 0
577#define PTP_si_FilesystemType 2
578#define PTP_si_AccessCapability 4
579#define PTP_si_MaxCapability 6
580#define PTP_si_FreeSpaceInBytes 14
581#define PTP_si_FreeSpaceInImages 22
582#define PTP_si_StorageDescription 26
587 uint8_t storagedescriptionlen;
589 if (len < 26)
return 0;
590 si->StorageType=dtoh16a(&data[PTP_si_StorageType]);
591 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]);
592 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]);
593 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]);
594 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]);
595 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]);
598 if (!ptp_unpack_string(params, data,
599 PTP_si_StorageDescription,
601 &storagedescriptionlen,
602 &si->StorageDescription)
606 if (!ptp_unpack_string(params, data,
607 PTP_si_StorageDescription+storagedescriptionlen*2+1,
609 &storagedescriptionlen,
611 ptp_debug(params,
"could not unpack storage description");
619#define PTP_oi_StorageID 0
620#define PTP_oi_ObjectFormat 4
621#define PTP_oi_ProtectionStatus 6
622#define PTP_oi_ObjectCompressedSize 8
623#define PTP_oi_ThumbFormat 12
624#define PTP_oi_ThumbCompressedSize 14
625#define PTP_oi_ThumbPixWidth 18
626#define PTP_oi_ThumbPixHeight 22
627#define PTP_oi_ImagePixWidth 26
628#define PTP_oi_ImagePixHeight 30
629#define PTP_oi_ImageBitDepth 34
630#define PTP_oi_ParentObject 38
631#define PTP_oi_AssociationType 42
632#define PTP_oi_AssociationDesc 44
633#define PTP_oi_SequenceNumber 48
634#define PTP_oi_filenamelen 52
635#define PTP_oi_Filename 53
639#define PTP_oi_MaxLen PTP_oi_Filename+(PTP_MAXSTRLEN+1)*2+3
641static inline uint32_t
644 unsigned char* oidata;
646 uint8_t capturedatelen=0;
648 oidata=malloc(PTP_oi_MaxLen + params->ocs64*4);
652 char *capture_date=
"20020101T010101";
654 memset (oidata, 0, PTP_oi_MaxLen + params->ocs64*4);
655 htod32a(&oidata[PTP_oi_StorageID],oi->StorageID);
656 htod16a(&oidata[PTP_oi_ObjectFormat],oi->ObjectFormat);
657 htod16a(&oidata[PTP_oi_ProtectionStatus],oi->ProtectionStatus);
658 htod32a(&oidata[PTP_oi_ObjectCompressedSize],oi->ObjectCompressedSize);
661 htod16a(&oidata[PTP_oi_ThumbFormat],oi->ThumbFormat);
662 htod32a(&oidata[PTP_oi_ThumbCompressedSize],oi->ThumbCompressedSize);
663 htod32a(&oidata[PTP_oi_ThumbPixWidth],oi->ThumbPixWidth);
664 htod32a(&oidata[PTP_oi_ThumbPixHeight],oi->ThumbPixHeight);
665 htod32a(&oidata[PTP_oi_ImagePixWidth],oi->ImagePixWidth);
666 htod32a(&oidata[PTP_oi_ImagePixHeight],oi->ImagePixHeight);
667 htod32a(&oidata[PTP_oi_ImageBitDepth],oi->ImageBitDepth);
668 htod32a(&oidata[PTP_oi_ParentObject],oi->ParentObject);
669 htod16a(&oidata[PTP_oi_AssociationType],oi->AssociationType);
670 htod32a(&oidata[PTP_oi_AssociationDesc],oi->AssociationDesc);
671 htod32a(&oidata[PTP_oi_SequenceNumber],oi->SequenceNumber);
673 ptp_pack_string(params, oi->Filename, oidata, PTP_oi_filenamelen, &filenamelen);
687 capturedatelen=strlen(capture_date);
688 htod8a(&data[PTP_oi_Filename+(filenamelen+1)*2],
690 for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
691 data[PTP_oi_Filename+(i+filenamelen+1)*2+1]=capture_date[i];
693 htod8a(&data[PTP_oi_Filename+(filenamelen+capturedatelen+2)*2+1],
695 for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
696 data[PTP_oi_Filename+(i+filenamelen+capturedatelen+2)*2+2]=
701 return (PTP_oi_Filename+filenamelen*2+(capturedatelen+1)*3)+params->ocs64*4;
705ptp_unpack_PTPTIME (
const char *str) {
713 ptpdatelen = strlen(str);
714 if (ptpdatelen >=
sizeof (ptpdate)) {
722 strncpy (ptpdate, str,
sizeof(ptpdate));
723 ptpdate[
sizeof(ptpdate) - 1] =
'\0';
725 memset(&tm,0,
sizeof(tm));
726 strncpy (tmp, ptpdate, 4);
728 tm.tm_year=atoi (tmp) - 1900;
729 strncpy (tmp, ptpdate + 4, 2);
731 tm.tm_mon = atoi (tmp) - 1;
732 strncpy (tmp, ptpdate + 6, 2);
734 tm.tm_mday = atoi (tmp);
735 strncpy (tmp, ptpdate + 9, 2);
737 tm.tm_hour = atoi (tmp);
738 strncpy (tmp, ptpdate + 11, 2);
740 tm.tm_min = atoi (tmp);
741 strncpy (tmp, ptpdate + 13, 2);
743 tm.tm_sec = atoi (tmp);
752 uint8_t capturedatelen;
755 if (len < PTP_oi_SequenceNumber)
758 oi->Filename = oi->Keywords = NULL;
761 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]);
762 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]);
763 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]);
764 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]);
767 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)) {
768 ptp_debug (params,
"objectsize 64bit detected!");
773 oi->ThumbFormat=dtoh16a(&data[PTP_oi_ThumbFormat]);
774 oi->ThumbCompressedSize=dtoh32a(&data[PTP_oi_ThumbCompressedSize]);
775 oi->ThumbPixWidth=dtoh32a(&data[PTP_oi_ThumbPixWidth]);
776 oi->ThumbPixHeight=dtoh32a(&data[PTP_oi_ThumbPixHeight]);
777 oi->ImagePixWidth=dtoh32a(&data[PTP_oi_ImagePixWidth]);
778 oi->ImagePixHeight=dtoh32a(&data[PTP_oi_ImagePixHeight]);
779 oi->ImageBitDepth=dtoh32a(&data[PTP_oi_ImageBitDepth]);
780 oi->ParentObject=dtoh32a(&data[PTP_oi_ParentObject]);
781 oi->AssociationType=dtoh16a(&data[PTP_oi_AssociationType]);
782 oi->AssociationDesc=dtoh32a(&data[PTP_oi_AssociationDesc]);
783 oi->SequenceNumber=dtoh32a(&data[PTP_oi_SequenceNumber]);
785 ptp_unpack_string(params, data, PTP_oi_filenamelen, len, &filenamelen, &oi->Filename);
786 ptp_unpack_string(params, data, PTP_oi_filenamelen+filenamelen*2+1, len, &capturedatelen, &capture_date);
790 oi->CaptureDate = ptp_unpack_PTPTIME(capture_date);
794 ptp_unpack_string(params, data,
795 PTP_oi_filenamelen+filenamelen*2
796 +capturedatelen*2+2, len, &capturedatelen, &capture_date
798 oi->ModificationDate = ptp_unpack_PTPTIME(capture_date);
803#define CTVAL(target,func) { \
804 if (total - *offset < sizeof(target)) \
806 target = func(&data[*offset]); \
807 *offset += sizeof(target); \
810#define RARR(val,member,func) { \
812 if (total - *offset < sizeof(uint32_t)) \
814 n = dtoh32a (&data[*offset]); \
815 *offset += sizeof(uint32_t); \
817 if (n >= UINT_MAX/sizeof(val->a.v[0])) \
819 if (n > (total - (*offset))/sizeof(val->a.v[0]))\
822 val->a.v = malloc(sizeof(val->a.v[0])*n); \
823 if (!val->a.v) return 0; \
825 CTVAL(val->a.v[j].member, func); \
828static inline unsigned int
830 PTPParams *params,
unsigned char* data,
unsigned int *offset,
unsigned int total,
833 if (*offset >= total)
838 CTVAL(value->i8,dtoh8a);
841 CTVAL(value->u8,dtoh8a);
844 CTVAL(value->i16,dtoh16a);
847 CTVAL(value->u16,dtoh16a);
850 CTVAL(value->i32,dtoh32a);
853 CTVAL(value->u32,dtoh32a);
856 CTVAL(value->i64,dtoh64a);
859 CTVAL(value->u64,dtoh64a);
862 case PTP_DTC_UINT128:
874 RARR(value,i8,dtoh8a);
877 RARR(value,u8,dtoh8a);
879 case PTP_DTC_AUINT16:
880 RARR(value,u16,dtoh16a);
883 RARR(value,i16,dtoh16a);
885 case PTP_DTC_AUINT32:
886 RARR(value,u32,dtoh32a);
889 RARR(value,i32,dtoh32a);
891 case PTP_DTC_AUINT64:
892 RARR(value,u64,dtoh64a);
895 RARR(value,i64,dtoh64a);
903 if (*offset >= total+1)
906 if (!ptp_unpack_string(params,data,*offset,total,&len,&value->str))
918#define PTP_dpd_DevicePropertyCode 0
919#define PTP_dpd_DataType 2
920#define PTP_dpd_GetSet 4
921#define PTP_dpd_FactoryDefaultValue 5
926 unsigned int offset = 0, ret;
928 memset (dpd, 0,
sizeof(*dpd));
931 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]);
932 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]);
933 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]);
934 dpd->FormFlag=PTP_DPFF_None;
936 offset = PTP_dpd_FactoryDefaultValue;
937 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaultValue, dpd->DataType);
938 if (!ret)
goto outofmemory;
939 if ((dpd->DataType == PTP_DTC_STR) && (offset == dpdlen))
941 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->CurrentValue, dpd->DataType);
942 if (!ret)
goto outofmemory;
949 if (offset +
sizeof(uint8_t) > dpdlen)
952 dpd->FormFlag=dtoh8a(&data[offset]);
953 offset+=
sizeof(uint8_t);
955 switch (dpd->FormFlag) {
957 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MinimumValue, dpd->DataType);
958 if (!ret)
goto outofmemory;
959 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MaximumValue, dpd->DataType);
960 if (!ret)
goto outofmemory;
961 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.StepSize, dpd->DataType);
962 if (!ret)
goto outofmemory;
964 case PTP_DPFF_Enumeration: {
966#define N dpd->FORM.Enum.NumberOfValues
968 if (offset +
sizeof(uint16_t) > dpdlen)
goto outofmemory;
970 N = dtoh16a(&data[offset]);
971 offset+=
sizeof(uint16_t);
972 dpd->FORM.Enum.SupportedValue = malloc(N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
973 if (!dpd->FORM.Enum.SupportedValue)
976 memset (dpd->FORM.Enum.SupportedValue,0 , N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
978 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);
988 dpd->FORM.Enum.NumberOfValues = i;
997 ptp_free_devicepropdesc(dpd);
1002#define PTP_dpd_Sony_DevicePropertyCode 0
1003#define PTP_dpd_Sony_DataType 2
1004#define PTP_dpd_Sony_GetSet 4
1005#define PTP_dpd_Sony_Unknown 5
1006#define PTP_dpd_Sony_FactoryDefaultValue 6
1009ptp_unpack_Sony_DPD (
PTPParams *params,
unsigned char* data,
PTPDevicePropDesc *dpd,
unsigned int dpdlen,
unsigned int *poffset)
1013 unsigned int unk1, unk2;
1016 memset (dpd, 0,
sizeof(*dpd));
1017 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_Sony_DevicePropertyCode]);
1018 dpd->DataType=dtoh16a(&data[PTP_dpd_Sony_DataType]);
1022 unk1 = dtoh8a(&data[PTP_dpd_Sony_GetSet]);
1023 unk2 = dtoh8a(&data[PTP_dpd_Sony_Unknown]);
1024 ptp_debug (params,
"prop 0x%04x, datatype 0x%04x, unk1 %d unk2 %d", dpd->DevicePropertyCode, dpd->DataType, unk1, unk2);
1028 dpd->FormFlag=PTP_DPFF_None;
1030 *poffset = PTP_dpd_Sony_FactoryDefaultValue;
1031 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FactoryDefaultValue, dpd->DataType);
1032 if (!ret)
goto outofmemory;
1033 if ((dpd->DataType == PTP_DTC_STR) && (*poffset == dpdlen))
1035 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->CurrentValue, dpd->DataType);
1036 if (!ret)
goto outofmemory;
1043 if (*poffset==PTP_dpd_Sony_FactoryDefaultValue)
1046 dpd->FormFlag=dtoh8a(&data[*poffset]);
1047 *poffset+=
sizeof(uint8_t);
1049 switch (dpd->FormFlag) {
1050 case PTP_DPFF_Range:
1051 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.MinimumValue, dpd->DataType);
1052 if (!ret)
goto outofmemory;
1053 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.MaximumValue, dpd->DataType);
1054 if (!ret)
goto outofmemory;
1055 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.StepSize, dpd->DataType);
1056 if (!ret)
goto outofmemory;
1058 case PTP_DPFF_Enumeration: {
1060#define N dpd->FORM.Enum.NumberOfValues
1061 N = dtoh16a(&data[*poffset]);
1062 *poffset+=
sizeof(uint16_t);
1063 dpd->FORM.Enum.SupportedValue = malloc(N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
1064 if (!dpd->FORM.Enum.SupportedValue)
1067 memset (dpd->FORM.Enum.SupportedValue,0 , N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
1069 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);
1079 dpd->FORM.Enum.NumberOfValues = i;
1088 ptp_free_devicepropdesc(dpd);
1094 if (type == PTP_DTC_STR) {
1096 dst->str = strdup(src->str);
1102 if (type & PTP_DTC_ARRAY_MASK) {
1105 dst->a.count = src->a.count;
1106 dst->a.v = malloc (
sizeof(src->a.v[0])*src->a.count);
1107 for (i=0;i<src->a.count;i++)
1108 duplicate_PropertyValue (&src->a.v[i], &dst->a.v[i], type & ~PTP_DTC_ARRAY_MASK);
1111 switch (type & ~PTP_DTC_ARRAY_MASK) {
1112 case PTP_DTC_INT8: dst->i8 = src->i8;
break;
1113 case PTP_DTC_UINT8: dst->u8 = src->u8;
break;
1114 case PTP_DTC_INT16: dst->i16 = src->i16;
break;
1115 case PTP_DTC_UINT16: dst->u16 = src->u16;
break;
1116 case PTP_DTC_INT32: dst->i32 = src->i32;
break;
1117 case PTP_DTC_UINT32: dst->u32 = src->u32;
break;
1118 case PTP_DTC_UINT64: dst->u64 = src->u64;
break;
1119 case PTP_DTC_INT64: dst->i64 = src->i64;
break;
1121 case PTP_DTC_INT128: dst->i128 = src->i128;
break;
1122 case PTP_DTC_UINT128: dst->u128 = src->u128;
break;
1133 dst->DevicePropertyCode = src->DevicePropertyCode;
1134 dst->DataType = src->DataType;
1135 dst->GetSet = src->GetSet;
1137 duplicate_PropertyValue (&src->FactoryDefaultValue, &dst->FactoryDefaultValue, src->DataType);
1138 duplicate_PropertyValue (&src->CurrentValue, &dst->CurrentValue, src->DataType);
1140 dst->FormFlag = src->FormFlag;
1141 switch (src->FormFlag) {
1142 case PTP_DPFF_Range:
1143 duplicate_PropertyValue (&src->FORM.Range.MinimumValue, &dst->FORM.Range.MinimumValue, src->DataType);
1144 duplicate_PropertyValue (&src->FORM.Range.MaximumValue, &dst->FORM.Range.MaximumValue, src->DataType);
1145 duplicate_PropertyValue (&src->FORM.Range.StepSize, &dst->FORM.Range.StepSize, src->DataType);
1147 case PTP_DPFF_Enumeration:
1148 dst->FORM.Enum.NumberOfValues = src->FORM.Enum.NumberOfValues;
1149 dst->FORM.Enum.SupportedValue = malloc (
sizeof(dst->FORM.Enum.SupportedValue[0])*src->FORM.Enum.NumberOfValues);
1150 for (i = 0; i<src->FORM.Enum.NumberOfValues ; i++)
1151 duplicate_PropertyValue (&src->FORM.Enum.SupportedValue[i], &dst->FORM.Enum.SupportedValue[i], src->DataType);
1158#define PTP_opd_ObjectPropertyCode 0
1159#define PTP_opd_DataType 2
1160#define PTP_opd_GetSet 4
1161#define PTP_opd_FactoryDefaultValue 5
1166 unsigned int offset=0, ret;
1168 memset (opd, 0,
sizeof(*opd));
1173 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]);
1174 opd->DataType=dtoh16a(&data[PTP_opd_DataType]);
1175 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]);
1177 offset = PTP_opd_FactoryDefaultValue;
1178 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
1179 if (!ret)
goto outofmemory;
1181 if (offset +
sizeof(uint32_t) > opdlen)
goto outofmemory;
1182 opd->GroupCode=dtoh32a(&data[offset]);
1183 offset+=
sizeof(uint32_t);
1185 if (offset +
sizeof(uint8_t) > opdlen)
goto outofmemory;
1186 opd->FormFlag=dtoh8a(&data[offset]);
1187 offset+=
sizeof(uint8_t);
1189 switch (opd->FormFlag) {
1190 case PTP_OPFF_Range:
1191 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
1192 if (!ret)
goto outofmemory;
1193 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
1194 if (!ret)
goto outofmemory;
1195 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
1196 if (!ret)
goto outofmemory;
1198 case PTP_OPFF_Enumeration: {
1200#define N opd->FORM.Enum.NumberOfValues
1202 if (offset +
sizeof(uint16_t) > opdlen)
goto outofmemory;
1203 N = dtoh16a(&data[offset]);
1204 offset+=
sizeof(uint16_t);
1206 opd->FORM.Enum.SupportedValue = malloc(N*
sizeof(opd->FORM.Enum.SupportedValue[0]));
1207 if (!opd->FORM.Enum.SupportedValue)
1210 memset (opd->FORM.Enum.SupportedValue,0 , N*
sizeof(opd->FORM.Enum.SupportedValue[0]));
1212 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
1222 opd->FORM.Enum.NumberOfValues = i;
1231 ptp_free_objectpropdesc(opd);
1236static inline uint32_t
1239 unsigned char* dpv=NULL;
1245 size=
sizeof(int8_t);
1247 htod8a(dpv,value->i8);
1250 size=
sizeof(uint8_t);
1252 htod8a(dpv,value->u8);
1255 size=
sizeof(int16_t);
1257 htod16a(dpv,value->i16);
1259 case PTP_DTC_UINT16:
1260 size=
sizeof(uint16_t);
1262 htod16a(dpv,value->u16);
1265 size=
sizeof(int32_t);
1267 htod32a(dpv,value->i32);
1269 case PTP_DTC_UINT32:
1270 size=
sizeof(uint32_t);
1272 htod32a(dpv,value->u32);
1275 size=
sizeof(int64_t);
1277 htod64a(dpv,value->i64);
1279 case PTP_DTC_UINT64:
1280 size=
sizeof(uint64_t);
1282 htod64a(dpv,value->u64);
1284 case PTP_DTC_AUINT8:
1285 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint8_t);
1287 htod32a(dpv,value->a.count);
1288 for (i=0;i<value->a.count;i++)
1289 htod8a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint8_t)],value->a.v[i].u8);
1292 size=
sizeof(uint32_t)+value->a.count*
sizeof(int8_t);
1294 htod32a(dpv,value->a.count);
1295 for (i=0;i<value->a.count;i++)
1296 htod8a(&dpv[
sizeof(uint32_t)+i*
sizeof(int8_t)],value->a.v[i].i8);
1298 case PTP_DTC_AUINT16:
1299 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint16_t);
1301 htod32a(dpv,value->a.count);
1302 for (i=0;i<value->a.count;i++)
1303 htod16a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint16_t)],value->a.v[i].u16);
1305 case PTP_DTC_AINT16:
1306 size=
sizeof(uint32_t)+value->a.count*
sizeof(int16_t);
1308 htod32a(dpv,value->a.count);
1309 for (i=0;i<value->a.count;i++)
1310 htod16a(&dpv[
sizeof(uint32_t)+i*
sizeof(int16_t)],value->a.v[i].i16);
1312 case PTP_DTC_AUINT32:
1313 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint32_t);
1315 htod32a(dpv,value->a.count);
1316 for (i=0;i<value->a.count;i++)
1317 htod32a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint32_t)],value->a.v[i].u32);
1319 case PTP_DTC_AINT32:
1320 size=
sizeof(uint32_t)+value->a.count*
sizeof(int32_t);
1322 htod32a(dpv,value->a.count);
1323 for (i=0;i<value->a.count;i++)
1324 htod32a(&dpv[
sizeof(uint32_t)+i*
sizeof(int32_t)],value->a.v[i].i32);
1326 case PTP_DTC_AUINT64:
1327 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint64_t);
1329 htod32a(dpv,value->a.count);
1330 for (i=0;i<value->a.count;i++)
1331 htod64a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint64_t)],value->a.v[i].u64);
1333 case PTP_DTC_AINT64:
1334 size=
sizeof(uint32_t)+value->a.count*
sizeof(int64_t);
1336 htod32a(dpv,value->a.count);
1337 for (i=0;i<value->a.count;i++)
1338 htod64a(&dpv[
sizeof(uint32_t)+i*
sizeof(int64_t)],value->a.v[i].i64);
1342 dpv=ptp_get_packed_stringcopy(params, value->str, &size);
1350#define MAX_MTP_PROPS 127
1351static inline uint32_t
1354 unsigned char* opldata;
1356 unsigned char *packedprops[MAX_MTP_PROPS];
1357 uint32_t packedpropslens[MAX_MTP_PROPS];
1358 uint32_t packedobjecthandles[MAX_MTP_PROPS];
1359 uint16_t packedpropsids[MAX_MTP_PROPS];
1360 uint16_t packedpropstypes[MAX_MTP_PROPS];
1361 uint32_t totalsize = 0;
1363 uint32_t noitems = 0;
1366 totalsize =
sizeof(uint32_t);
1368 while (nrofprops-- && noitems < MAX_MTP_PROPS) {
1370 packedobjecthandles[noitems]=propitr->ObjectHandle;
1371 totalsize +=
sizeof(uint32_t);
1373 packedpropsids[noitems]=propitr->property;
1374 totalsize +=
sizeof(uint16_t);
1376 packedpropstypes[noitems]= propitr->datatype;
1377 totalsize +=
sizeof(uint16_t);
1379 packedpropslens[noitems] = ptp_pack_DPV (params, &propitr->propval, &packedprops[noitems], propitr->datatype);
1380 totalsize += packedpropslens[noitems];
1386 opldata = malloc(totalsize);
1388 htod32a(&opldata[bufp],noitems);
1392 for (i = 0; i < noitems; i++) {
1394 htod32a(&opldata[bufp],packedobjecthandles[i]);
1395 bufp +=
sizeof(uint32_t);
1396 htod16a(&opldata[bufp],packedpropsids[i]);
1397 bufp +=
sizeof(uint16_t);
1398 htod16a(&opldata[bufp],packedpropstypes[i]);
1399 bufp +=
sizeof(uint16_t);
1401 memcpy(&opldata[bufp], packedprops[i], packedpropslens[i]);
1402 bufp += packedpropslens[i];
1403 free(packedprops[i]);
1405 *opldataptr = opldata;
1410_compare_func(
const void* x,
const void *y) {
1414 return px->ObjectHandle - py->ObjectHandle;
1420 uint32_t prop_count;
1422 unsigned int offset = 0, i;
1424 if (len <
sizeof(uint32_t)) {
1425 ptp_debug (params ,
"must have at least 4 bytes data, not %d", len);
1429 prop_count = dtoh32a(data);
1431 if (prop_count == 0)
1435 ptp_debug (params ,
"prop_count %d is too large", prop_count);
1438 ptp_debug (params ,
"Unpacking MTP OPL, size %d (prop_count %d)", len, prop_count);
1440 data +=
sizeof(uint32_t);
1441 len -=
sizeof(uint32_t);
1443 if (!props)
return 0;
1444 for (i = 0; i < prop_count; i++) {
1445 if (len <= (
sizeof(uint32_t) +
sizeof(uint16_t) +
sizeof(uint16_t))) {
1446 ptp_debug (params ,
"short MTP Object Property List at property %d (of %d)", i, prop_count);
1447 ptp_debug (params ,
"device probably needs DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL");
1448 ptp_debug (params ,
"or even DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST", i);
1455 props[i].ObjectHandle = dtoh32a(data);
1456 data +=
sizeof(uint32_t);
1457 len -=
sizeof(uint32_t);
1459 props[i].property = dtoh16a(data);
1460 data +=
sizeof(uint16_t);
1461 len -=
sizeof(uint16_t);
1463 props[i].datatype = dtoh16a(data);
1464 data +=
sizeof(uint16_t);
1465 len -=
sizeof(uint16_t);
1468 if (!ptp_unpack_DPV(params, data, &offset, len, &props[i].propval, props[i].datatype)) {
1469 ptp_debug (params ,
"unpacking DPV of property %d encountered insufficient buffer. attack?", i);
1477 qsort (props, prop_count,
sizeof(
MTPProperties),_compare_func);
1487#define PTP_ec_Length 0
1488#define PTP_ec_Type 4
1489#define PTP_ec_Code 6
1490#define PTP_ec_TransId 8
1491#define PTP_ec_Param1 12
1492#define PTP_ec_Param2 16
1493#define PTP_ec_Param3 20
1498 unsigned int length;
1503 memset(ec,0,
sizeof(*ec));
1505 length=dtoh32a(&data[PTP_ec_Length]);
1507 ptp_debug (params,
"length %d in container, but data only %d bytes?!", length, len);
1510 type = dtoh16a(&data[PTP_ec_Type]);
1512 ec->Code=dtoh16a(&data[PTP_ec_Code]);
1513 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]);
1515 if (type!=PTP_USB_CONTAINER_EVENT) {
1516 ptp_debug (params,
"Unknown canon event type %d (code=%x,tid=%x), please report!",type,ec->Code,ec->Transaction_ID);
1519 if (length>=(PTP_ec_Param1+4)) {
1520 ec->Param1=dtoh32a(&data[PTP_ec_Param1]);
1523 if (length>=(PTP_ec_Param2+4)) {
1524 ec->Param2=dtoh32a(&data[PTP_ec_Param2]);
1527 if (length>=(PTP_ec_Param3+4)) {
1528 ec->Param3=dtoh32a(&data[PTP_ec_Param3]);
1537#define PTP_cfe_ObjectHandle 0
1538#define PTP_cfe_ObjectFormatCode 4
1539#define PTP_cfe_Flags 6
1540#define PTP_cfe_ObjectSize 7
1541#define PTP_cfe_Time 11
1542#define PTP_cfe_Filename 15
1550 fe->ObjectHandle=dtoh32a(&data[PTP_cfe_ObjectHandle]);
1551 fe->ObjectFormatCode=dtoh16a(&data[PTP_cfe_ObjectFormatCode]);
1552 fe->Flags=dtoh8a(&data[PTP_cfe_Flags]);
1553 fe->ObjectSize=dtoh32a((
unsigned char*)&data[PTP_cfe_ObjectSize]);
1554 fe->Time=(time_t)dtoh32a(&data[PTP_cfe_Time]);
1555 for (i=0; i<PTP_CANON_FilenameBufferLen; i++)
1556 fe->Filename[i]=(
char)dtoh8a(&data[PTP_cfe_Filename+i]);
1611#define PTP_cefe_ObjectHandle 0
1612#define PTP_cefe_StorageID 4
1613#define PTP_cefe_ObjectFormatCode 8
1614#define PTP_cefe_Flags 16
1615#define PTP_cefe_ObjectSize 20
1616#define PTP_cefe_Filename 32
1617#define PTP_cefe_Time 48
1624 if (size < PTP_cefe_Time + 4)
return;
1626 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]);
1627 fe->ObjectFormatCode=dtoh16a(&data[PTP_cefe_ObjectFormatCode]);
1628 fe->Flags=dtoh8a(&data[PTP_cefe_Flags]);
1629 fe->ObjectSize=dtoh32a((
unsigned char*)&data[PTP_cefe_ObjectSize]);
1630 fe->Time=(time_t)dtoh32a(&data[PTP_cefe_Time]);
1631 for (i=0; i<PTP_CANON_FilenameBufferLen; i++)
1632 fe->Filename[i]=(
char)data[PTP_cefe_Filename+i];
1633 fe->Filename[PTP_CANON_FilenameBufferLen-1] = 0;
1637static inline uint16_t
1638ptp_unpack_EOS_ImageFormat (
PTPParams* params,
unsigned char** data )
1670 const unsigned char* d = *data;
1671 uint32_t n = dtoh32a( d );
1672 uint32_t l, t1, s1, c1, t2 = 0, s2 = 0, c2 = 0;
1674 if (n != 1 && n !=2) {
1675 ptp_debug (params,
"parsing EOS ImageFormat property failed (n != 1 && n != 2: %d)", n);
1679 l = dtoh32a( d+=4 );
1681 ptp_debug (params,
"parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
1685 t1 = dtoh32a( d+=4 );
1686 s1 = dtoh32a( d+=4 );
1687 c1 = dtoh32a( d+=4 );
1690 l = dtoh32a( d+=4 );
1692 ptp_debug (params,
"parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
1695 t2 = dtoh32a( d+=4 );
1696 s2 = dtoh32a( d+=4 );
1697 c2 = dtoh32a( d+=4 );
1700 *data = (
unsigned char*) d+4;
1709 c1 |= (t1 == 6) ? 8 : 0;
1710 c2 |= (t2 == 6) ? 8 : 0;
1712 return ((s1 & 0xF) << 12) | ((c1 & 0xF) << 8) | ((s2 & 0xF) << 4) | ((c2 & 0xF) << 0);
1715static inline uint32_t
1716ptp_pack_EOS_ImageFormat (
PTPParams* params,
unsigned char* data, uint16_t value)
1718 uint32_t n = (value & 0xFF) ? 2 : 1;
1719 uint32_t s = 4 + 0x10 * n;
1724#define PACK_5DM3_SMALL_JPEG_SIZE( X ) (X) >= 0xd ? (X)+1 : (X)
1726 htod32a(data+=0, n);
1727 htod32a(data+=4, 0x10);
1728 htod32a(data+=4, (((value >> 8) & 0xF) >> 3) ? 6 : 1);
1729 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 12) & 0xF));
1730 htod32a(data+=4, ((value >> 8) & 0xF) & ~8);
1733 htod32a(data+=4, 0x10);
1734 htod32a(data+=4, (((value >> 0) & 0xF) >> 3) ? 6 : 1);
1735 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF));
1736 htod32a(data+=4, ((value >> 0) & 0xF) & ~8);
1739#undef PACK_5DM3_SMALL_JPEG_SIZE
1763ptp_unpack_EOS_FocusInfoEx (
PTPParams* params,
unsigned char** data, uint32_t datasize )
1765 uint32_t size = dtoh32a( *data );
1766 uint32_t halfsize = dtoh16a( (*data) + 4);
1767 uint32_t version = dtoh16a( (*data) + 6);
1768 uint32_t focus_points_in_struct = dtoh16a( (*data) + 8);
1769 uint32_t focus_points_in_use = dtoh16a( (*data) + 10);
1770 uint32_t sizeX = dtoh16a( (*data) + 12);
1771 uint32_t sizeY = dtoh16a( (*data) + 14);
1772 uint32_t size2X = dtoh16a( (*data) + 16);
1773 uint32_t size2Y = dtoh16a( (*data) + 18);
1778 if ((size >= datasize) || (size < 20))
1779 return strdup(
"bad size 1");
1782 if (!focus_points_in_struct || !focus_points_in_use) {
1783 ptp_debug(params,
"skipped FocusInfoEx data (zero filled)");
1784 return strdup(
"no focus points returned by camera");
1791 if (size < focus_points_in_struct*8) {
1792 ptp_error(params,
"focus_points_in_struct %d is too large vs size %d", focus_points_in_struct, size);
1793 return strdup(
"bad size 2");
1795 if (focus_points_in_use > focus_points_in_struct) {
1796 ptp_error(params,
"focus_points_in_use %d is larger than focus_points_in_struct %d", focus_points_in_use, focus_points_in_struct);
1797 return strdup(
"bad size 3");
1800 maxlen = focus_points_in_use*32 + 100 + (size - focus_points_in_struct*8)*2;
1801 if (halfsize != size-4) {
1802 ptp_error(params,
"halfsize %d is not expected %d", halfsize, size-4);
1803 return strdup(
"bad size 4");
1805 if (20 + focus_points_in_struct*8 + (focus_points_in_struct+7)/8 > size) {
1806 ptp_error(params,
"size %d is too large for fp in struct %d", focus_points_in_struct*8 + 20 + (focus_points_in_struct+7)/8, size);
1807 return strdup(
"bad size 5");
1810 ptp_debug(params,
"d1d3 content:");
1811 for (i=0;i<size;i+=2)
1812 ptp_debug(params,
"%d: %02x %02x", i, (*data)[i], (*data)[i+1]);
1814 ptp_debug(params,
"d1d3 version %d", version);
1815 ptp_debug(params,
"d1d3 size %d", size);
1816 ptp_debug(params,
"d1d3 focus points in struct %d, in use %d", focus_points_in_struct, focus_points_in_use);
1818 str = (
char*)malloc( maxlen );
1823 p += sprintf(p,
"eosversion=%u,size=%ux%u,size2=%ux%u,points={", version, sizeX, sizeY, size2X, size2Y);
1824 for (i=0;i<focus_points_in_use;i++) {
1825 int16_t x = dtoh16a((*data) + focus_points_in_struct*4 + 20 + 2*i);
1826 int16_t y = dtoh16a((*data) + focus_points_in_struct*6 + 20 + 2*i);
1827 int16_t w = dtoh16a((*data) + focus_points_in_struct*2 + 20 + 2*i);
1828 int16_t h = dtoh16a((*data) + focus_points_in_struct*0 + 20 + 2*i);
1830 p += sprintf(p,
"{%d,%d,%d,%d}",x,y,w,h);
1832 if (i<focus_points_in_use-1)
1833 p += sprintf(p,
",");
1835 p += sprintf(p,
"},select={");
1836 for (i=0;i<focus_points_in_use;i++) {
1837 if ((1<<(i%8)) & ((*data)[focus_points_in_struct*8+20+i/8]))
1838 p+=sprintf(p,
"%u,", i);
1841 p += sprintf(p,
"},unknown={");
1842 for (i=focus_points_in_struct*8+(focus_points_in_struct+7)/8+20;i<size;i++) {
1843 if ((p-str) > maxlen - 4)
1845 p+=sprintf(p,
"%02x", (*data)[i]);
1847 p += sprintf(p,
"}");
1853ptp_unpack_EOS_CustomFuncEx (
PTPParams* params,
unsigned char** data )
1855 uint32_t s = dtoh32a( *data );
1856 uint32_t n = s/4, i;
1860 ptp_debug (params,
"customfuncex data is larger than 1k / %d... unexpected?", s);
1861 return strdup(
"bad length");
1863 str = (
char*)malloc( s*2+s/4+1 );
1865 return strdup(
"malloc failed");
1868 for (i=0; i < n; ++i)
1869 p += sprintf(p,
"%x,", dtoh32a( *data + 4*i ));
1873static inline uint32_t
1874ptp_pack_EOS_CustomFuncEx (
PTPParams* params,
unsigned char* data,
char* str)
1876 uint32_t s = strtoul(str, NULL, 16);
1877 uint32_t n = s/4, i, v;
1884 v = strtoul(str, &str, 16);
1886 htod32a(data + i*4, v);
1895#define PTP_ece_Size 0
1896#define PTP_ece_Type 4
1898#define PTP_ece_Prop_Subtype 8
1899#define PTP_ece_Prop_Val_Data 0xc
1900#define PTP_ece_Prop_Desc_Type 0xc
1901#define PTP_ece_Prop_Desc_Count 0x10
1902#define PTP_ece_Prop_Desc_Data 0x14
1905#define PTP_ece_OI_ObjectID 8
1906#define PTP_ece_OI_OFC 0x0c
1907#define PTP_ece_OI_Size 0x14
1908#define PTP_ece_OI_Name 0x1c
1911#define PTP_ece_OA_ObjectID 8
1912#define PTP_ece_OA_StorageID 0x0c
1913#define PTP_ece_OA_OFC 0x10
1914#define PTP_ece_OA_Size 0x1c
1915#define PTP_ece_OA_Parent 0x20
1916#define PTP_ece_OA_Name 0x28
1918#define PTP_ece2_OA_ObjectID 8
1919#define PTP_ece2_OA_StorageID 0x0c
1920#define PTP_ece2_OA_OFC 0x10
1921#define PTP_ece2_OA_Size 0x1c
1922#define PTP_ece2_OA_Parent 0x24
1923#define PTP_ece2_OA_2ndOID 0x28
1924#define PTP_ece2_OA_Name 0x2c
1927#define PTP_ece_OAN_OFC 0x0c
1928#define PTP_ece_OAN_Size 0x14
1931_lookup_or_allocate_canon_prop(
PTPParams *params, uint16_t proptype)
1935 for (j=0;j<params->nrofcanon_props;j++)
1936 if (params->canon_props[j].proptype == proptype)
1938 if (j<params->nrofcanon_props)
1939 return ¶ms->canon_props[j].dpd;
1942 params->canon_props = realloc(params->canon_props,
sizeof(params->canon_props[0])*(j+1));
1944 params->canon_props = malloc(
sizeof(params->canon_props[0]));
1945 params->canon_props[j].proptype = proptype;
1946 params->canon_props[j].size = 0;
1947 params->canon_props[j].data = NULL;
1948 memset (¶ms->canon_props[j].dpd,0,
sizeof(params->canon_props[j].dpd));
1949 params->canon_props[j].dpd.GetSet = 1;
1950 params->canon_props[j].dpd.FormFlag = PTP_DPFF_None;
1951 params->nrofcanon_props = j+1;
1952 return ¶ms->canon_props[j].dpd;
1959 int i = 0, entries = 0;
1960 unsigned char *curdata = data;
1965 while (curdata - data + 8 < datasize) {
1966 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
1967 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
1969 if (size > datasize) {
1970 ptp_debug (params,
"size %d is larger than datasize %d", size, datasize);
1974 ptp_debug (params,
"size %d is smaller than 8.", size);
1977 if ((size == 8) && (type == 0))
1979 if ((curdata - data) + size >= datasize) {
1980 ptp_debug (params,
"canon eos event decoder ran over supplied data, skipping entries");
1983 if (type == PTP_EC_CANON_EOS_OLCInfoChanged) {
1989 if (dtoh16a(curdata+12) & (1<<j))
2000 while (curdata - data + 8 < datasize) {
2001 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
2002 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
2004 if (size > datasize) {
2005 ptp_debug (params,
"size %d is larger than datasize %d", size, datasize);
2009 ptp_debug (params,
"size %d is smaller than 8", size);
2013 if ((size == 8) && (type == 0))
2016 if ((curdata - data) + size >= datasize) {
2017 ptp_debug (params,
"canon eos event decoder ran over supplied data, skipping entries");
2021 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2022 ce[i].u.info = NULL;
2024 case PTP_EC_CANON_EOS_ObjectContentChanged:
2025 if (size < PTP_ece_OA_ObjectID+1) {
2026 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OA_ObjectID+1);
2029 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTCONTENT_CHANGE;
2030 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OA_ObjectID]);
2032 case PTP_EC_CANON_EOS_ObjectInfoChangedEx:
2033 case PTP_EC_CANON_EOS_ObjectAddedEx:
2034 if (size < PTP_ece_OA_Name+1) {
2035 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OA_Name+1);
2038 ce[i].type = ((type == PTP_EC_CANON_EOS_ObjectAddedEx) ? PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO : PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO_CHANGE);
2039 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OA_ObjectID]);
2040 ce[i].u.object.oi.StorageID = dtoh32a(&curdata[PTP_ece_OA_StorageID]);
2041 ce[i].u.object.oi.ParentObject = dtoh32a(&curdata[PTP_ece_OA_Parent]);
2042 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece_OA_OFC]);
2043 ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata[PTP_ece_OA_Size]);
2044 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece_OA_Name]));
2045 if (type == PTP_EC_CANON_EOS_ObjectAddedEx) {
2046 ptp_debug (params,
"event %d: objectinfo added oid %08lx, parent %08lx, ofc %04x, size %d, filename %s", i, ce[i].u.object.oid, ce[i].u.object.oi.ParentObject, ce[i].u.object.oi.ObjectFormat, ce[i].u.object.oi.ObjectCompressedSize, ce[i].u.object.oi.Filename);
2048 ptp_debug (params,
"event %d: objectinfo changed oid %08lx, parent %08lx, ofc %04x, size %d, filename %s", i, ce[i].u.object.oid, ce[i].u.object.oi.ParentObject, ce[i].u.object.oi.ObjectFormat, ce[i].u.object.oi.ObjectCompressedSize, ce[i].u.object.oi.Filename);
2051 case PTP_EC_CANON_EOS_ObjectAddedEx64:
2052 if (size < PTP_ece2_OA_Name+1) {
2053 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece2_OA_Name+1);
2056 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO;
2057 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece2_OA_ObjectID]);
2058 ce[i].u.object.oi.StorageID = dtoh32a(&curdata[PTP_ece2_OA_StorageID]);
2059 ce[i].u.object.oi.ParentObject = dtoh32a(&curdata[PTP_ece2_OA_Parent]);
2060 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece2_OA_OFC]);
2061 ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata[PTP_ece2_OA_Size]);
2062 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece2_OA_Name]));
2063 ptp_debug (params,
"event %d: objectinfo added oid %08lx, parent %08lx, ofc %04x, size %d, filename %s", i, ce[i].u.object.oid, ce[i].u.object.oi.ParentObject, ce[i].u.object.oi.ObjectFormat, ce[i].u.object.oi.ObjectCompressedSize, ce[i].u.object.oi.Filename);
2065 case PTP_EC_CANON_EOS_RequestObjectTransfer:
2066 case PTP_EC_CANON_EOS_RequestObjectTransfer64:
2067 if (size < PTP_ece_OI_Name+1) {
2068 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OI_Name+1);
2071 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER;
2072 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OI_ObjectID]);
2073 ce[i].u.object.oi.StorageID = 0;
2074 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece_OI_OFC]);
2075 ce[i].u.object.oi.ParentObject = 0;
2076 ce[i].u.object.oi.ObjectCompressedSize = dtoh32a(&curdata[PTP_ece_OI_Size]);
2077 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece_OI_Name]));
2079 ptp_debug (params,
"event %d: request object transfer oid %08lx, ofc %04x, size %d, filename %p", i, ce[i].u.object.oid, ce[i].u.object.oi.ObjectFormat, ce[i].u.object.oi.ObjectCompressedSize, ce[i].u.object.oi.Filename);
2081 case PTP_EC_CANON_EOS_AvailListChanged: {
2082 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
2083 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Prop_Desc_Type]);
2084 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop_Desc_Count]);
2085 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data];
2089 if (size < PTP_ece_Prop_Desc_Data) {
2090 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_Prop_Desc_Data);
2094 ptp_debug (params,
"event %d: EOS prop %04x desc record, datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype);
2095 for (j=0;j<params->nrofcanon_props;j++)
2096 if (params->canon_props[j].proptype == proptype)
2098 if (j==params->nrofcanon_props) {
2099 ptp_debug (params,
"event %d: propdesc %x, default value not found.", i, proptype);
2102 dpd = ¶ms->canon_props[j].dpd;
2107 if (propxtype != 3) {
2108 ptp_debug (params,
"event %d: propxtype is %x for %04x, unhandled, size %d", i, propxtype, proptype, size);
2109 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++)
2110 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2115 if (propxcnt >= 2<<16)
2118 ptp_debug (params,
"event %d: propxtype is %x, prop is 0x%04x, data type is 0x%04x, propxcnt is %d.",
2119 i, propxtype, proptype, dpd->DataType, propxcnt);
2120 dpd->FormFlag = PTP_DPFF_Enumeration;
2121 dpd->FORM.Enum.NumberOfValues = propxcnt;
2122 free (dpd->FORM.Enum.SupportedValue);
2123 dpd->FORM.Enum.SupportedValue = malloc (
sizeof (
PTPPropertyValue)*propxcnt);
2126 case PTP_DPC_CANON_EOS_ImageFormat:
2127 case PTP_DPC_CANON_EOS_ImageFormatCF:
2128 case PTP_DPC_CANON_EOS_ImageFormatSD:
2129 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2131 for (j=0;j<propxcnt;j++) {
2132 dpd->FORM.Enum.SupportedValue[j].u16 =
2133 ptp_unpack_EOS_ImageFormat( params, &xdata );
2134 ptp_debug (params,
"event %d: suppval[%d] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16);
2139 switch (dpd->DataType) {
2140#define XX( TYPE, CONV )\
2141 if (sizeof(dpd->FORM.Enum.SupportedValue[j].TYPE)*propxcnt + PTP_ece_Prop_Desc_Data > size) { \
2142 ptp_debug (params, "size %lu does not match needed %u", sizeof(dpd->FORM.Enum.SupportedValue[j].TYPE)*propxcnt + PTP_ece_Prop_Desc_Data, size); \
2145 for (j=0;j<propxcnt;j++) { \
2146 dpd->FORM.Enum.SupportedValue[j].TYPE = CONV(xdata); \
2147 ptp_debug (params, "event %u: suppval[%u] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \
2152 case PTP_DTC_INT16: XX( i16, dtoh16a );
2153 case PTP_DTC_UINT16: XX( u16, dtoh16a );
2154 case PTP_DTC_UINT32: XX( u32, dtoh32a );
2155 case PTP_DTC_INT32: XX( i32, dtoh32a );
2156 case PTP_DTC_UINT8: XX( u8, dtoh8a );
2157 case PTP_DTC_INT8: XX( i8, dtoh8a );
2160 free (dpd->FORM.Enum.SupportedValue);
2161 dpd->FORM.Enum.SupportedValue = NULL;
2162 dpd->FORM.Enum.NumberOfValues = 0;
2163 ptp_debug (params ,
"event %d: data type 0x%04x of %x unhandled, size %d, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata), size);
2164 for (j=0;j<(size-PTP_ece_Prop_Desc_Data)/4;j++, xdata+=4)
2165 ptp_debug (params,
" %3d: 0x%8x", j, dtoh32a(xdata));
2171 case PTP_EC_CANON_EOS_PropValueChanged:
2174 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
2175 unsigned char *xdata = &curdata[PTP_ece_Prop_Val_Data];
2178 if (size < PTP_ece_Prop_Val_Data) {
2179 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_Prop_Val_Data);
2182 ptp_debug (params,
"event %d: EOS prop %04x info record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data);
2183 for (j=0;j<params->nrofcanon_props;j++)
2184 if (params->canon_props[j].proptype == proptype)
2186 if (j<params->nrofcanon_props) {
2187 if ( (params->canon_props[j].size != size) ||
2188 (memcmp(params->canon_props[j].data,xdata,size-PTP_ece_Prop_Val_Data))) {
2189 params->canon_props[j].data = realloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data);
2190 params->canon_props[j].size = size;
2191 memcpy (params->canon_props[j].data,xdata,size-PTP_ece_Prop_Val_Data);
2195 params->canon_props = realloc(params->canon_props,
sizeof(params->canon_props[0])*(j+1));
2197 params->canon_props = malloc(
sizeof(params->canon_props[0]));
2198 params->canon_props[j].proptype = proptype;
2199 params->canon_props[j].size = size;
2200 params->canon_props[j].data = malloc(size-PTP_ece_Prop_Val_Data);
2201 memcpy(params->canon_props[j].data, xdata, size-PTP_ece_Prop_Val_Data);
2202 memset (¶ms->canon_props[j].dpd,0,
sizeof(params->canon_props[j].dpd));
2203 params->canon_props[j].dpd.GetSet = 1;
2204 params->canon_props[j].dpd.FormFlag = PTP_DPFF_None;
2205 params->nrofcanon_props = j+1;
2207 dpd = ¶ms->canon_props[j].dpd;
2209 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2210 ce[i].u.propid = proptype;
2214#define XX(x) case PTP_DPC_CANON_##x:
2216 XX(EOS_BatteryPower)
2217 XX(EOS_BatterySelect)
2219 XX(EOS_PTPExtensionVersion)
2221 XX(EOS_AvailableShots)
2222 XX(EOS_CurrentStorage)
2223 XX(EOS_CurrentFolder)
2226 XX(EOS_HDDirectoryStructure)
2230 XX(EOS_CardExtension)
2232 XX(EOS_ShutterCounter)
2233 XX(EOS_SerialNumber)
2234 XX(EOS_DepthOfFieldPreview)
2235 XX(EOS_EVFRecordStatus)
2238 XX(EOS_DepthOfField)
2244 dpd->GetSet = PTP_DPGS_Get;
2250 case PTP_DPC_CANON_EOS_CameraTime:
2251 case PTP_DPC_CANON_EOS_UTCTime:
2252 case PTP_DPC_CANON_EOS_Summertime:
2253 case PTP_DPC_CANON_EOS_AvailableShots:
2254 case PTP_DPC_CANON_EOS_CaptureDestination:
2255 case PTP_DPC_CANON_EOS_WhiteBalanceXA:
2256 case PTP_DPC_CANON_EOS_WhiteBalanceXB:
2257 case PTP_DPC_CANON_EOS_CurrentStorage:
2258 case PTP_DPC_CANON_EOS_CurrentFolder:
2259 case PTP_DPC_CANON_EOS_ShutterCounter:
2260 case PTP_DPC_CANON_EOS_ModelID:
2261 case PTP_DPC_CANON_EOS_LensID:
2262 case PTP_DPC_CANON_EOS_StroboFiring:
2263 case PTP_DPC_CANON_EOS_AFSelectFocusArea:
2264 case PTP_DPC_CANON_EOS_ContinousAFMode:
2265 case PTP_DPC_CANON_EOS_MirrorUpSetting:
2266 case PTP_DPC_CANON_EOS_OLCInfoVersion:
2267 case PTP_DPC_CANON_EOS_PowerZoomPosition:
2268 case PTP_DPC_CANON_EOS_PowerZoomSpeed:
2269 dpd->DataType = PTP_DTC_UINT32;
2272 case PTP_DPC_CANON_EOS_AutoExposureMode:
2273 dpd->DataType = PTP_DTC_UINT16;
2274 dpd->FormFlag = PTP_DPFF_Enumeration;
2275 dpd->FORM.Enum.NumberOfValues = 0;
2277 case PTP_DPC_CANON_EOS_Aperture:
2278 case PTP_DPC_CANON_EOS_ShutterSpeed:
2279 case PTP_DPC_CANON_EOS_ISOSpeed:
2280 case PTP_DPC_CANON_EOS_FocusMode:
2281 case PTP_DPC_CANON_EOS_ColorSpace:
2282 case PTP_DPC_CANON_EOS_BatteryPower:
2283 case PTP_DPC_CANON_EOS_BatterySelect:
2284 case PTP_DPC_CANON_EOS_PTPExtensionVersion:
2285 case PTP_DPC_CANON_EOS_DriveMode:
2286 case PTP_DPC_CANON_EOS_AEB:
2287 case PTP_DPC_CANON_EOS_BracketMode:
2288 case PTP_DPC_CANON_EOS_QuickReviewTime:
2289 case PTP_DPC_CANON_EOS_EVFMode:
2290 case PTP_DPC_CANON_EOS_EVFOutputDevice:
2291 case PTP_DPC_CANON_EOS_AutoPowerOff:
2292 case PTP_DPC_CANON_EOS_EVFRecordStatus:
2293 case PTP_DPC_CANON_EOS_HighISOSettingNoiseReduction:
2294 case PTP_DPC_CANON_EOS_MultiAspect:
2295 dpd->DataType = PTP_DTC_UINT16;
2297 case PTP_DPC_CANON_EOS_PictureStyle:
2298 case PTP_DPC_CANON_EOS_WhiteBalance:
2299 case PTP_DPC_CANON_EOS_MeteringMode:
2300 case PTP_DPC_CANON_EOS_ExpCompensation:
2301 dpd->DataType = PTP_DTC_UINT8;
2303 case PTP_DPC_CANON_EOS_Owner:
2304 case PTP_DPC_CANON_EOS_Artist:
2305 case PTP_DPC_CANON_EOS_Copyright:
2306 case PTP_DPC_CANON_EOS_SerialNumber:
2307 case PTP_DPC_CANON_EOS_LensName:
2308 dpd->DataType = PTP_DTC_STR;
2310 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA:
2311 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB:
2312 dpd->DataType = PTP_DTC_INT32;
2315 case PTP_DPC_CANON_EOS_DPOFVersion:
2316 dpd->DataType = PTP_DTC_UINT16;
2317 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint16", i ,proptype, size-PTP_ece_Prop_Val_Data);
2318 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2319 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2321 case PTP_DPC_CANON_EOS_CustomFunc1:
2322 case PTP_DPC_CANON_EOS_CustomFunc2:
2323 case PTP_DPC_CANON_EOS_CustomFunc3:
2324 case PTP_DPC_CANON_EOS_CustomFunc4:
2325 case PTP_DPC_CANON_EOS_CustomFunc5:
2326 case PTP_DPC_CANON_EOS_CustomFunc6:
2327 case PTP_DPC_CANON_EOS_CustomFunc7:
2328 case PTP_DPC_CANON_EOS_CustomFunc8:
2329 case PTP_DPC_CANON_EOS_CustomFunc9:
2330 case PTP_DPC_CANON_EOS_CustomFunc10:
2331 case PTP_DPC_CANON_EOS_CustomFunc11:
2332 dpd->DataType = PTP_DTC_UINT8;
2333 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint8", i ,proptype, size-PTP_ece_Prop_Val_Data);
2334 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2335 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2340 case PTP_DPC_CANON_EOS_ColorTemperature:
2341 case PTP_DPC_CANON_EOS_WftStatus:
2342 case PTP_DPC_CANON_EOS_LensStatus:
2343 case PTP_DPC_CANON_EOS_CardExtension:
2344 case PTP_DPC_CANON_EOS_TempStatus:
2345 case PTP_DPC_CANON_EOS_PhotoStudioMode:
2346 case PTP_DPC_CANON_EOS_DepthOfFieldPreview:
2347 case PTP_DPC_CANON_EOS_EVFSharpness:
2348 case PTP_DPC_CANON_EOS_EVFWBMode:
2349 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs:
2350 case PTP_DPC_CANON_EOS_EVFColorTemp:
2351 case PTP_DPC_CANON_EOS_ExposureSimMode:
2352 case PTP_DPC_CANON_EOS_LvAfSystem:
2353 case PTP_DPC_CANON_EOS_MovSize:
2354 case PTP_DPC_CANON_EOS_DepthOfField:
2355 case PTP_DPC_CANON_EOS_LvViewTypeSelect:
2356 case PTP_DPC_CANON_EOS_AloMode:
2357 case PTP_DPC_CANON_EOS_Brightness:
2358 dpd->DataType = PTP_DTC_UINT32;
2359 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_Val_Data);
2360 if ((size-PTP_ece_Prop_Val_Data) %
sizeof(uint32_t) != 0)
2361 ptp_debug (params,
"event %d: Warning: datasize modulo sizeof(uint32) is not 0: ", i, (size-PTP_ece_Prop_Val_Data) %
sizeof(uint32_t) );
2362 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/
sizeof(uint32_t);j++)
2363 ptp_debug (params,
" %d: 0x%8x", j, dtoh32a(xdata+j*4));
2366 case PTP_DPC_CANON_EOS_ImageFormat:
2367 case PTP_DPC_CANON_EOS_ImageFormatCF:
2368 case PTP_DPC_CANON_EOS_ImageFormatSD:
2369 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2370 case PTP_DPC_CANON_EOS_CustomFuncEx:
2371 case PTP_DPC_CANON_EOS_FocusInfoEx:
2374 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data);
2375 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2376 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2379 switch (dpd->DataType) {
2380 case PTP_DTC_UINT32:
2381 dpd->FactoryDefaultValue.u32 = dtoh32a(xdata);
2382 dpd->CurrentValue.u32 = dtoh32a(xdata);
2383 ptp_debug (params ,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u32);
2386 dpd->FactoryDefaultValue.i16 = dtoh16a(xdata);
2387 dpd->CurrentValue.i16 = dtoh16a(xdata);
2388 ptp_debug (params,
"event %d: currentvalue of %x is %d", i, proptype, dpd->CurrentValue.i16);
2390 case PTP_DTC_UINT16:
2391 dpd->FactoryDefaultValue.u16 = dtoh16a(xdata);
2392 dpd->CurrentValue.u16 = dtoh16a(xdata);
2393 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
2396 dpd->FactoryDefaultValue.u8 = dtoh8a(xdata);
2397 dpd->CurrentValue.u8 = dtoh8a(xdata);
2398 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u8);
2401 dpd->FactoryDefaultValue.i8 = dtoh8a(xdata);
2402 dpd->CurrentValue.i8 = dtoh8a(xdata);
2403 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.i8);
2408 dpd->FactoryDefaultValue.str = ptp_unpack_string(params, data, 0, &len);
2409 dpd->CurrentValue.str = ptp_unpack_string(params, data, 0, &len);
2411 free (dpd->FactoryDefaultValue.str);
2412 dpd->FactoryDefaultValue.str = strdup( (
char*)xdata );
2414 free (dpd->CurrentValue.str);
2415 dpd->CurrentValue.str = strdup( (
char*)xdata );
2417 ptp_debug (params,
"event %d: currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2427 case PTP_DPC_CANON_EOS_ImageFormat:
2428 case PTP_DPC_CANON_EOS_ImageFormatCF:
2429 case PTP_DPC_CANON_EOS_ImageFormatSD:
2430 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2431 dpd->DataType = PTP_DTC_UINT16;
2432 dpd->FactoryDefaultValue.u16 = ptp_unpack_EOS_ImageFormat( params, &xdata );
2433 dpd->CurrentValue.u16 = dpd->FactoryDefaultValue.u16;
2434 ptp_debug (params,
"event %d: decoded imageformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
2436 case PTP_DPC_CANON_EOS_CustomFuncEx:
2437 dpd->DataType = PTP_DTC_STR;
2438 free (dpd->FactoryDefaultValue.str);
2439 free (dpd->CurrentValue.str);
2440 dpd->FactoryDefaultValue.str = ptp_unpack_EOS_CustomFuncEx( params, &xdata );
2441 dpd->CurrentValue.str = strdup( (
char*)dpd->FactoryDefaultValue.str );
2442 ptp_debug (params,
"event %d: decoded custom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2444 case PTP_DPC_CANON_EOS_FocusInfoEx:
2445 dpd->DataType = PTP_DTC_STR;
2446 free (dpd->FactoryDefaultValue.str);
2447 free (dpd->CurrentValue.str);
2448 dpd->FactoryDefaultValue.str = ptp_unpack_EOS_FocusInfoEx( params, &xdata, size );
2449 dpd->CurrentValue.str = strdup( (
char*)dpd->FactoryDefaultValue.str );
2450 ptp_debug (params,
"event %d: decoded focus info, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2467 case PTP_EC_CANON_EOS_OLCInfoChanged: {
2468 uint32_t len, curoff;
2469 uint16_t mask,proptype;
2473 dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_OLCInfoVersion);
2475 ptp_debug (params,
"olcinfoversion is %d", dpd->CurrentValue.u32);
2476 olcver = dpd->CurrentValue.u32;
2480 ptp_debug (params,
"event %d: EOS event OLCInfoChanged (size %d)", i, size);
2483 for (k=8;k<size;k++)
2484 ptp_debug (params,
" %d: %02x", k-8, curdata[k]);
2486 len = dtoh32a(curdata+8);
2487 if ((len != size-8) && (len != size-4)) {
2488 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2489 ce[i].u.info = strdup(
"OLC size unexpected");
2490 ptp_debug (params,
"event %d: OLC unexpected size %d for blob len %d (not -4 nor -8)", i, size, len);
2493 mask = dtoh16a(curdata+8+4);
2495 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2496 ce[i].u.info = strdup(
"OLC size too small");
2497 ptp_debug (params,
"event %d: OLC unexpected size %d", i, size);
2501 if (mask & CANON_EOS_OLC_BUTTON) {
2502 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2503 ce[i].u.info = malloc(strlen(
"Button 1234567"));
2504 sprintf(ce[i].u.info,
"Button %d", dtoh16a(curdata+curoff));
2509 if (mask & CANON_EOS_OLC_SHUTTERSPEED) {
2515 proptype = PTP_DPC_CANON_EOS_ShutterSpeed;
2516 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2517 dpd->CurrentValue.u16 = curdata[curoff+5];
2519 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2520 ce[i].u.propid = proptype;
2537 if (mask & CANON_EOS_OLC_APERTURE) {
2543 proptype = PTP_DPC_CANON_EOS_Aperture;
2544 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2545 dpd->CurrentValue.u16 = curdata[curoff+4];
2547 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2548 ce[i].u.propid = proptype;
2549 if (olcver >= 0xf) {
2556 if (mask & CANON_EOS_OLC_ISO) {
2559 proptype = PTP_DPC_CANON_EOS_ISOSpeed;
2560 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2561 dpd->CurrentValue.u16 = curdata[curoff+3];
2563 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2564 ce[i].u.propid = proptype;
2568 if (mask & 0x0010) {
2570 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2571 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0010 content 01234567")+1);
2572 sprintf(ce[i].u.info,
"OLCInfo event 0x0010 content %02x%02x%02x%02x",
2581 if (mask & 0x0020) {
2586 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2587 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0020 content 0123456789ab")+1);
2588 sprintf(ce[i].u.info,
"OLCInfo event 0x0020 content %02x%02x%02x%02x%02x%02x",
2599 if (mask & 0x0040) {
2600 int value = (
signed char)curdata[curoff+2];
2603 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2604 ce[i].u.info = malloc(strlen(
"OLCInfo exposure indicator 012345678901234567890123456789abcd")+1);
2605 sprintf(ce[i].u.info,
"OLCInfo exposure indicator %d,%d,%d.%d (%02x%02x%02x%02x)",
2608 value/10,abs(value)%10,
2617 if (mask & 0x0080) {
2619 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2620 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0080 content 01234567")+1);
2621 sprintf(ce[i].u.info,
"OLCInfo event 0x0080 content %02x%02x%02x%02x",
2630 if (mask & 0x0100) {
2632 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSINFO;
2633 ce[i].u.info = malloc(strlen(
"0123456789ab")+1);
2634 sprintf(ce[i].u.info,
"%02x%02x%02x%02x%02x%02x",
2645 if (mask & 0x0200) {
2647 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSMASK;
2648 ce[i].u.info = malloc(strlen(
"0123456789abcd0123456789abcdef")+1);
2649 sprintf(ce[i].u.info,
"%02x%02x%02x%02x%02x%02x%02x",
2661 if (mask & 0x0400) {
2663 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2664 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0400 content 0123456789abcd")+1);
2665 sprintf(ce[i].u.info,
"OLCInfo event 0x0400 content %02x%02x%02x%02x%02x%02x%02x",
2677 if (mask & 0x0800) {
2680 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2681 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0800 content 0123456789abcdef")+1);
2682 sprintf(ce[i].u.info,
"OLCInfo event 0x0800 content %02x%02x%02x%02x%02x%02x%02x%02x",
2695 if (mask & 0x1000) {
2697 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2698 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x1000 content 01")+1);
2699 sprintf(ce[i].u.info,
"OLCInfo event 0x1000 content %02x",
2706 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2707 ce[i].u.info = malloc(strlen(
"OLCInfo event mask 0123456789")+1);
2708 sprintf(ce[i].u.info,
"OLCInfo event mask=%x", mask);
2711 case PTP_EC_CANON_EOS_CameraStatusChanged:
2712 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS;
2713 ce[i].u.status = dtoh32a(curdata+8);
2714 ptp_debug (params,
"event %d: EOS event CameraStatusChanged (size %d) = %d", i, size, dtoh32a(curdata+8));
2715 params->eos_camerastatus = dtoh32a(curdata+8);
2720 ptp_debug (params,
"event %d: EOS event 0, but size %d", i, size);
2722 case PTP_EC_CANON_EOS_BulbExposureTime:
2723 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2724 ce[i].u.info = malloc(strlen(
"BulbExposureTime 123456789012345678"));
2725 sprintf (ce[i].u.info,
"BulbExposureTime %u", dtoh32a(curdata+8));
2727 case PTP_EC_CANON_EOS_ObjectRemoved:
2728 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTREMOVED;
2729 ce[i].u.object.oid = dtoh32a(curdata+8);
2733#define XX(x) case PTP_EC_CANON_EOS_##x: \
2734 ptp_debug (params, "event %u: unhandled EOS event "#x" (size %u)", i, size); \
2735 ce[i].u.info = malloc(strlen("unhandled EOS event "#x" (size 12345678901)")+1); \
2736 sprintf (ce[i].u.info, "unhandled EOS event "#x" (size %u)", size); \
2739 XX(RequestGetObjectInfoEx)
2740 XX(StorageStatusChanged)
2741 XX(StorageInfoChanged)
2742 XX(ObjectInfoChangedEx)
2743 XX(ObjectContentChanged)
2744 XX(WillSoonShutdown)
2745 XX(ShutdownTimerUpdated)
2746 XX(RequestCancelTransfer)
2747 XX(RequestObjectTransferDT)
2748 XX(RequestCancelTransferDT)
2751 XX(BulbExposureTime)
2753 XX(RequestObjectTransferTS)
2755 XX(PowerZoomInfoChanged)
2756 XX(CTGInfoCheckComplete)
2759 ptp_debug (params,
"event %d: unknown EOS event %04x", i, type);
2765 for (j=8;j<size;j++)
2766 ptp_debug (params,
" %d: %02x", j, curdata[j]);
2768 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2774 ptp_debug (params,
"BAD: i %d, entries %d", i, entries);
2788#define PTP_nikon_ec_Length 0
2789#define PTP_nikon_ec_Code 2
2790#define PTP_nikon_ec_Param1 4
2791#define PTP_nikon_ec_Size 6
2793ptp_unpack_Nikon_EC (
PTPParams *params,
unsigned char* data,
unsigned int len,
PTPContainer **ec,
unsigned int *cnt)
2800 if (len < PTP_nikon_ec_Code)
2802 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]);
2803 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) {
2812 for (i=0;i<*cnt;i++) {
2814 (*ec)[i].Code = dtoh16a(&data[PTP_nikon_ec_Code+PTP_nikon_ec_Size*i]);
2815 (*ec)[i].Param1 = dtoh32a(&data[PTP_nikon_ec_Param1+PTP_nikon_ec_Size*i]);
2816 (*ec)[i].Nparam = 1;
2821static inline uint32_t
2825 unsigned char *curdata;
2827 len = 2*(strlen(text->title)+1)+1+
2828 2*(strlen(text->line[0])+1)+1+
2829 2*(strlen(text->line[1])+1)+1+
2830 2*(strlen(text->line[2])+1)+1+
2831 2*(strlen(text->line[3])+1)+1+
2832 2*(strlen(text->line[4])+1)+1+
2833 4*2+2*4+2+4+2+5*4*2;
2834 *data = malloc(len);
2835 if (!*data)
return 0;
2838 htod16a(curdata,100);curdata+=2;
2839 htod16a(curdata,1);curdata+=2;
2840 htod16a(curdata,0);curdata+=2;
2841 htod16a(curdata,1000);curdata+=2;
2843 htod32a(curdata,0);curdata+=4;
2844 htod32a(curdata,0);curdata+=4;
2846 htod16a(curdata,6);curdata+=2;
2847 htod32a(curdata,0);curdata+=4;
2849 ptp_pack_string(params, text->title, curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
2850 htod16a(curdata,0x10);curdata+=2;
2853 ptp_pack_string(params, text->line[i], curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
2854 htod16a(curdata,0x10);curdata+=2;
2855 htod16a(curdata,0x01);curdata+=2;
2856 htod16a(curdata,0x02);curdata+=2;
2857 htod16a(curdata,0x06);curdata+=2;
2862#define ptp_canon_dir_version 0x00
2863#define ptp_canon_dir_ofc 0x02
2864#define ptp_canon_dir_unk1 0x04
2865#define ptp_canon_dir_objectid 0x08
2866#define ptp_canon_dir_parentid 0x0c
2867#define ptp_canon_dir_previd 0x10
2868#define ptp_canon_dir_nextid 0x14
2869#define ptp_canon_dir_nextchild 0x18
2870#define ptp_canon_dir_storageid 0x1c
2871#define ptp_canon_dir_name 0x20
2872#define ptp_canon_dir_flags 0x2c
2873#define ptp_canon_dir_size 0x30
2874#define ptp_canon_dir_unixtime 0x34
2875#define ptp_canon_dir_year 0x38
2876#define ptp_canon_dir_month 0x39
2877#define ptp_canon_dir_mday 0x3a
2878#define ptp_canon_dir_hour 0x3b
2879#define ptp_canon_dir_minute 0x3c
2880#define ptp_canon_dir_second 0x3d
2881#define ptp_canon_dir_unk2 0x3e
2882#define ptp_canon_dir_thumbsize 0x40
2883#define ptp_canon_dir_width 0x44
2884#define ptp_canon_dir_height 0x48
2886static inline uint16_t
2887ptp_unpack_canon_directory (
2895 unsigned int i, j, nrofobs = 0, curob = 0;
2897#define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff)
2899 if (ISOBJECT(dir+i*0x4c)) nrofobs++;
2900 handles->n = nrofobs;
2901 handles->Handler = calloc(nrofobs,
sizeof(handles->Handler[0]));
2902 if (!handles->Handler)
return PTP_RC_GeneralError;
2903 *oinfos = calloc(nrofobs,
sizeof((*oinfos)[0]));
2904 if (!*oinfos)
return PTP_RC_GeneralError;
2905 *flags = calloc(nrofobs,
sizeof((*flags)[0]));
2906 if (!*flags)
return PTP_RC_GeneralError;
2912 for (i=0;i<cnt;i++) {
2913 unsigned char *cur = dir+i*0x4c;
2919 handles->Handler[curob] = dtoh32a(cur + ptp_canon_dir_objectid);
2920 oi->StorageID = 0xffffffff;
2921 oi->ObjectFormat = dtoh16a(cur + ptp_canon_dir_ofc);
2922 oi->ParentObject = dtoh32a(cur + ptp_canon_dir_parentid);
2923 oi->Filename = strdup((
char*)(cur + ptp_canon_dir_name));
2924 oi->ObjectCompressedSize= dtoh32a(cur + ptp_canon_dir_size);
2925 oi->ThumbCompressedSize = dtoh32a(cur + ptp_canon_dir_thumbsize);
2926 oi->ImagePixWidth = dtoh32a(cur + ptp_canon_dir_width);
2927 oi->ImagePixHeight = dtoh32a(cur + ptp_canon_dir_height);
2928 oi->CaptureDate = oi->ModificationDate = dtoh32a(cur + ptp_canon_dir_unixtime);
2929 (*flags)[curob] = dtoh32a(cur + ptp_canon_dir_flags);
2934 for (i=0;i<cnt;i++) {
2935 unsigned char *cur = dir+i*0x4c;
2936 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
2940 for (j=0;j<handles->n;j++)
if (nextchild == handles->Handler[j])
break;
2941 if (j == handles->n)
continue;
2942 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid);
2946 unsigned int changed = 0;
2947 for (i=0;i<cnt;i++) {
2948 unsigned char *cur = dir+i*0x4c;
2949 uint32_t oid = dtoh32a(cur + ptp_canon_dir_objectid);
2950 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_nextid);
2951 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
2956 for (j=0;j<handles->n;j++)
if (oid == handles->Handler[j])
break;
2957 if (j == handles->n) {
2961 storageid = (*oinfos)[j].StorageID;
2962 if (storageid == 0xffffffff)
continue;
2963 if (nextoid != 0xffffffff) {
2964 for (j=0;j<handles->n;j++)
if (nextoid == handles->Handler[j])
break;
2965 if (j == handles->n) {
2969 if ((*oinfos)[j].StorageID == 0xffffffff) {
2970 (*oinfos)[j].StorageID = storageid;
2974 if (nextchild != 0xffffffff) {
2975 for (j=0;j<handles->n;j++)
if (nextchild == handles->Handler[j])
break;
2976 if (j == handles->n) {
2980 if ((*oinfos)[j].StorageID == 0xffffffff) {
2981 (*oinfos)[j].StorageID = storageid;
2991 if (!changed || (changed==nrofobs-1))
2999ptp_unpack_ptp11_manifest (
3001 unsigned char *data,
3002 unsigned int datalen,
3006 uint64_t numberoifs, i;
3007 unsigned int curoffset;
3012 numberoifs = dtoh64ap(params,data);
3018 for (i = 0; i < numberoifs; i++) {
3023 if (curoffset + 34 + 2 > datalen)
3026 oif->ObjectHandle = dtoh32ap(params,data+curoffset);
3027 oif->StorageID = dtoh32ap(params,data+curoffset+4);
3028 oif->ObjectFormat = dtoh16ap(params,data+curoffset+8);
3029 oif->ProtectionStatus = dtoh16ap(params,data+curoffset+10);
3030 oif->ObjectCompressedSize64 = dtoh64ap(params,data+curoffset+12);
3031 oif->ParentObject = dtoh32ap(params,data+curoffset+20);
3032 oif->AssociationType = dtoh16ap(params,data+curoffset+24);
3033 oif->AssociationDesc = dtoh32ap(params,data+curoffset+26);
3034 oif->SequenceNumber = dtoh32ap(params,data+curoffset+30);
3035 if (!ptp_unpack_string(params, data, curoffset+34, datalen, &len, &oif->Filename))
3037 if (curoffset+34+len*2+1 > datalen)
3040 if (!ptp_unpack_string(params, data, curoffset+len*2+1+34, datalen, &dlen, &modify_date))
3043 oif->ModificationDate = ptp_unpack_PTPTIME(modify_date);
3045 curoffset += 34+len*2+dlen*2+2;
3047 *numoifs = numberoifs;
3051 for (i = 0; i < numberoifs; i++)
3052 if (xoifs[i].Filename) free (xoifs[i].Filename);
3063 header->version_major = dtoh32a(&data[off]);
3064 header->version_minor = dtoh32a(&data[off+=4]);
3065 header->lcd_aspect_ratio = dtoh32a(&data[off+=4]);
3066 header->palette_type = dtoh32a(&data[off+=4]);
3067 header->palette_data_start = dtoh32a(&data[off+=4]);
3068 header->vp_desc_start = dtoh32a(&data[off+=4]);
3069 header->bm_desc_start = dtoh32a(&data[off+=4]);
3070 if (header->version_minor > 1)
3071 header->bmo_desc_start = dtoh32a(&data[off+=4]);
3080 fd->fb_type = dtoh32a(&data[off]);
3081 fd->data_start = dtoh32a(&data[off+=4]);
3082 fd->buffer_width = dtoh32a(&data[off+=4]);
3083 fd->visible_width = dtoh32a(&data[off+=4]);
3084 fd->visible_height = dtoh32a(&data[off+=4]);
3085 fd->margin_left = dtoh32a(&data[off+=4]);
3086 fd->margin_top = dtoh32a(&data[off+=4]);
3087 fd->margin_right = dtoh32a(&data[off+=4]);
3088 fd->margin_bot = dtoh32a(&data[off+=4]);
Definition chdk_live_view.h:65