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)
138ptp_unpack_string(
PTPParams *params,
unsigned char* data, uint32_t offset, uint32_t total, uint8_t *len,
char **retstr)
141 uint16_t
string[PTP_MAXSTRLEN+1];
143 char loclstr[PTP_MAXSTRLEN*3+1];
144 size_t nconv, srclen, destlen;
150 if (offset + 1 > total)
153 length = dtoh8a(&data[offset]);
156 *retstr = strdup(
"");
160 if (offset + 1 + length*
sizeof(
string[0]) > total)
166 memcpy(
string, &data[offset+1], length *
sizeof(
string[0]));
167 string[length] = 0x0000U;
171 src = (
char *)
string;
172 srclen = length *
sizeof(
string[0]);
174 destlen =
sizeof(loclstr)-1;
176#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
177 if (params->cd_ucs2_to_locale != (iconv_t)-1)
178 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, &destlen);
180 if (nconv == (
size_t) -1) {
183 for (i=0;i<length;i++) {
184 if (dtoh16a(&data[offset+1+2*i])>127)
187 loclstr[i] = dtoh16a(&data[offset+1+2*i]);
189 dest = loclstr+length;
192 loclstr[
sizeof(loclstr)-1] =
'\0';
193 *retstr = strdup(loclstr);
198ucs2strlen(uint16_t
const *
const unicstr)
203 for(length = 0; unicstr[length] != 0x0000U; length ++);
209ptp_pack_string(
PTPParams *params,
char *
string,
unsigned char* data, uint16_t offset, uint8_t *len)
212 uint16_t ucs2str[PTP_MAXSTRLEN+1];
213 char *ucs2strp = (
char *) ucs2str;
214 size_t convlen = strlen(
string);
217 memset(ucs2strp, 0,
sizeof(ucs2str));
218#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
219 if (params->cd_locale_to_ucs2 != (iconv_t)-1) {
221 size_t convmax = PTP_MAXSTRLEN * 2;
222 char *stringp = string;
224 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen,
225 &ucs2strp, &convmax);
226 if (nconv == (
size_t) -1)
227 ucs2str[0] = 0x0000U;
233 for (i=0;i<convlen;i++) {
234 ucs2str[i] =
string[i];
236 ucs2str[convlen] = 0;
242 packedlen = ucs2strlen(ucs2str);
243 if (packedlen > PTP_MAXSTRLEN-1) {
249 htod8a(&data[offset],packedlen+1);
250 memcpy(&data[offset+1], &ucs2str[0], packedlen *
sizeof(ucs2str[0]));
251 htod16a(&data[offset+packedlen*2+1], 0x0000);
254 *len = (uint8_t) packedlen+1;
257static inline unsigned char *
258ptp_get_packed_stringcopy(
PTPParams *params,
char *
string, uint32_t *packed_size)
260 uint8_t packed[PTP_MAXSTRLEN*2+3], len;
262 unsigned char *retcopy = NULL;
265 ptp_pack_string(params,
"", (
unsigned char*) packed, 0, &len);
267 ptp_pack_string(params,
string, (
unsigned char*) packed, 0, &len);
272 retcopy = malloc(plen);
277 memcpy(retcopy, packed, plen);
282static inline uint32_t
283ptp_unpack_uint32_t_array(
PTPParams *params,
unsigned char* data,
unsigned int offset,
unsigned int datalen, uint32_t **array)
290 if (offset >= datalen)
293 if (offset +
sizeof(uint32_t) > datalen)
297 n=dtoh32a(&data[offset]);
298 if (n >= UINT_MAX/
sizeof(uint32_t))
303 if (offset +
sizeof(uint32_t)*(n+1) > datalen) {
304 ptp_debug (params ,
"array runs over datalen bufferend (%d vs %d)", offset +
sizeof(uint32_t)*(n+1) , datalen);
308 *array = malloc (n*
sizeof(uint32_t));
312 (*array)[i]=dtoh32a(&data[offset+(
sizeof(uint32_t)*(i+1))]);
316static inline uint32_t
317ptp_pack_uint32_t_array(
PTPParams *params, uint32_t *array, uint32_t arraylen,
unsigned char **data )
321 *data = malloc ((arraylen+1)*
sizeof(uint32_t));
324 htod32a(&(*data)[0],arraylen);
325 for (i=0;i<arraylen;i++)
326 htod32a(&(*data)[
sizeof(uint32_t)*(i+1)], array[i]);
327 return (arraylen+1)*
sizeof(uint32_t);
330static inline uint32_t
331ptp_unpack_uint16_t_array(
PTPParams *params,
unsigned char* data,
unsigned int offset,
unsigned int datalen, uint16_t **array)
339 if (datalen - offset <
sizeof(uint32_t))
341 n=dtoh32a(&data[offset]);
343 if (n >= (UINT_MAX - offset -
sizeof(uint32_t))/
sizeof(uint16_t))
347 if (offset +
sizeof(uint32_t) > datalen)
349 if (offset +
sizeof(uint32_t)+
sizeof(uint16_t)*n > datalen) {
350 ptp_debug (params ,
"array runs over datalen bufferend (%d vs %d)", offset +
sizeof(uint32_t)+n*
sizeof(uint16_t) , datalen);
353 *array = malloc (n*
sizeof(uint16_t));
357 (*array)[i]=dtoh16a(&data[offset+(
sizeof(uint16_t)*(i+2))]);
363#define PTP_di_StandardVersion 0
364#define PTP_di_VendorExtensionID 2
365#define PTP_di_VendorExtensionVersion 6
366#define PTP_di_VendorExtensionDesc 8
367#define PTP_di_FunctionalMode 8
368#define PTP_di_OperationsSupported 10
374 unsigned int totallen;
377 if (datalen < 12)
return 0;
378 memset (di, 0,
sizeof(*di));
379 di->StandardVersion = dtoh16a(&data[PTP_di_StandardVersion]);
380 di->VendorExtensionID =
381 dtoh32a(&data[PTP_di_VendorExtensionID]);
382 di->VendorExtensionVersion =
383 dtoh16a(&data[PTP_di_VendorExtensionVersion]);
384 if (!ptp_unpack_string(params, data,
385 PTP_di_VendorExtensionDesc,
388 &di->VendorExtensionDesc)
392 if (datalen <= totallen + PTP_di_FunctionalMode +
sizeof(uint16_t)) {
393 ptp_debug (params,
"datalen %d <= totallen + PTP_di_FunctionalMode + sizeof(uint16_t) %d", datalen, totallen + PTP_di_FunctionalMode +
sizeof(uint16_t));
397 dtoh16a(&data[PTP_di_FunctionalMode+totallen]);
398 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data,
399 PTP_di_OperationsSupported+totallen,
401 &di->OperationsSupported);
402 totallen=totallen+di->OperationsSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
403 if (datalen <= totallen+PTP_di_OperationsSupported) {
404 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 1", datalen, totallen+PTP_di_OperationsSupported);
407 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data,
408 PTP_di_OperationsSupported+totallen,
410 &di->EventsSupported);
411 totallen=totallen+di->EventsSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
412 if (datalen <= totallen+PTP_di_OperationsSupported) {
413 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 2", datalen, totallen+PTP_di_OperationsSupported);
416 di->DevicePropertiesSupported_len =
417 ptp_unpack_uint16_t_array(params, data,
418 PTP_di_OperationsSupported+totallen,
420 &di->DevicePropertiesSupported);
421 totallen=totallen+di->DevicePropertiesSupported_len*
sizeof(uint16_t)+
sizeof(uint32_t);
422 if (datalen <= totallen+PTP_di_OperationsSupported) {
423 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 3", datalen, totallen+PTP_di_OperationsSupported);
426 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data,
427 PTP_di_OperationsSupported+totallen,
429 &di->CaptureFormats);
430 totallen=totallen+di->CaptureFormats_len*
sizeof(uint16_t)+
sizeof(uint32_t);
431 if (datalen <= totallen+PTP_di_OperationsSupported) {
432 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 4", datalen, totallen+PTP_di_OperationsSupported);
435 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data,
436 PTP_di_OperationsSupported+totallen,
439 totallen=totallen+di->ImageFormats_len*
sizeof(uint16_t)+
sizeof(uint32_t);
440 if (datalen <= totallen+PTP_di_OperationsSupported) {
441 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 5", datalen, totallen+PTP_di_OperationsSupported);
444 if (!ptp_unpack_string(params, data,
445 PTP_di_OperationsSupported+totallen,
453 if (datalen <= totallen+PTP_di_OperationsSupported) {
454 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 6", datalen, totallen+PTP_di_OperationsSupported);
457 if (!ptp_unpack_string(params, data,
458 PTP_di_OperationsSupported+totallen,
466 if (datalen <= totallen+PTP_di_OperationsSupported) {
467 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 7", datalen, totallen+PTP_di_OperationsSupported);
470 if (!ptp_unpack_string(params, data,
471 PTP_di_OperationsSupported+totallen,
479 if (datalen <= totallen+PTP_di_OperationsSupported) {
480 ptp_debug (params,
"datalen %d <= totallen+PTP_di_OperationsSupported %d 8", datalen, totallen+PTP_di_OperationsSupported);
483 if (!ptp_unpack_string(params, data,
484 PTP_di_OperationsSupported+totallen,
495 free (di->SerialNumber);
496 free (di->DeviceVersion);
498 free (di->Manufacturer);
499 free (di->ImageFormats);
500 free (di->CaptureFormats);
501 free (di->VendorExtensionDesc);
502 free (di->OperationsSupported);
503 free (di->EventsSupported);
504 free (di->DevicePropertiesSupported);
505 memset(di, 0,
sizeof(*di));
512 unsigned int totallen = 4;
514 memset (di,0,
sizeof(*di));
515 if (datalen < 8)
return 0;
518 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data,
519 totallen, datalen, &di->EventsSupported);
520 if (!di->EventsSupported)
return 0;
521 totallen += di->EventsSupported_len*
sizeof(uint32_t)+4;
522 if (totallen >= datalen)
return 0;
524 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, data,
525 totallen, datalen, &di->DevicePropertiesSupported);
526 if (!di->DevicePropertiesSupported)
return 0;
527 totallen += di->DevicePropertiesSupported_len*
sizeof(uint32_t)+4;
528 if (totallen >= datalen)
return 0;
530 di->unk_len = ptp_unpack_uint32_t_array(params, data,
531 totallen, datalen, &di->unk);
532 if (!di->unk)
return 0;
533 totallen += di->unk_len*
sizeof(uint32_t)+4;
540 free (di->EventsSupported);
541 free (di->DevicePropertiesSupported);
553 oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, len, &oh->Handler);
568 sids->Storage = NULL;
573 sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids, len, &sids->Storage);
578#define PTP_si_StorageType 0
579#define PTP_si_FilesystemType 2
580#define PTP_si_AccessCapability 4
581#define PTP_si_MaxCapability 6
582#define PTP_si_FreeSpaceInBytes 14
583#define PTP_si_FreeSpaceInImages 22
584#define PTP_si_StorageDescription 26
589 uint8_t storagedescriptionlen;
591 if (len < 26)
return 0;
592 si->StorageType=dtoh16a(&data[PTP_si_StorageType]);
593 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]);
594 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]);
595 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]);
596 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]);
597 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]);
600 if (!ptp_unpack_string(params, data,
601 PTP_si_StorageDescription,
603 &storagedescriptionlen,
604 &si->StorageDescription)
608 if (!ptp_unpack_string(params, data,
609 PTP_si_StorageDescription+storagedescriptionlen*2+1,
611 &storagedescriptionlen,
613 ptp_debug(params,
"could not unpack storage description");
621#define PTP_oi_StorageID 0
622#define PTP_oi_ObjectFormat 4
623#define PTP_oi_ProtectionStatus 6
624#define PTP_oi_ObjectCompressedSize 8
625#define PTP_oi_ThumbFormat 12
626#define PTP_oi_ThumbCompressedSize 14
627#define PTP_oi_ThumbPixWidth 18
628#define PTP_oi_ThumbPixHeight 22
629#define PTP_oi_ImagePixWidth 26
630#define PTP_oi_ImagePixHeight 30
631#define PTP_oi_ImageBitDepth 34
632#define PTP_oi_ParentObject 38
633#define PTP_oi_AssociationType 42
634#define PTP_oi_AssociationDesc 44
635#define PTP_oi_SequenceNumber 48
636#define PTP_oi_filenamelen 52
637#define PTP_oi_Filename 53
641#define PTP_oi_MaxLen PTP_oi_Filename+(PTP_MAXSTRLEN+1)*2+3
643static inline uint32_t
646 unsigned char* oidata;
648 uint8_t capturedatelen=0;
650 oidata=malloc(PTP_oi_MaxLen + params->ocs64*4);
654 char *capture_date=
"20020101T010101";
656 memset (oidata, 0, PTP_oi_MaxLen + params->ocs64*4);
657 htod32a(&oidata[PTP_oi_StorageID],oi->StorageID);
658 htod16a(&oidata[PTP_oi_ObjectFormat],oi->ObjectFormat);
659 htod16a(&oidata[PTP_oi_ProtectionStatus],oi->ProtectionStatus);
660 htod32a(&oidata[PTP_oi_ObjectCompressedSize],oi->ObjectCompressedSize);
663 htod16a(&oidata[PTP_oi_ThumbFormat],oi->ThumbFormat);
664 htod32a(&oidata[PTP_oi_ThumbCompressedSize],oi->ThumbCompressedSize);
665 htod32a(&oidata[PTP_oi_ThumbPixWidth],oi->ThumbPixWidth);
666 htod32a(&oidata[PTP_oi_ThumbPixHeight],oi->ThumbPixHeight);
667 htod32a(&oidata[PTP_oi_ImagePixWidth],oi->ImagePixWidth);
668 htod32a(&oidata[PTP_oi_ImagePixHeight],oi->ImagePixHeight);
669 htod32a(&oidata[PTP_oi_ImageBitDepth],oi->ImageBitDepth);
670 htod32a(&oidata[PTP_oi_ParentObject],oi->ParentObject);
671 htod16a(&oidata[PTP_oi_AssociationType],oi->AssociationType);
672 htod32a(&oidata[PTP_oi_AssociationDesc],oi->AssociationDesc);
673 htod32a(&oidata[PTP_oi_SequenceNumber],oi->SequenceNumber);
675 ptp_pack_string(params, oi->Filename, oidata, PTP_oi_filenamelen, &filenamelen);
689 capturedatelen=strlen(capture_date);
690 htod8a(&data[PTP_oi_Filename+(filenamelen+1)*2],
692 for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
693 data[PTP_oi_Filename+(i+filenamelen+1)*2+1]=capture_date[i];
695 htod8a(&data[PTP_oi_Filename+(filenamelen+capturedatelen+2)*2+1],
697 for (i=0;i<capturedatelen && i< PTP_MAXSTRLEN; i++) {
698 data[PTP_oi_Filename+(i+filenamelen+capturedatelen+2)*2+2]=
703 return (PTP_oi_Filename+filenamelen*2+(capturedatelen+1)*3)+params->ocs64*4;
707ptp_unpack_PTPTIME (
const char *str) {
715 ptpdatelen = strlen(str);
716 if (ptpdatelen >=
sizeof (ptpdate)) {
724 strncpy (ptpdate, str,
sizeof(ptpdate));
725 ptpdate[
sizeof(ptpdate) - 1] =
'\0';
727 memset(&tm,0,
sizeof(tm));
728 strncpy (tmp, ptpdate, 4);
730 tm.tm_year=atoi (tmp) - 1900;
731 strncpy (tmp, ptpdate + 4, 2);
733 tm.tm_mon = atoi (tmp) - 1;
734 strncpy (tmp, ptpdate + 6, 2);
736 tm.tm_mday = atoi (tmp);
737 strncpy (tmp, ptpdate + 9, 2);
739 tm.tm_hour = atoi (tmp);
740 strncpy (tmp, ptpdate + 11, 2);
742 tm.tm_min = atoi (tmp);
743 strncpy (tmp, ptpdate + 13, 2);
745 tm.tm_sec = atoi (tmp);
754 uint8_t capturedatelen;
757 if (len < PTP_oi_SequenceNumber)
760 oi->Filename = oi->Keywords = NULL;
763 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]);
764 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]);
765 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]);
766 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]);
769 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)) {
770 ptp_debug (params,
"objectsize 64bit detected!");
775 oi->ThumbFormat=dtoh16a(&data[PTP_oi_ThumbFormat]);
776 oi->ThumbCompressedSize=dtoh32a(&data[PTP_oi_ThumbCompressedSize]);
777 oi->ThumbPixWidth=dtoh32a(&data[PTP_oi_ThumbPixWidth]);
778 oi->ThumbPixHeight=dtoh32a(&data[PTP_oi_ThumbPixHeight]);
779 oi->ImagePixWidth=dtoh32a(&data[PTP_oi_ImagePixWidth]);
780 oi->ImagePixHeight=dtoh32a(&data[PTP_oi_ImagePixHeight]);
781 oi->ImageBitDepth=dtoh32a(&data[PTP_oi_ImageBitDepth]);
782 oi->ParentObject=dtoh32a(&data[PTP_oi_ParentObject]);
783 oi->AssociationType=dtoh16a(&data[PTP_oi_AssociationType]);
784 oi->AssociationDesc=dtoh32a(&data[PTP_oi_AssociationDesc]);
785 oi->SequenceNumber=dtoh32a(&data[PTP_oi_SequenceNumber]);
787 ptp_unpack_string(params, data, PTP_oi_filenamelen, len, &filenamelen, &oi->Filename);
788 ptp_unpack_string(params, data, PTP_oi_filenamelen+filenamelen*2+1, len, &capturedatelen, &capture_date);
792 oi->CaptureDate = ptp_unpack_PTPTIME(capture_date);
796 ptp_unpack_string(params, data,
797 PTP_oi_filenamelen+filenamelen*2
798 +capturedatelen*2+2, len, &capturedatelen, &capture_date
800 oi->ModificationDate = ptp_unpack_PTPTIME(capture_date);
805#define CTVAL(target,func) { \
806 if (total - *offset < sizeof(target)) \
808 target = func(&data[*offset]); \
809 *offset += sizeof(target); \
812#define RARR(val,member,func) { \
814 if (total - *offset < sizeof(uint32_t)) \
816 n = dtoh32a (&data[*offset]); \
817 *offset += sizeof(uint32_t); \
819 if (n >= UINT_MAX/sizeof(val->a.v[0])) \
821 if (n > (total - (*offset))/sizeof(val->a.v[0]))\
824 val->a.v = malloc(sizeof(val->a.v[0])*n); \
825 if (!val->a.v) return 0; \
827 CTVAL(val->a.v[j].member, func); \
830static inline unsigned int
832 PTPParams *params,
unsigned char* data,
unsigned int *offset,
unsigned int total,
835 if (*offset >= total)
840 CTVAL(value->i8,dtoh8a);
843 CTVAL(value->u8,dtoh8a);
846 CTVAL(value->i16,dtoh16a);
849 CTVAL(value->u16,dtoh16a);
852 CTVAL(value->i32,dtoh32a);
855 CTVAL(value->u32,dtoh32a);
858 CTVAL(value->i64,dtoh64a);
861 CTVAL(value->u64,dtoh64a);
864 case PTP_DTC_UINT128:
876 RARR(value,i8,dtoh8a);
879 RARR(value,u8,dtoh8a);
881 case PTP_DTC_AUINT16:
882 RARR(value,u16,dtoh16a);
885 RARR(value,i16,dtoh16a);
887 case PTP_DTC_AUINT32:
888 RARR(value,u32,dtoh32a);
891 RARR(value,i32,dtoh32a);
893 case PTP_DTC_AUINT64:
894 RARR(value,u64,dtoh64a);
897 RARR(value,i64,dtoh64a);
905 if (*offset >= total+1)
908 if (!ptp_unpack_string(params,data,*offset,total,&len,&value->str))
920#define PTP_dpd_DevicePropertyCode 0
921#define PTP_dpd_DataType 2
922#define PTP_dpd_GetSet 4
923#define PTP_dpd_FactoryDefaultValue 5
928 unsigned int offset = 0, ret;
932 memset (dpd, 0,
sizeof(*dpd));
935 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]);
936 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]);
937 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]);
938 dpd->FormFlag=PTP_DPFF_None;
940 offset = PTP_dpd_FactoryDefaultValue;
941 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaultValue, dpd->DataType);
942 if (!ret)
goto outofmemory;
943 if ((dpd->DataType == PTP_DTC_STR) && (offset == dpdlen)) {
947 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->CurrentValue, dpd->DataType);
948 if (!ret)
goto outofmemory;
955 if (offset +
sizeof(uint8_t) > dpdlen) {
960 dpd->FormFlag=dtoh8a(&data[offset]);
961 offset+=
sizeof(uint8_t);
963 switch (dpd->FormFlag) {
965 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MinimumValue, dpd->DataType);
966 if (!ret)
goto outofmemory;
967 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.MaximumValue, dpd->DataType);
968 if (!ret)
goto outofmemory;
969 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Range.StepSize, dpd->DataType);
970 if (!ret)
goto outofmemory;
972 case PTP_DPFF_Enumeration: {
974#define N dpd->FORM.Enum.NumberOfValues
976 if (offset +
sizeof(uint16_t) > dpdlen)
goto outofmemory;
978 N = dtoh16a(&data[offset]);
979 offset+=
sizeof(uint16_t);
980 dpd->FORM.Enum.SupportedValue = malloc(N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
981 if (!dpd->FORM.Enum.SupportedValue)
984 memset (dpd->FORM.Enum.SupportedValue,0 , N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
986 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);
996 dpd->FORM.Enum.NumberOfValues = i;
1003 *newoffset = offset;
1006 ptp_free_devicepropdesc(dpd);
1011#define PTP_dpd_Sony_DevicePropertyCode 0
1012#define PTP_dpd_Sony_DataType 2
1013#define PTP_dpd_Sony_ChangeMethod 4
1014#define PTP_dpd_Sony_GetSet 5
1015#define PTP_dpd_Sony_FactoryDefaultValue 6
1018ptp_unpack_Sony_DPD (
PTPParams *params,
unsigned char* data,
PTPDevicePropDesc *dpd,
unsigned int dpdlen,
unsigned int *poffset)
1021 unsigned int changemethod, getset;
1023 memset (dpd, 0,
sizeof(*dpd));
1024 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_Sony_DevicePropertyCode]);
1025 dpd->DataType=dtoh16a(&data[PTP_dpd_Sony_DataType]);
1027 changemethod = dtoh8a(&data[PTP_dpd_Sony_ChangeMethod]);
1028 getset = dtoh8a(&data[PTP_dpd_Sony_GetSet]);
1030 ptp_debug (params,
"prop 0x%04x, datatype 0x%04x, changemethod %d getset %d", dpd->DevicePropertyCode, dpd->DataType, changemethod, getset);
1043 dpd->FormFlag=PTP_DPFF_None;
1045 *poffset = PTP_dpd_Sony_FactoryDefaultValue;
1046 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FactoryDefaultValue, dpd->DataType);
1047 if (!ret)
goto outofmemory;
1048 if ((dpd->DataType == PTP_DTC_STR) && (*poffset == dpdlen))
1050 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->CurrentValue, dpd->DataType);
1051 if (!ret)
goto outofmemory;
1058 if (*poffset==PTP_dpd_Sony_FactoryDefaultValue)
1061 dpd->FormFlag=dtoh8a(&data[*poffset]);
1062 *poffset+=
sizeof(uint8_t);
1064 switch (dpd->FormFlag) {
1065 case PTP_DPFF_Range:
1066 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.MinimumValue, dpd->DataType);
1067 if (!ret)
goto outofmemory;
1068 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.MaximumValue, dpd->DataType);
1069 if (!ret)
goto outofmemory;
1070 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Range.StepSize, dpd->DataType);
1071 if (!ret)
goto outofmemory;
1073 case PTP_DPFF_Enumeration: {
1075#define N dpd->FORM.Enum.NumberOfValues
1076 N = dtoh16a(&data[*poffset]);
1077 *poffset+=
sizeof(uint16_t);
1078 dpd->FORM.Enum.SupportedValue = malloc(N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
1079 if (!dpd->FORM.Enum.SupportedValue)
1082 memset (dpd->FORM.Enum.SupportedValue,0 , N*
sizeof(dpd->FORM.Enum.SupportedValue[0]));
1084 ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);
1094 dpd->FORM.Enum.NumberOfValues = i;
1103 ptp_free_devicepropdesc(dpd);
1109 if (type == PTP_DTC_STR) {
1111 dst->str = strdup(src->str);
1117 if (type & PTP_DTC_ARRAY_MASK) {
1120 dst->a.count = src->a.count;
1121 dst->a.v = malloc (
sizeof(src->a.v[0])*src->a.count);
1122 for (i=0;i<src->a.count;i++)
1123 duplicate_PropertyValue (&src->a.v[i], &dst->a.v[i], type & ~PTP_DTC_ARRAY_MASK);
1126 switch (type & ~PTP_DTC_ARRAY_MASK) {
1127 case PTP_DTC_INT8: dst->i8 = src->i8;
break;
1128 case PTP_DTC_UINT8: dst->u8 = src->u8;
break;
1129 case PTP_DTC_INT16: dst->i16 = src->i16;
break;
1130 case PTP_DTC_UINT16: dst->u16 = src->u16;
break;
1131 case PTP_DTC_INT32: dst->i32 = src->i32;
break;
1132 case PTP_DTC_UINT32: dst->u32 = src->u32;
break;
1133 case PTP_DTC_UINT64: dst->u64 = src->u64;
break;
1134 case PTP_DTC_INT64: dst->i64 = src->i64;
break;
1136 case PTP_DTC_INT128: dst->i128 = src->i128;
break;
1137 case PTP_DTC_UINT128: dst->u128 = src->u128;
break;
1148 dst->DevicePropertyCode = src->DevicePropertyCode;
1149 dst->DataType = src->DataType;
1150 dst->GetSet = src->GetSet;
1152 duplicate_PropertyValue (&src->FactoryDefaultValue, &dst->FactoryDefaultValue, src->DataType);
1153 duplicate_PropertyValue (&src->CurrentValue, &dst->CurrentValue, src->DataType);
1155 dst->FormFlag = src->FormFlag;
1156 switch (src->FormFlag) {
1157 case PTP_DPFF_Range:
1158 duplicate_PropertyValue (&src->FORM.Range.MinimumValue, &dst->FORM.Range.MinimumValue, src->DataType);
1159 duplicate_PropertyValue (&src->FORM.Range.MaximumValue, &dst->FORM.Range.MaximumValue, src->DataType);
1160 duplicate_PropertyValue (&src->FORM.Range.StepSize, &dst->FORM.Range.StepSize, src->DataType);
1162 case PTP_DPFF_Enumeration:
1163 dst->FORM.Enum.NumberOfValues = src->FORM.Enum.NumberOfValues;
1164 dst->FORM.Enum.SupportedValue = malloc (
sizeof(dst->FORM.Enum.SupportedValue[0])*src->FORM.Enum.NumberOfValues);
1165 for (i = 0; i<src->FORM.Enum.NumberOfValues ; i++)
1166 duplicate_PropertyValue (&src->FORM.Enum.SupportedValue[i], &dst->FORM.Enum.SupportedValue[i], src->DataType);
1173#define PTP_opd_ObjectPropertyCode 0
1174#define PTP_opd_DataType 2
1175#define PTP_opd_GetSet 4
1176#define PTP_opd_FactoryDefaultValue 5
1181 unsigned int offset=0, ret;
1184 memset (opd, 0,
sizeof(*opd));
1189 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]);
1190 opd->DataType=dtoh16a(&data[PTP_opd_DataType]);
1191 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]);
1193 offset = PTP_opd_FactoryDefaultValue;
1194 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
1195 if (!ret)
goto outofmemory;
1197 if (offset +
sizeof(uint32_t) > opdlen)
goto outofmemory;
1198 opd->GroupCode=dtoh32a(&data[offset]);
1199 offset+=
sizeof(uint32_t);
1201 if (offset +
sizeof(uint8_t) > opdlen)
goto outofmemory;
1202 opd->FormFlag=dtoh8a(&data[offset]);
1203 offset+=
sizeof(uint8_t);
1205 switch (opd->FormFlag) {
1206 case PTP_OPFF_Range:
1207 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
1208 if (!ret)
goto outofmemory;
1209 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
1210 if (!ret)
goto outofmemory;
1211 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
1212 if (!ret)
goto outofmemory;
1214 case PTP_OPFF_Enumeration: {
1216#define N opd->FORM.Enum.NumberOfValues
1218 if (offset +
sizeof(uint16_t) > opdlen)
goto outofmemory;
1219 N = dtoh16a(&data[offset]);
1220 offset+=
sizeof(uint16_t);
1222 opd->FORM.Enum.SupportedValue = malloc(N*
sizeof(opd->FORM.Enum.SupportedValue[0]));
1223 if (!opd->FORM.Enum.SupportedValue)
1226 memset (opd->FORM.Enum.SupportedValue,0 , N*
sizeof(opd->FORM.Enum.SupportedValue[0]));
1228 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
1238 opd->FORM.Enum.NumberOfValues = i;
1245 case PTP_OPFF_DateTime:
1246 if (!ptp_unpack_string(params, data, offset, opdlen, &len, &opd->FORM.DateTime.String))
1247 opd->FORM.DateTime.String = NULL;
1250 case PTP_OPFF_RegularExpression:
1251 if (!ptp_unpack_string(params, data, offset, opdlen, &len, &opd->FORM.RegularExpression.String))
1252 opd->FORM.RegularExpression.String = NULL;
1255 case PTP_OPFF_FixedLengthArray:
1256 if (offset +
sizeof(uint16_t) > opdlen)
goto outofmemory;
1257 opd->FORM.FixedLengthArray.NumberOfValues = dtoh16a(&data[offset]);
1258 offset +=
sizeof(uint16_t);
1260 case PTP_OPFF_ByteArray:
1261 if (offset +
sizeof(uint16_t) > opdlen)
goto outofmemory;
1262 opd->FORM.ByteArray.NumberOfValues = dtoh16a(&data[offset]);
1263 offset +=
sizeof(uint16_t);
1265 case PTP_OPFF_LongString:
1270 ptp_free_objectpropdesc(opd);
1274static inline uint32_t
1277 unsigned char* dpv=NULL;
1283 size=
sizeof(int8_t);
1285 htod8a(dpv,value->i8);
1288 size=
sizeof(uint8_t);
1290 htod8a(dpv,value->u8);
1293 size=
sizeof(int16_t);
1295 htod16a(dpv,value->i16);
1297 case PTP_DTC_UINT16:
1298 size=
sizeof(uint16_t);
1300 htod16a(dpv,value->u16);
1303 size=
sizeof(int32_t);
1305 htod32a(dpv,value->i32);
1307 case PTP_DTC_UINT32:
1308 size=
sizeof(uint32_t);
1310 htod32a(dpv,value->u32);
1313 size=
sizeof(int64_t);
1315 htod64a(dpv,value->i64);
1317 case PTP_DTC_UINT64:
1318 size=
sizeof(uint64_t);
1320 htod64a(dpv,value->u64);
1322 case PTP_DTC_AUINT8:
1323 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint8_t);
1325 htod32a(dpv,value->a.count);
1326 for (i=0;i<value->a.count;i++)
1327 htod8a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint8_t)],value->a.v[i].u8);
1330 size=
sizeof(uint32_t)+value->a.count*
sizeof(int8_t);
1332 htod32a(dpv,value->a.count);
1333 for (i=0;i<value->a.count;i++)
1334 htod8a(&dpv[
sizeof(uint32_t)+i*
sizeof(int8_t)],value->a.v[i].i8);
1336 case PTP_DTC_AUINT16:
1337 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint16_t);
1339 htod32a(dpv,value->a.count);
1340 for (i=0;i<value->a.count;i++)
1341 htod16a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint16_t)],value->a.v[i].u16);
1343 case PTP_DTC_AINT16:
1344 size=
sizeof(uint32_t)+value->a.count*
sizeof(int16_t);
1346 htod32a(dpv,value->a.count);
1347 for (i=0;i<value->a.count;i++)
1348 htod16a(&dpv[
sizeof(uint32_t)+i*
sizeof(int16_t)],value->a.v[i].i16);
1350 case PTP_DTC_AUINT32:
1351 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint32_t);
1353 htod32a(dpv,value->a.count);
1354 for (i=0;i<value->a.count;i++)
1355 htod32a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint32_t)],value->a.v[i].u32);
1357 case PTP_DTC_AINT32:
1358 size=
sizeof(uint32_t)+value->a.count*
sizeof(int32_t);
1360 htod32a(dpv,value->a.count);
1361 for (i=0;i<value->a.count;i++)
1362 htod32a(&dpv[
sizeof(uint32_t)+i*
sizeof(int32_t)],value->a.v[i].i32);
1364 case PTP_DTC_AUINT64:
1365 size=
sizeof(uint32_t)+value->a.count*
sizeof(uint64_t);
1367 htod32a(dpv,value->a.count);
1368 for (i=0;i<value->a.count;i++)
1369 htod64a(&dpv[
sizeof(uint32_t)+i*
sizeof(uint64_t)],value->a.v[i].u64);
1371 case PTP_DTC_AINT64:
1372 size=
sizeof(uint32_t)+value->a.count*
sizeof(int64_t);
1374 htod32a(dpv,value->a.count);
1375 for (i=0;i<value->a.count;i++)
1376 htod64a(&dpv[
sizeof(uint32_t)+i*
sizeof(int64_t)],value->a.v[i].i64);
1380 dpv=ptp_get_packed_stringcopy(params, value->str, &size);
1388#define MAX_MTP_PROPS 127
1389static inline uint32_t
1392 unsigned char* opldata;
1394 unsigned char *packedprops[MAX_MTP_PROPS];
1395 uint32_t packedpropslens[MAX_MTP_PROPS];
1396 uint32_t packedobjecthandles[MAX_MTP_PROPS];
1397 uint16_t packedpropsids[MAX_MTP_PROPS];
1398 uint16_t packedpropstypes[MAX_MTP_PROPS];
1399 uint32_t totalsize = 0;
1401 uint32_t noitems = 0;
1404 totalsize =
sizeof(uint32_t);
1406 while (nrofprops-- && noitems < MAX_MTP_PROPS) {
1408 packedobjecthandles[noitems]=propitr->ObjectHandle;
1409 totalsize +=
sizeof(uint32_t);
1411 packedpropsids[noitems]=propitr->property;
1412 totalsize +=
sizeof(uint16_t);
1414 packedpropstypes[noitems]= propitr->datatype;
1415 totalsize +=
sizeof(uint16_t);
1417 packedpropslens[noitems] = ptp_pack_DPV (params, &propitr->propval, &packedprops[noitems], propitr->datatype);
1418 totalsize += packedpropslens[noitems];
1424 opldata = malloc(totalsize);
1426 htod32a(&opldata[bufp],noitems);
1430 for (i = 0; i < noitems; i++) {
1432 htod32a(&opldata[bufp],packedobjecthandles[i]);
1433 bufp +=
sizeof(uint32_t);
1434 htod16a(&opldata[bufp],packedpropsids[i]);
1435 bufp +=
sizeof(uint16_t);
1436 htod16a(&opldata[bufp],packedpropstypes[i]);
1437 bufp +=
sizeof(uint16_t);
1439 memcpy(&opldata[bufp], packedprops[i], packedpropslens[i]);
1440 bufp += packedpropslens[i];
1441 free(packedprops[i]);
1443 *opldataptr = opldata;
1448_compare_func(
const void* x,
const void *y) {
1452 return px->ObjectHandle - py->ObjectHandle;
1458 uint32_t prop_count;
1460 unsigned int offset = 0, i;
1462 if (len <
sizeof(uint32_t)) {
1463 ptp_debug (params ,
"must have at least 4 bytes data, not %d", len);
1467 prop_count = dtoh32a(data);
1469 if (prop_count == 0)
1473 ptp_debug (params ,
"prop_count %d is too large", prop_count);
1476 ptp_debug (params ,
"Unpacking MTP OPL, size %d (prop_count %d)", len, prop_count);
1478 data +=
sizeof(uint32_t);
1479 len -=
sizeof(uint32_t);
1481 if (!props)
return 0;
1482 for (i = 0; i < prop_count; i++) {
1483 if (len <= (
sizeof(uint32_t) +
sizeof(uint16_t) +
sizeof(uint16_t))) {
1484 ptp_debug (params ,
"short MTP Object Property List at property %d (of %d)", i, prop_count);
1485 ptp_debug (params ,
"device probably needs DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL");
1486 ptp_debug (params ,
"or even DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST", i);
1493 props[i].ObjectHandle = dtoh32a(data);
1494 data +=
sizeof(uint32_t);
1495 len -=
sizeof(uint32_t);
1497 props[i].property = dtoh16a(data);
1498 data +=
sizeof(uint16_t);
1499 len -=
sizeof(uint16_t);
1501 props[i].datatype = dtoh16a(data);
1502 data +=
sizeof(uint16_t);
1503 len -=
sizeof(uint16_t);
1506 if (!ptp_unpack_DPV(params, data, &offset, len, &props[i].propval, props[i].datatype)) {
1507 ptp_debug (params ,
"unpacking DPV of property %d encountered insufficient buffer. attack?", i);
1515 qsort (props, prop_count,
sizeof(
MTPProperties),_compare_func);
1525#define PTP_ec_Length 0
1526#define PTP_ec_Type 4
1527#define PTP_ec_Code 6
1528#define PTP_ec_TransId 8
1529#define PTP_ec_Param1 12
1530#define PTP_ec_Param2 16
1531#define PTP_ec_Param3 20
1536 unsigned int length;
1541 memset(ec,0,
sizeof(*ec));
1543 length=dtoh32a(&data[PTP_ec_Length]);
1545 ptp_debug (params,
"length %d in container, but data only %d bytes?!", length, len);
1548 type = dtoh16a(&data[PTP_ec_Type]);
1550 ec->Code=dtoh16a(&data[PTP_ec_Code]);
1551 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]);
1553 if (type!=PTP_USB_CONTAINER_EVENT) {
1554 ptp_debug (params,
"Unknown canon event type %d (code=%x,tid=%x), please report!",type,ec->Code,ec->Transaction_ID);
1557 if (length>=(PTP_ec_Param1+4)) {
1558 ec->Param1=dtoh32a(&data[PTP_ec_Param1]);
1561 if (length>=(PTP_ec_Param2+4)) {
1562 ec->Param2=dtoh32a(&data[PTP_ec_Param2]);
1565 if (length>=(PTP_ec_Param3+4)) {
1566 ec->Param3=dtoh32a(&data[PTP_ec_Param3]);
1575#define PTP_cfe_ObjectHandle 0
1576#define PTP_cfe_ObjectFormatCode 4
1577#define PTP_cfe_Flags 6
1578#define PTP_cfe_ObjectSize 7
1579#define PTP_cfe_Time 11
1580#define PTP_cfe_Filename 15
1588 fe->ObjectHandle=dtoh32a(&data[PTP_cfe_ObjectHandle]);
1589 fe->ObjectFormatCode=dtoh16a(&data[PTP_cfe_ObjectFormatCode]);
1590 fe->Flags=dtoh8a(&data[PTP_cfe_Flags]);
1591 fe->ObjectSize=dtoh32a((
unsigned char*)&data[PTP_cfe_ObjectSize]);
1592 fe->Time=(time_t)dtoh32a(&data[PTP_cfe_Time]);
1593 for (i=0; i<PTP_CANON_FilenameBufferLen; i++)
1594 fe->Filename[i]=(
char)dtoh8a(&data[PTP_cfe_Filename+i]);
1649#define PTP_cefe_ObjectHandle 0
1650#define PTP_cefe_StorageID 4
1651#define PTP_cefe_ObjectFormatCode 8
1652#define PTP_cefe_Flags 16
1653#define PTP_cefe_ObjectSize 20
1654#define PTP_cefe_Filename 32
1655#define PTP_cefe_Time 48
1662 if (size < PTP_cefe_Time + 4)
return;
1664 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]);
1665 fe->ObjectFormatCode=dtoh16a(&data[PTP_cefe_ObjectFormatCode]);
1666 fe->Flags=dtoh8a(&data[PTP_cefe_Flags]);
1667 fe->ObjectSize=dtoh32a((
unsigned char*)&data[PTP_cefe_ObjectSize]);
1668 fe->Time=(time_t)dtoh32a(&data[PTP_cefe_Time]);
1669 for (i=0; i<PTP_CANON_FilenameBufferLen; i++)
1670 fe->Filename[i]=(
char)data[PTP_cefe_Filename+i];
1671 fe->Filename[PTP_CANON_FilenameBufferLen-1] = 0;
1675static inline uint16_t
1676ptp_unpack_EOS_ImageFormat (
PTPParams* params,
unsigned char** data )
1708 const unsigned char* d = *data;
1709 uint32_t n = dtoh32a( d );
1710 uint32_t l, t1, s1, c1, t2 = 0, s2 = 0, c2 = 0;
1712 if (n != 1 && n !=2) {
1713 ptp_debug (params,
"parsing EOS ImageFormat property failed (n != 1 && n != 2: %d)", n);
1717 l = dtoh32a( d+=4 );
1719 ptp_debug (params,
"parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
1723 t1 = dtoh32a( d+=4 );
1724 s1 = dtoh32a( d+=4 );
1725 c1 = dtoh32a( d+=4 );
1728 l = dtoh32a( d+=4 );
1730 ptp_debug (params,
"parsing EOS ImageFormat property failed (l != 0x10: 0x%x)", l);
1733 t2 = dtoh32a( d+=4 );
1734 s2 = dtoh32a( d+=4 );
1735 c2 = dtoh32a( d+=4 );
1738 *data = (
unsigned char*) d+4;
1747 c1 |= (t1 == 6) ? 8 : 0;
1748 c2 |= (t2 == 6) ? 8 : 0;
1750 return ((s1 & 0xF) << 12) | ((c1 & 0xF) << 8) | ((s2 & 0xF) << 4) | ((c2 & 0xF) << 0);
1753static inline uint32_t
1754ptp_pack_EOS_ImageFormat (
PTPParams* params,
unsigned char* data, uint16_t value)
1756 uint32_t n = (value & 0xFF) ? 2 : 1;
1757 uint32_t s = 4 + 0x10 * n;
1762#define PACK_5DM3_SMALL_JPEG_SIZE( X ) (X) >= 0xd ? (X)+1 : (X)
1764 htod32a(data+=0, n);
1765 htod32a(data+=4, 0x10);
1766 htod32a(data+=4, (((value >> 8) & 0xF) >> 3) ? 6 : 1);
1767 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 12) & 0xF));
1768 htod32a(data+=4, ((value >> 8) & 0xF) & ~8);
1771 htod32a(data+=4, 0x10);
1772 htod32a(data+=4, (((value >> 0) & 0xF) >> 3) ? 6 : 1);
1773 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF));
1774 htod32a(data+=4, ((value >> 0) & 0xF) & ~8);
1777#undef PACK_5DM3_SMALL_JPEG_SIZE
1801ptp_unpack_EOS_FocusInfoEx (
PTPParams* params,
unsigned char** data, uint32_t datasize )
1803 uint32_t size = dtoh32a( *data );
1804 uint32_t halfsize = dtoh16a( (*data) + 4);
1805 uint32_t version = dtoh16a( (*data) + 6);
1806 uint32_t focus_points_in_struct = dtoh16a( (*data) + 8);
1807 uint32_t focus_points_in_use = dtoh16a( (*data) + 10);
1808 uint32_t sizeX = dtoh16a( (*data) + 12);
1809 uint32_t sizeY = dtoh16a( (*data) + 14);
1810 uint32_t size2X = dtoh16a( (*data) + 16);
1811 uint32_t size2Y = dtoh16a( (*data) + 18);
1816 if ((size >= datasize) || (size < 20))
1817 return strdup(
"bad size 1");
1820 if (!focus_points_in_struct || !focus_points_in_use) {
1821 ptp_debug(params,
"skipped FocusInfoEx data (zero filled)");
1822 return strdup(
"no focus points returned by camera");
1829 if (size < focus_points_in_struct*8) {
1830 ptp_error(params,
"focus_points_in_struct %d is too large vs size %d", focus_points_in_struct, size);
1831 return strdup(
"bad size 2");
1833 if (focus_points_in_use > focus_points_in_struct) {
1834 ptp_error(params,
"focus_points_in_use %d is larger than focus_points_in_struct %d", focus_points_in_use, focus_points_in_struct);
1835 return strdup(
"bad size 3");
1838 maxlen = focus_points_in_use*32 + 100 + (size - focus_points_in_struct*8)*2;
1839 if (halfsize != size-4) {
1840 ptp_error(params,
"halfsize %d is not expected %d", halfsize, size-4);
1841 return strdup(
"bad size 4");
1843 if (20 + focus_points_in_struct*8 + (focus_points_in_struct+7)/8 > size) {
1844 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);
1845 return strdup(
"bad size 5");
1848 ptp_debug(params,
"d1d3 content:");
1849 for (i=0;i<size;i+=2)
1850 ptp_debug(params,
"%d: %02x %02x", i, (*data)[i], (*data)[i+1]);
1852 ptp_debug(params,
"d1d3 version %d", version);
1853 ptp_debug(params,
"d1d3 size %d", size);
1854 ptp_debug(params,
"d1d3 focus points in struct %d, in use %d", focus_points_in_struct, focus_points_in_use);
1856 str = (
char*)malloc( maxlen );
1861 p += sprintf(p,
"eosversion=%u,size=%ux%u,size2=%ux%u,points={", version, sizeX, sizeY, size2X, size2Y);
1862 for (i=0;i<focus_points_in_use;i++) {
1863 int16_t x = dtoh16a((*data) + focus_points_in_struct*4 + 20 + 2*i);
1864 int16_t y = dtoh16a((*data) + focus_points_in_struct*6 + 20 + 2*i);
1865 int16_t w = dtoh16a((*data) + focus_points_in_struct*2 + 20 + 2*i);
1866 int16_t h = dtoh16a((*data) + focus_points_in_struct*0 + 20 + 2*i);
1868 p += sprintf(p,
"{%d,%d,%d,%d}",x,y,w,h);
1870 if (i<focus_points_in_use-1)
1871 p += sprintf(p,
",");
1873 p += sprintf(p,
"},select={");
1874 for (i=0;i<focus_points_in_use;i++) {
1875 if ((1<<(i%8)) & ((*data)[focus_points_in_struct*8+20+i/8]))
1876 p+=sprintf(p,
"%u,", i);
1879 p += sprintf(p,
"},unknown={");
1880 for (i=focus_points_in_struct*8+(focus_points_in_struct+7)/8+20;i<size;i++) {
1881 if ((p-str) > maxlen - 4)
1883 p+=sprintf(p,
"%02x", (*data)[i]);
1885 p += sprintf(p,
"}");
1891ptp_unpack_EOS_CustomFuncEx (
PTPParams* params,
unsigned char** data )
1893 uint32_t s = dtoh32a( *data );
1894 uint32_t n = s/4, i;
1898 ptp_debug (params,
"customfuncex data is larger than 1k / %d... unexpected?", s);
1899 return strdup(
"bad length");
1901 str = (
char*)malloc( s*2+s/4+1 );
1903 return strdup(
"malloc failed");
1906 for (i=0; i < n; ++i)
1907 p += sprintf(p,
"%x,", dtoh32a( *data + 4*i ));
1911static inline uint32_t
1912ptp_pack_EOS_CustomFuncEx (
PTPParams* params,
unsigned char* data,
char* str)
1914 uint32_t s = strtoul(str, NULL, 16);
1915 uint32_t n = s/4, i, v;
1922 v = strtoul(str, &str, 16);
1924 htod32a(data + i*4, v);
1933#define PTP_ece_Size 0
1934#define PTP_ece_Type 4
1936#define PTP_ece_Prop_Subtype 8
1937#define PTP_ece_Prop_Val_Data 0xc
1938#define PTP_ece_Prop_Desc_Type 0xc
1939#define PTP_ece_Prop_Desc_Count 0x10
1940#define PTP_ece_Prop_Desc_Data 0x14
1943#define PTP_ece_OI_ObjectID 8
1944#define PTP_ece_OI_OFC 0x0c
1945#define PTP_ece_OI_Size 0x14
1946#define PTP_ece_OI_Name 0x1c
1949#define PTP_ece_OA_ObjectID 8
1950#define PTP_ece_OA_StorageID 0x0c
1951#define PTP_ece_OA_OFC 0x10
1952#define PTP_ece_OA_Size 0x1c
1953#define PTP_ece_OA_Parent 0x20
1954#define PTP_ece_OA_Name 0x28
1956#define PTP_ece2_OA_ObjectID 8
1957#define PTP_ece2_OA_StorageID 0x0c
1958#define PTP_ece2_OA_OFC 0x10
1959#define PTP_ece2_OA_Size 0x1c
1960#define PTP_ece2_OA_Parent 0x24
1961#define PTP_ece2_OA_2ndOID 0x28
1962#define PTP_ece2_OA_Name 0x2c
1965#define PTP_ece_OAN_OFC 0x0c
1966#define PTP_ece_OAN_Size 0x14
1969_lookup_or_allocate_canon_prop(
PTPParams *params, uint16_t proptype)
1973 for (j=0;j<params->nrofcanon_props;j++)
1974 if (params->canon_props[j].proptype == proptype)
1976 if (j<params->nrofcanon_props)
1977 return ¶ms->canon_props[j].dpd;
1980 params->canon_props = realloc(params->canon_props,
sizeof(params->canon_props[0])*(j+1));
1982 params->canon_props = malloc(
sizeof(params->canon_props[0]));
1983 params->canon_props[j].proptype = proptype;
1984 params->canon_props[j].size = 0;
1985 params->canon_props[j].data = NULL;
1986 memset (¶ms->canon_props[j].dpd,0,
sizeof(params->canon_props[j].dpd));
1987 params->canon_props[j].dpd.GetSet = 1;
1988 params->canon_props[j].dpd.FormFlag = PTP_DPFF_None;
1989 params->nrofcanon_props = j+1;
1990 return ¶ms->canon_props[j].dpd;
1997 int i = 0, entries = 0;
1998 unsigned char *curdata = data;
2003 while (curdata - data + 8 < datasize) {
2004 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
2005 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
2007 if (size > datasize) {
2008 ptp_debug (params,
"size %d is larger than datasize %d", size, datasize);
2012 ptp_debug (params,
"size %d is smaller than 8.", size);
2015 if ((size == 8) && (type == 0))
2017 if ((curdata - data) + size >= datasize) {
2018 ptp_debug (params,
"canon eos event decoder ran over supplied data, skipping entries");
2021 if (type == PTP_EC_CANON_EOS_OLCInfoChanged) {
2027 if (dtoh16a(curdata+12) & (1<<j))
2038 while (curdata - data + 8 < datasize) {
2039 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
2040 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
2042 if (size > datasize) {
2043 ptp_debug (params,
"size %d is larger than datasize %d", size, datasize);
2047 ptp_debug (params,
"size %d is smaller than 8", size);
2051 if ((size == 8) && (type == 0))
2054 if ((curdata - data) + size >= datasize) {
2055 ptp_debug (params,
"canon eos event decoder ran over supplied data, skipping entries");
2059 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2060 ce[i].u.info = NULL;
2062 case PTP_EC_CANON_EOS_ObjectContentChanged:
2063 if (size < PTP_ece_OA_ObjectID+1) {
2064 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OA_ObjectID+1);
2067 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTCONTENT_CHANGE;
2068 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OA_ObjectID]);
2070 case PTP_EC_CANON_EOS_ObjectInfoChangedEx:
2071 case PTP_EC_CANON_EOS_ObjectAddedEx:
2072 if (size < PTP_ece_OA_Name+1) {
2073 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OA_Name+1);
2076 ce[i].type = ((type == PTP_EC_CANON_EOS_ObjectAddedEx) ? PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO : PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO_CHANGE);
2077 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OA_ObjectID]);
2078 ce[i].u.object.oi.StorageID = dtoh32a(&curdata[PTP_ece_OA_StorageID]);
2079 ce[i].u.object.oi.ParentObject = dtoh32a(&curdata[PTP_ece_OA_Parent]);
2080 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece_OA_OFC]);
2081 ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata[PTP_ece_OA_Size]);
2082 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece_OA_Name]));
2083 if (type == PTP_EC_CANON_EOS_ObjectAddedEx) {
2084 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);
2086 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);
2089 case PTP_EC_CANON_EOS_ObjectAddedEx64:
2090 if (size < PTP_ece2_OA_Name+1) {
2091 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece2_OA_Name+1);
2094 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO;
2095 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece2_OA_ObjectID]);
2096 ce[i].u.object.oi.StorageID = dtoh32a(&curdata[PTP_ece2_OA_StorageID]);
2097 ce[i].u.object.oi.ParentObject = dtoh32a(&curdata[PTP_ece2_OA_Parent]);
2098 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece2_OA_OFC]);
2099 ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata[PTP_ece2_OA_Size]);
2100 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece2_OA_Name]));
2101 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);
2103 case PTP_EC_CANON_EOS_RequestObjectTransfer:
2104 case PTP_EC_CANON_EOS_RequestObjectTransfer64:
2105 if (size < PTP_ece_OI_Name+1) {
2106 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_OI_Name+1);
2109 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER;
2110 ce[i].u.object.oid = dtoh32a(&curdata[PTP_ece_OI_ObjectID]);
2111 ce[i].u.object.oi.StorageID = 0;
2112 ce[i].u.object.oi.ObjectFormat = dtoh16a(&curdata[PTP_ece_OI_OFC]);
2113 ce[i].u.object.oi.ParentObject = 0;
2114 ce[i].u.object.oi.ObjectCompressedSize = dtoh32a(&curdata[PTP_ece_OI_Size]);
2115 ce[i].u.object.oi.Filename = strdup(((
char*)&curdata[PTP_ece_OI_Name]));
2117 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);
2119 case PTP_EC_CANON_EOS_AvailListChanged: {
2120 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
2121 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Prop_Desc_Type]);
2122 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop_Desc_Count]);
2123 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data];
2127 if (size < PTP_ece_Prop_Desc_Data) {
2128 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_Prop_Desc_Data);
2132 ptp_debug (params,
"event %d: EOS prop %04x (%s) desc record, datasize %d, propxtype %d", i, proptype, ptp_get_property_description (params, proptype), size-PTP_ece_Prop_Desc_Data, propxtype);
2133 for (j=0;j<params->nrofcanon_props;j++)
2134 if (params->canon_props[j].proptype == proptype)
2136 if (j==params->nrofcanon_props) {
2137 ptp_debug (params,
"event %d: propdesc %x, default value not found.", i, proptype);
2140 dpd = ¶ms->canon_props[j].dpd;
2145 if (propxtype != 3) {
2146 ptp_debug (params,
"event %d: propxtype is %x for %04x, unhandled, size %d", i, propxtype, proptype, size);
2147 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++)
2148 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2153 if (propxcnt >= 2<<16)
2156 ptp_debug (params,
"event %d: propxtype is %x, prop is 0x%04x, data type is 0x%04x, propxcnt is %d.",
2157 i, propxtype, proptype, dpd->DataType, propxcnt);
2158 dpd->FormFlag = PTP_DPFF_Enumeration;
2159 dpd->FORM.Enum.NumberOfValues = propxcnt;
2160 free (dpd->FORM.Enum.SupportedValue);
2161 dpd->FORM.Enum.SupportedValue = malloc (
sizeof (
PTPPropertyValue)*propxcnt);
2164 case PTP_DPC_CANON_EOS_ImageFormat:
2165 case PTP_DPC_CANON_EOS_ImageFormatCF:
2166 case PTP_DPC_CANON_EOS_ImageFormatSD:
2167 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2169 for (j=0;j<propxcnt;j++) {
2170 dpd->FORM.Enum.SupportedValue[j].u16 =
2171 ptp_unpack_EOS_ImageFormat( params, &xdata );
2172 ptp_debug (params,
"event %d: suppval[%d] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16);
2177 switch (dpd->DataType) {
2178#define XX( TYPE, CONV )\
2179 if (sizeof(dpd->FORM.Enum.SupportedValue[j].TYPE)*propxcnt + PTP_ece_Prop_Desc_Data > size) { \
2180 ptp_debug (params, "size %lu does not match needed %u", sizeof(dpd->FORM.Enum.SupportedValue[j].TYPE)*propxcnt + PTP_ece_Prop_Desc_Data, size); \
2183 for (j=0;j<propxcnt;j++) { \
2184 dpd->FORM.Enum.SupportedValue[j].TYPE = CONV(xdata); \
2185 ptp_debug (params, "event %u: suppval[%u] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \
2190 case PTP_DTC_INT16: XX( i16, dtoh16a );
2191 case PTP_DTC_UINT16: XX( u16, dtoh16a );
2192 case PTP_DTC_UINT32: XX( u32, dtoh32a );
2193 case PTP_DTC_INT32: XX( i32, dtoh32a );
2194 case PTP_DTC_UINT8: XX( u8, dtoh8a );
2195 case PTP_DTC_INT8: XX( i8, dtoh8a );
2198 free (dpd->FORM.Enum.SupportedValue);
2199 dpd->FORM.Enum.SupportedValue = NULL;
2200 dpd->FORM.Enum.NumberOfValues = 0;
2201 ptp_debug (params ,
"event %d: data type 0x%04x of %x unhandled, size %d, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata), size);
2202 for (j=0;j<(size-PTP_ece_Prop_Desc_Data)/4;j++, xdata+=4)
2203 ptp_debug (params,
" %3d: 0x%8x", j, dtoh32a(xdata));
2209 case PTP_EC_CANON_EOS_PropValueChanged:
2212 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop_Subtype]);
2213 unsigned char *xdata = &curdata[PTP_ece_Prop_Val_Data];
2216 if (size < PTP_ece_Prop_Val_Data) {
2217 ptp_debug (params,
"size %d is smaller than %d", size, PTP_ece_Prop_Val_Data);
2220 ptp_debug (params,
"event %d: EOS prop %04x (%s) info record, datasize is %d", i, proptype, ptp_get_property_description(params,proptype), size-PTP_ece_Prop_Val_Data);
2221 for (j=0;j<params->nrofcanon_props;j++)
2222 if (params->canon_props[j].proptype == proptype)
2224 if (j<params->nrofcanon_props) {
2225 if ( (params->canon_props[j].size != size) ||
2226 (memcmp(params->canon_props[j].data,xdata,size-PTP_ece_Prop_Val_Data))) {
2227 params->canon_props[j].data = realloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data);
2228 params->canon_props[j].size = size;
2229 memcpy (params->canon_props[j].data,xdata,size-PTP_ece_Prop_Val_Data);
2233 params->canon_props = realloc(params->canon_props,
sizeof(params->canon_props[0])*(j+1));
2235 params->canon_props = malloc(
sizeof(params->canon_props[0]));
2236 params->canon_props[j].proptype = proptype;
2237 params->canon_props[j].size = size;
2238 params->canon_props[j].data = malloc(size-PTP_ece_Prop_Val_Data);
2239 memcpy(params->canon_props[j].data, xdata, size-PTP_ece_Prop_Val_Data);
2240 memset (¶ms->canon_props[j].dpd,0,
sizeof(params->canon_props[j].dpd));
2241 params->canon_props[j].dpd.GetSet = 1;
2242 params->canon_props[j].dpd.FormFlag = PTP_DPFF_None;
2243 params->nrofcanon_props = j+1;
2245 dpd = ¶ms->canon_props[j].dpd;
2247 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2248 ce[i].u.propid = proptype;
2252#define XX(x) case PTP_DPC_CANON_##x:
2254 XX(EOS_BatteryPower)
2255 XX(EOS_BatterySelect)
2257 XX(EOS_PTPExtensionVersion)
2259 XX(EOS_AvailableShots)
2260 XX(EOS_CurrentStorage)
2261 XX(EOS_CurrentFolder)
2264 XX(EOS_HDDirectoryStructure)
2268 XX(EOS_CardExtension)
2270 XX(EOS_ShutterCounter)
2271 XX(EOS_SerialNumber)
2272 XX(EOS_DepthOfFieldPreview)
2273 XX(EOS_EVFRecordStatus)
2276 XX(EOS_DepthOfField)
2283 dpd->GetSet = PTP_DPGS_Get;
2289 case PTP_DPC_CANON_EOS_CameraTime:
2290 case PTP_DPC_CANON_EOS_UTCTime:
2291 case PTP_DPC_CANON_EOS_Summertime:
2292 case PTP_DPC_CANON_EOS_AvailableShots:
2293 case PTP_DPC_CANON_EOS_CaptureDestination:
2294 case PTP_DPC_CANON_EOS_WhiteBalanceXA:
2295 case PTP_DPC_CANON_EOS_WhiteBalanceXB:
2296 case PTP_DPC_CANON_EOS_CurrentStorage:
2297 case PTP_DPC_CANON_EOS_CurrentFolder:
2298 case PTP_DPC_CANON_EOS_ShutterCounter:
2299 case PTP_DPC_CANON_EOS_ModelID:
2300 case PTP_DPC_CANON_EOS_LensID:
2301 case PTP_DPC_CANON_EOS_StroboFiring:
2302 case PTP_DPC_CANON_EOS_AFSelectFocusArea:
2303 case PTP_DPC_CANON_EOS_ContinousAFMode:
2304 case PTP_DPC_CANON_EOS_MirrorUpSetting:
2305 case PTP_DPC_CANON_EOS_OLCInfoVersion:
2306 case PTP_DPC_CANON_EOS_PowerZoomPosition:
2307 case PTP_DPC_CANON_EOS_PowerZoomSpeed:
2308 case PTP_DPC_CANON_EOS_BuiltinStroboMode:
2309 case PTP_DPC_CANON_EOS_StroboETTL2Metering:
2310 case PTP_DPC_CANON_EOS_ColorTemperature:
2311 case PTP_DPC_CANON_EOS_FixedMovie:
2312 dpd->DataType = PTP_DTC_UINT32;
2315 case PTP_DPC_CANON_EOS_AutoExposureMode:
2316 dpd->DataType = PTP_DTC_UINT16;
2317 dpd->FormFlag = PTP_DPFF_Enumeration;
2318 dpd->FORM.Enum.NumberOfValues = 0;
2320 case PTP_DPC_CANON_EOS_Aperture:
2321 case PTP_DPC_CANON_EOS_ShutterSpeed:
2322 case PTP_DPC_CANON_EOS_ISOSpeed:
2323 case PTP_DPC_CANON_EOS_FocusMode:
2324 case PTP_DPC_CANON_EOS_ColorSpace:
2325 case PTP_DPC_CANON_EOS_BatteryPower:
2326 case PTP_DPC_CANON_EOS_BatterySelect:
2327 case PTP_DPC_CANON_EOS_PTPExtensionVersion:
2328 case PTP_DPC_CANON_EOS_DriveMode:
2329 case PTP_DPC_CANON_EOS_AEB:
2330 case PTP_DPC_CANON_EOS_BracketMode:
2331 case PTP_DPC_CANON_EOS_QuickReviewTime:
2332 case PTP_DPC_CANON_EOS_EVFMode:
2333 case PTP_DPC_CANON_EOS_EVFOutputDevice:
2334 case PTP_DPC_CANON_EOS_AutoPowerOff:
2335 case PTP_DPC_CANON_EOS_EVFRecordStatus:
2336 case PTP_DPC_CANON_EOS_HighISOSettingNoiseReduction:
2337 case PTP_DPC_CANON_EOS_MultiAspect:
2338 dpd->DataType = PTP_DTC_UINT16;
2340 case PTP_DPC_CANON_EOS_PictureStyle:
2341 case PTP_DPC_CANON_EOS_WhiteBalance:
2342 case PTP_DPC_CANON_EOS_MeteringMode:
2343 case PTP_DPC_CANON_EOS_ExpCompensation:
2344 dpd->DataType = PTP_DTC_UINT8;
2346 case PTP_DPC_CANON_EOS_Owner:
2347 case PTP_DPC_CANON_EOS_Artist:
2348 case PTP_DPC_CANON_EOS_Copyright:
2349 case PTP_DPC_CANON_EOS_SerialNumber:
2350 case PTP_DPC_CANON_EOS_LensName:
2351 dpd->DataType = PTP_DTC_STR;
2353 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA:
2354 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB:
2355 dpd->DataType = PTP_DTC_INT32;
2358 case PTP_DPC_CANON_EOS_DPOFVersion:
2359 dpd->DataType = PTP_DTC_UINT16;
2360 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint16", i ,proptype, size-PTP_ece_Prop_Val_Data);
2361 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2362 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2364 case PTP_DPC_CANON_EOS_CustomFunc1:
2365 case PTP_DPC_CANON_EOS_CustomFunc2:
2366 case PTP_DPC_CANON_EOS_CustomFunc3:
2367 case PTP_DPC_CANON_EOS_CustomFunc4:
2368 case PTP_DPC_CANON_EOS_CustomFunc5:
2369 case PTP_DPC_CANON_EOS_CustomFunc6:
2370 case PTP_DPC_CANON_EOS_CustomFunc7:
2371 case PTP_DPC_CANON_EOS_CustomFunc8:
2372 case PTP_DPC_CANON_EOS_CustomFunc9:
2373 case PTP_DPC_CANON_EOS_CustomFunc10:
2374 case PTP_DPC_CANON_EOS_CustomFunc11:
2375 dpd->DataType = PTP_DTC_UINT8;
2376 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint8", i ,proptype, size-PTP_ece_Prop_Val_Data);
2377 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2378 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2383 case PTP_DPC_CANON_EOS_WftStatus:
2384 case PTP_DPC_CANON_EOS_LensStatus:
2385 case PTP_DPC_CANON_EOS_CardExtension:
2386 case PTP_DPC_CANON_EOS_TempStatus:
2387 case PTP_DPC_CANON_EOS_PhotoStudioMode:
2388 case PTP_DPC_CANON_EOS_DepthOfFieldPreview:
2389 case PTP_DPC_CANON_EOS_EVFSharpness:
2390 case PTP_DPC_CANON_EOS_EVFWBMode:
2391 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs:
2392 case PTP_DPC_CANON_EOS_EVFColorTemp:
2393 case PTP_DPC_CANON_EOS_ExposureSimMode:
2394 case PTP_DPC_CANON_EOS_LvAfSystem:
2395 case PTP_DPC_CANON_EOS_MovSize:
2396 case PTP_DPC_CANON_EOS_DepthOfField:
2397 case PTP_DPC_CANON_EOS_LvViewTypeSelect:
2398 case PTP_DPC_CANON_EOS_AloMode:
2399 case PTP_DPC_CANON_EOS_Brightness:
2400 case PTP_DPC_CANON_EOS_GPSLogCtrl:
2401 case PTP_DPC_CANON_EOS_GPSDeviceActive:
2402 dpd->DataType = PTP_DTC_UINT32;
2403 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_Val_Data);
2404 if ((size-PTP_ece_Prop_Val_Data) %
sizeof(uint32_t) != 0)
2405 ptp_debug (params,
"event %d: Warning: datasize modulo sizeof(uint32) is not 0: ", i, (size-PTP_ece_Prop_Val_Data) %
sizeof(uint32_t) );
2406 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/
sizeof(uint32_t);j++)
2407 ptp_debug (params,
" %d: 0x%8x", j, dtoh32a(xdata+j*4));
2410 case PTP_DPC_CANON_EOS_ImageFormat:
2411 case PTP_DPC_CANON_EOS_ImageFormatCF:
2412 case PTP_DPC_CANON_EOS_ImageFormatSD:
2413 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2414 case PTP_DPC_CANON_EOS_CustomFuncEx:
2415 case PTP_DPC_CANON_EOS_FocusInfoEx:
2418 ptp_debug (params,
"event %d: Unknown EOS property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data);
2419 for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
2420 ptp_debug (params,
" %d: %02x", j, xdata[j]);
2423 switch (dpd->DataType) {
2424 case PTP_DTC_UINT32:
2425 dpd->FactoryDefaultValue.u32 = dtoh32a(xdata);
2426 dpd->CurrentValue.u32 = dtoh32a(xdata);
2427 ptp_debug (params ,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u32);
2430 dpd->FactoryDefaultValue.i16 = dtoh16a(xdata);
2431 dpd->CurrentValue.i16 = dtoh16a(xdata);
2432 ptp_debug (params,
"event %d: currentvalue of %x is %d", i, proptype, dpd->CurrentValue.i16);
2434 case PTP_DTC_UINT16:
2435 dpd->FactoryDefaultValue.u16 = dtoh16a(xdata);
2436 dpd->CurrentValue.u16 = dtoh16a(xdata);
2437 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
2440 dpd->FactoryDefaultValue.u8 = dtoh8a(xdata);
2441 dpd->CurrentValue.u8 = dtoh8a(xdata);
2442 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u8);
2445 dpd->FactoryDefaultValue.i8 = dtoh8a(xdata);
2446 dpd->CurrentValue.i8 = dtoh8a(xdata);
2447 ptp_debug (params,
"event %d: currentvalue of %x is %x", i, proptype, dpd->CurrentValue.i8);
2452 dpd->FactoryDefaultValue.str = ptp_unpack_string(params, data, 0, &len);
2453 dpd->CurrentValue.str = ptp_unpack_string(params, data, 0, &len);
2455 free (dpd->FactoryDefaultValue.str);
2456 dpd->FactoryDefaultValue.str = strdup( (
char*)xdata );
2458 free (dpd->CurrentValue.str);
2459 dpd->CurrentValue.str = strdup( (
char*)xdata );
2461 ptp_debug (params,
"event %d: currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2471 case PTP_DPC_CANON_EOS_ImageFormat:
2472 case PTP_DPC_CANON_EOS_ImageFormatCF:
2473 case PTP_DPC_CANON_EOS_ImageFormatSD:
2474 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2475 dpd->DataType = PTP_DTC_UINT16;
2476 dpd->FactoryDefaultValue.u16 = ptp_unpack_EOS_ImageFormat( params, &xdata );
2477 dpd->CurrentValue.u16 = dpd->FactoryDefaultValue.u16;
2478 ptp_debug (params,
"event %d: decoded imageformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
2480 case PTP_DPC_CANON_EOS_CustomFuncEx:
2481 dpd->DataType = PTP_DTC_STR;
2482 free (dpd->FactoryDefaultValue.str);
2483 free (dpd->CurrentValue.str);
2484 dpd->FactoryDefaultValue.str = ptp_unpack_EOS_CustomFuncEx( params, &xdata );
2485 dpd->CurrentValue.str = strdup( (
char*)dpd->FactoryDefaultValue.str );
2486 ptp_debug (params,
"event %d: decoded custom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2488 case PTP_DPC_CANON_EOS_FocusInfoEx:
2489 dpd->DataType = PTP_DTC_STR;
2490 free (dpd->FactoryDefaultValue.str);
2491 free (dpd->CurrentValue.str);
2492 dpd->FactoryDefaultValue.str = ptp_unpack_EOS_FocusInfoEx( params, &xdata, size );
2493 dpd->CurrentValue.str = strdup( (
char*)dpd->FactoryDefaultValue.str );
2494 ptp_debug (params,
"event %d: decoded focus info, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2511 case PTP_EC_CANON_EOS_OLCInfoChanged: {
2512 uint32_t len, curoff;
2513 uint16_t mask,proptype;
2517 dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_OLCInfoVersion);
2519 ptp_debug (params,
"olcinfoversion is %d", dpd->CurrentValue.u32);
2520 olcver = dpd->CurrentValue.u32;
2524 ptp_debug (params,
"event %d: EOS event OLCInfoChanged (size %d)", i, size);
2527 for (k=8;k<size;k++)
2528 ptp_debug (params,
" %d: %02x", k-8, curdata[k]);
2530 len = dtoh32a(curdata+8);
2531 if ((len != size-8) && (len != size-4)) {
2532 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2533 ce[i].u.info = strdup(
"OLC size unexpected");
2534 ptp_debug (params,
"event %d: OLC unexpected size %d for blob len %d (not -4 nor -8)", i, size, len);
2537 mask = dtoh16a(curdata+8+4);
2539 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2540 ce[i].u.info = strdup(
"OLC size too small");
2541 ptp_debug (params,
"event %d: OLC unexpected size %d", i, size);
2545 if (mask & CANON_EOS_OLC_BUTTON) {
2546 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2547 ce[i].u.info = malloc(strlen(
"Button 1234567"));
2548 sprintf(ce[i].u.info,
"Button %d", dtoh16a(curdata+curoff));
2553 if (mask & CANON_EOS_OLC_SHUTTERSPEED) {
2561 proptype = PTP_DPC_CANON_EOS_ShutterSpeed;
2562 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2563 dpd->CurrentValue.u16 = curdata[curoff+5];
2565 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2566 ce[i].u.propid = proptype;
2587 if (mask & CANON_EOS_OLC_APERTURE) {
2593 proptype = PTP_DPC_CANON_EOS_Aperture;
2594 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2595 dpd->CurrentValue.u16 = curdata[curoff+4];
2597 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2598 ce[i].u.propid = proptype;
2599 if (olcver >= 0xf) {
2606 if (mask & CANON_EOS_OLC_ISO) {
2609 proptype = PTP_DPC_CANON_EOS_ISOSpeed;
2610 dpd = _lookup_or_allocate_canon_prop(params, proptype);
2611 dpd->CurrentValue.u16 = curdata[curoff+3];
2613 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
2614 ce[i].u.propid = proptype;
2618 if (mask & 0x0010) {
2620 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2621 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0010 content 01234567")+1);
2622 sprintf(ce[i].u.info,
"OLCInfo event 0x0010 content %02x%02x%02x%02x",
2631 if (mask & 0x0020) {
2636 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2637 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0020 content 0123456789ab")+1);
2638 sprintf(ce[i].u.info,
"OLCInfo event 0x0020 content %02x%02x%02x%02x%02x%02x",
2649 if (mask & 0x0040) {
2650 int value = (
signed char)curdata[curoff+2];
2653 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2654 ce[i].u.info = malloc(strlen(
"OLCInfo exposure indicator 012345678901234567890123456789abcd")+1);
2655 sprintf(ce[i].u.info,
"OLCInfo exposure indicator %d,%d,%d.%d (%02x%02x%02x%02x)",
2658 value/10,abs(value)%10,
2667 if (mask & 0x0080) {
2669 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2670 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0080 content 01234567")+1);
2671 sprintf(ce[i].u.info,
"OLCInfo event 0x0080 content %02x%02x%02x%02x",
2680 if (mask & 0x0100) {
2682 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSINFO;
2683 ce[i].u.info = malloc(strlen(
"0123456789ab")+1);
2684 sprintf(ce[i].u.info,
"%02x%02x%02x%02x%02x%02x",
2695 if (mask & 0x0200) {
2697 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSMASK;
2698 ce[i].u.info = malloc(strlen(
"0123456789abcd0123456789abcdef")+1);
2699 sprintf(ce[i].u.info,
"%02x%02x%02x%02x%02x%02x%02x",
2711 if (mask & 0x0400) {
2713 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2714 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0400 content 0123456789abcd")+1);
2715 sprintf(ce[i].u.info,
"OLCInfo event 0x0400 content %02x%02x%02x%02x%02x%02x%02x",
2727 if (mask & 0x0800) {
2730 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2731 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x0800 content 0123456789abcdef")+1);
2732 sprintf(ce[i].u.info,
"OLCInfo event 0x0800 content %02x%02x%02x%02x%02x%02x%02x%02x",
2745 if (mask & 0x1000) {
2747 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2748 ce[i].u.info = malloc(strlen(
"OLCInfo event 0x1000 content 01")+1);
2749 sprintf(ce[i].u.info,
"OLCInfo event 0x1000 content %02x",
2756 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2757 ce[i].u.info = malloc(strlen(
"OLCInfo event mask 0123456789")+1);
2758 sprintf(ce[i].u.info,
"OLCInfo event mask=%x", mask);
2761 case PTP_EC_CANON_EOS_CameraStatusChanged:
2762 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS;
2763 ce[i].u.status = dtoh32a(curdata+8);
2764 ptp_debug (params,
"event %d: EOS event CameraStatusChanged (size %d) = %d", i, size, dtoh32a(curdata+8));
2765 params->eos_camerastatus = dtoh32a(curdata+8);
2770 ptp_debug (params,
"event %d: EOS event 0, but size %d", i, size);
2772 case PTP_EC_CANON_EOS_BulbExposureTime:
2773 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2774 ce[i].u.info = malloc(strlen(
"BulbExposureTime 123456789012345678"));
2775 sprintf (ce[i].u.info,
"BulbExposureTime %u", dtoh32a(curdata+8));
2777 case PTP_EC_CANON_EOS_ObjectRemoved:
2778 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTREMOVED;
2779 ce[i].u.object.oid = dtoh32a(curdata+8);
2783#define XX(x) case PTP_EC_CANON_EOS_##x: \
2784 ptp_debug (params, "event %u: unhandled EOS event "#x" (size %u)", i, size); \
2785 ce[i].u.info = malloc(strlen("unhandled EOS event "#x" (size 12345678901)")+1); \
2786 sprintf (ce[i].u.info, "unhandled EOS event "#x" (size %u)", size); \
2789 XX(RequestGetObjectInfoEx)
2790 XX(StorageStatusChanged)
2791 XX(StorageInfoChanged)
2792 XX(ObjectInfoChangedEx)
2793 XX(ObjectContentChanged)
2794 XX(WillSoonShutdown)
2795 XX(ShutdownTimerUpdated)
2796 XX(RequestCancelTransfer)
2797 XX(RequestObjectTransferDT)
2798 XX(RequestCancelTransferDT)
2801 XX(BulbExposureTime)
2803 XX(RequestObjectTransferTS)
2805 XX(PowerZoomInfoChanged)
2806 XX(CTGInfoCheckComplete)
2809 ptp_debug (params,
"event %d: unknown EOS event %04x", i, type);
2815 for (j=8;j<size;j++)
2816 ptp_debug (params,
" %d: %02x", j, curdata[j]);
2818 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2824 ptp_debug (params,
"BAD: i %d, entries %d", i, entries);
2838#define PTP_nikon_ec_Length 0
2839#define PTP_nikon_ec_Code 2
2840#define PTP_nikon_ec_Param1 4
2841#define PTP_nikon_ec_Size 6
2843ptp_unpack_Nikon_EC (
PTPParams *params,
unsigned char* data,
unsigned int len,
PTPContainer **ec,
unsigned int *cnt)
2850 if (len < PTP_nikon_ec_Code)
2852 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]);
2853 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) {
2862 for (i=0;i<*cnt;i++) {
2864 (*ec)[i].Code = dtoh16a(&data[PTP_nikon_ec_Code+PTP_nikon_ec_Size*i]);
2865 (*ec)[i].Param1 = dtoh32a(&data[PTP_nikon_ec_Param1+PTP_nikon_ec_Size*i]);
2866 (*ec)[i].Nparam = 1;
2873#define PTP_nikon_ec_ex_Length 0
2874#define PTP_nikon_ec_ex_Code 2
2877ptp_unpack_Nikon_EC_EX (
PTPParams *params,
unsigned char* data,
unsigned int len,
PTPContainer **ec,
unsigned int *cnt)
2879 unsigned int i, offset;
2884 if (len < PTP_nikon_ec_ex_Code)
2886 *cnt = dtoh16a(&data[PTP_nikon_ec_ex_Length]);
2887 if (*cnt > (len-PTP_nikon_ec_ex_Code)/4) {
2895 offset = PTP_nikon_ec_ex_Code+
sizeof(uint16_t);
2897 for (i=0;i<*cnt;i++) {
2899 if (len - offset < 4) {
2905 (*ec)[i].Code = dtoh16a(&data[offset]);
2906 (*ec)[i].Nparam = dtoh16a(&data[offset+2]);
2907 ptp_debug (params,
"nikon eventex %d: code 0x%04x, params %d", i, (*ec)[i].Code, (*ec)[i].Nparam);
2908 if ( ((*ec)[i].Nparam > 5) ||
2909 (len < ((*ec)[i].Nparam*
sizeof(uint32_t)) + 4 + offset)
2916 switch ((*ec)[i].Nparam) {
2917 case 5: (*ec)[i].Param5 = dtoh32a(&data[offset+4+
sizeof(uint32_t)*4]);
2918 case 4: (*ec)[i].Param4 = dtoh32a(&data[offset+4+
sizeof(uint32_t)*3]);
2919 case 3: (*ec)[i].Param3 = dtoh32a(&data[offset+4+
sizeof(uint32_t)*2]);
2920 case 2: (*ec)[i].Param2 = dtoh32a(&data[offset+4+
sizeof(uint32_t)*1]);
2921 case 1: (*ec)[i].Param1 = dtoh32a(&data[offset+4]);
2925 offset += (*ec)[i].Nparam*
sizeof(uint32_t) + 4;
2930static inline uint32_t
2934 unsigned char *curdata;
2936 len = 2*(strlen(text->title)+1)+1+
2937 2*(strlen(text->line[0])+1)+1+
2938 2*(strlen(text->line[1])+1)+1+
2939 2*(strlen(text->line[2])+1)+1+
2940 2*(strlen(text->line[3])+1)+1+
2941 2*(strlen(text->line[4])+1)+1+
2942 4*2+2*4+2+4+2+5*4*2;
2943 *data = malloc(len);
2944 if (!*data)
return 0;
2947 htod16a(curdata,100);curdata+=2;
2948 htod16a(curdata,1);curdata+=2;
2949 htod16a(curdata,0);curdata+=2;
2950 htod16a(curdata,1000);curdata+=2;
2952 htod32a(curdata,0);curdata+=4;
2953 htod32a(curdata,0);curdata+=4;
2955 htod16a(curdata,6);curdata+=2;
2956 htod32a(curdata,0);curdata+=4;
2958 ptp_pack_string(params, text->title, curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
2959 htod16a(curdata,0x10);curdata+=2;
2962 ptp_pack_string(params, text->line[i], curdata, 0, &retlen); curdata+=2*retlen+1;htod16a(curdata,0);curdata+=2;
2963 htod16a(curdata,0x10);curdata+=2;
2964 htod16a(curdata,0x01);curdata+=2;
2965 htod16a(curdata,0x02);curdata+=2;
2966 htod16a(curdata,0x06);curdata+=2;
2971#define ptp_canon_dir_version 0x00
2972#define ptp_canon_dir_ofc 0x02
2973#define ptp_canon_dir_unk1 0x04
2974#define ptp_canon_dir_objectid 0x08
2975#define ptp_canon_dir_parentid 0x0c
2976#define ptp_canon_dir_previd 0x10
2977#define ptp_canon_dir_nextid 0x14
2978#define ptp_canon_dir_nextchild 0x18
2979#define ptp_canon_dir_storageid 0x1c
2980#define ptp_canon_dir_name 0x20
2981#define ptp_canon_dir_flags 0x2c
2982#define ptp_canon_dir_size 0x30
2983#define ptp_canon_dir_unixtime 0x34
2984#define ptp_canon_dir_year 0x38
2985#define ptp_canon_dir_month 0x39
2986#define ptp_canon_dir_mday 0x3a
2987#define ptp_canon_dir_hour 0x3b
2988#define ptp_canon_dir_minute 0x3c
2989#define ptp_canon_dir_second 0x3d
2990#define ptp_canon_dir_unk2 0x3e
2991#define ptp_canon_dir_thumbsize 0x40
2992#define ptp_canon_dir_width 0x44
2993#define ptp_canon_dir_height 0x48
2995static inline uint16_t
2996ptp_unpack_canon_directory (
3004 unsigned int i, j, nrofobs = 0, curob = 0;
3006#define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff)
3008 if (ISOBJECT(dir+i*0x4c)) nrofobs++;
3009 handles->n = nrofobs;
3010 handles->Handler = calloc(nrofobs,
sizeof(handles->Handler[0]));
3011 if (!handles->Handler)
return PTP_RC_GeneralError;
3012 *oinfos = calloc(nrofobs,
sizeof((*oinfos)[0]));
3013 if (!*oinfos)
return PTP_RC_GeneralError;
3014 *flags = calloc(nrofobs,
sizeof((*flags)[0]));
3015 if (!*flags)
return PTP_RC_GeneralError;
3021 for (i=0;i<cnt;i++) {
3022 unsigned char *cur = dir+i*0x4c;
3028 handles->Handler[curob] = dtoh32a(cur + ptp_canon_dir_objectid);
3029 oi->StorageID = 0xffffffff;
3030 oi->ObjectFormat = dtoh16a(cur + ptp_canon_dir_ofc);
3031 oi->ParentObject = dtoh32a(cur + ptp_canon_dir_parentid);
3032 oi->Filename = strdup((
char*)(cur + ptp_canon_dir_name));
3033 oi->ObjectCompressedSize= dtoh32a(cur + ptp_canon_dir_size);
3034 oi->ThumbCompressedSize = dtoh32a(cur + ptp_canon_dir_thumbsize);
3035 oi->ImagePixWidth = dtoh32a(cur + ptp_canon_dir_width);
3036 oi->ImagePixHeight = dtoh32a(cur + ptp_canon_dir_height);
3037 oi->CaptureDate = oi->ModificationDate = dtoh32a(cur + ptp_canon_dir_unixtime);
3038 (*flags)[curob] = dtoh32a(cur + ptp_canon_dir_flags);
3043 for (i=0;i<cnt;i++) {
3044 unsigned char *cur = dir+i*0x4c;
3045 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
3049 for (j=0;j<handles->n;j++)
if (nextchild == handles->Handler[j])
break;
3050 if (j == handles->n)
continue;
3051 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid);
3055 unsigned int changed = 0;
3056 for (i=0;i<cnt;i++) {
3057 unsigned char *cur = dir+i*0x4c;
3058 uint32_t oid = dtoh32a(cur + ptp_canon_dir_objectid);
3059 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_nextid);
3060 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchild);
3065 for (j=0;j<handles->n;j++)
if (oid == handles->Handler[j])
break;
3066 if (j == handles->n) {
3070 storageid = (*oinfos)[j].StorageID;
3071 if (storageid == 0xffffffff)
continue;
3072 if (nextoid != 0xffffffff) {
3073 for (j=0;j<handles->n;j++)
if (nextoid == handles->Handler[j])
break;
3074 if (j == handles->n) {
3078 if ((*oinfos)[j].StorageID == 0xffffffff) {
3079 (*oinfos)[j].StorageID = storageid;
3083 if (nextchild != 0xffffffff) {
3084 for (j=0;j<handles->n;j++)
if (nextchild == handles->Handler[j])
break;
3085 if (j == handles->n) {
3089 if ((*oinfos)[j].StorageID == 0xffffffff) {
3090 (*oinfos)[j].StorageID = storageid;
3100 if (!changed || (changed==nrofobs-1))
3108ptp_unpack_ptp11_manifest (
3110 unsigned char *data,
3111 unsigned int datalen,
3115 uint64_t numberoifs, i;
3116 unsigned int curoffset;
3121 numberoifs = dtoh64ap(params,data);
3127 for (i = 0; i < numberoifs; i++) {
3132 if (curoffset + 34 + 2 > datalen)
3135 oif->ObjectHandle = dtoh32ap(params,data+curoffset);
3136 oif->StorageID = dtoh32ap(params,data+curoffset+4);
3137 oif->ObjectFormat = dtoh16ap(params,data+curoffset+8);
3138 oif->ProtectionStatus = dtoh16ap(params,data+curoffset+10);
3139 oif->ObjectCompressedSize64 = dtoh64ap(params,data+curoffset+12);
3140 oif->ParentObject = dtoh32ap(params,data+curoffset+20);
3141 oif->AssociationType = dtoh16ap(params,data+curoffset+24);
3142 oif->AssociationDesc = dtoh32ap(params,data+curoffset+26);
3143 oif->SequenceNumber = dtoh32ap(params,data+curoffset+30);
3144 if (!ptp_unpack_string(params, data, curoffset+34, datalen, &len, &oif->Filename))
3146 if (curoffset+34+len*2+1 > datalen)
3149 if (!ptp_unpack_string(params, data, curoffset+len*2+1+34, datalen, &dlen, &modify_date))
3152 oif->ModificationDate = ptp_unpack_PTPTIME(modify_date);
3154 curoffset += 34+len*2+dlen*2+2;
3156 *numoifs = numberoifs;
3160 for (i = 0; i < numberoifs; i++)
3161 if (xoifs[i].Filename) free (xoifs[i].Filename);
3172 header->version_major = dtoh32a(&data[off]);
3173 header->version_minor = dtoh32a(&data[off+=4]);
3174 header->lcd_aspect_ratio = dtoh32a(&data[off+=4]);
3175 header->palette_type = dtoh32a(&data[off+=4]);
3176 header->palette_data_start = dtoh32a(&data[off+=4]);
3177 header->vp_desc_start = dtoh32a(&data[off+=4]);
3178 header->bm_desc_start = dtoh32a(&data[off+=4]);
3179 if (header->version_minor > 1)
3180 header->bmo_desc_start = dtoh32a(&data[off+=4]);
3189 fd->fb_type = dtoh32a(&data[off]);
3190 fd->data_start = dtoh32a(&data[off+=4]);
3191 fd->buffer_width = dtoh32a(&data[off+=4]);
3192 fd->visible_width = dtoh32a(&data[off+=4]);
3193 fd->visible_height = dtoh32a(&data[off+=4]);
3194 fd->margin_left = dtoh32a(&data[off+=4]);
3195 fd->margin_top = dtoh32a(&data[off+=4]);
3196 fd->margin_right = dtoh32a(&data[off+=4]);
3197 fd->margin_bot = dtoh32a(&data[off+=4]);
3202 if (!data)
return PTP_RC_GeneralError;
3203 if (size < 36)
return PTP_RC_GeneralError;
3205 si->DatasetSize = dtoh64ap(params,data+0);
3206 si->TimeResolution = dtoh64ap(params,data+8);
3207 si->FrameHeaderSize = dtoh32ap(params,data+16);
3208 si->FrameMaxSize = dtoh32ap(params,data+20);
3209 si->PacketHeaderSize = dtoh32ap(params,data+24);
3210 si->PacketMaxSize = dtoh32ap(params,data+28);
3211 si->PacketAlignment = dtoh32ap(params,data+32);
Definition chdk_live_view.h:65