Skip to content

Commit

Permalink
try a workaround for newer Sonys that have two enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
msmeissn committed Apr 4, 2024
1 parent 7a7f671 commit 4ab7802
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions camlibs/ptp2/ptp-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd,
#define PTP_dpd_Sony_ChangeMethod 4
#define PTP_dpd_Sony_GetSet 5
#define PTP_dpd_Sony_FactoryDefaultValue 6
/* PTP_dpd_SonyCurrentValue 6 + sizeof(DataType) */

static inline int
ptp_unpack_Sony_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd, unsigned int dpdlen, unsigned int *poffset)
Expand Down Expand Up @@ -1060,6 +1061,7 @@ ptp_unpack_Sony_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *
return 1;

dpd->FormFlag=dtoh8a(&data[*poffset]);
ptp_debug (params, "formflag 0x%04x", dpd->FormFlag);
*poffset+=sizeof(uint8_t);

switch (dpd->FormFlag) {
Expand Down Expand Up @@ -1097,6 +1099,40 @@ ptp_unpack_Sony_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *
}
}
}
if (dpdlen >= *poffset + 2) {
uint16_t val = dtoh16a(&data[*poffset]);

/* check if we have a secondary list of items, this is for newer Sonys (2024) */
if (val < 0x200) { /* actually would be 0x5XXX or 0xDxxx */
if (dpd->FormFlag == PTP_DPFF_Enumeration) {
int i;

N = dtoh16a(&data[*poffset]);
*poffset+=sizeof(uint16_t);
dpd->FORM.Enum.SupportedValue = calloc(N,sizeof(dpd->FORM.Enum.SupportedValue[0]));
if (!dpd->FORM.Enum.SupportedValue)
goto outofmemory;

for (i=0;i<N;i++) {
ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.Enum.SupportedValue[i], dpd->DataType);

/* Slightly different handling here. The HP PhotoSmart 120
* specifies an enumeration with N in wrong endian
* 00 01 instead of 01 00, so we count the enum just until the
* the end of the packet.
*/
if (!ret) {
if (!i)
goto outofmemory;
dpd->FORM.Enum.NumberOfValues = i;
break;
}
}
} else {
ptp_debug (params, "apparently not a enum, but also no value (formflags is %d, value is 0x%04x)", dpd->FormFlag, val);
}
}
}
#undef N
return 1;
outofmemory:
Expand Down

0 comments on commit 4ab7802

Please sign in to comment.