OLD | NEW |
1 /* ptp-pack.c | 1 /* ptp-pack.c |
2 * | 2 * |
3 * Copyright (C) 2001-2004 Mariusz Woloszyn <emsi@ipartners.pl> | 3 * Copyright (C) 2001-2004 Mariusz Woloszyn <emsi@ipartners.pl> |
4 * Copyright (C) 2003-2012 Marcus Meissner <marcus@jet.franken.de> | 4 * Copyright (C) 2003-2014 Marcus Meissner <marcus@jet.franken.de> |
5 * Copyright (C) 2006-2008 Linus Walleij <triad@df.lth.se> | 5 * Copyright (C) 2006-2008 Linus Walleij <triad@df.lth.se> |
6 * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com> | 6 * Copyright (C) 2007 Tero Saarni <tero.saarni@gmail.com> |
7 * Copyright (C) 2009 Axel Waggershauser <awagger@web.de> | 7 * Copyright (C) 2009 Axel Waggershauser <awagger@web.de> |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Lesser General Public | 10 * modify it under the terms of the GNU Lesser General Public |
11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
13 * | 13 * |
14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Lesser General Public License for more details. | 17 * Lesser General Public License for more details. |
18 * | 18 * |
19 * You should have received a copy of the GNU Lesser General Public | 19 * You should have received a copy of the GNU Lesser General Public |
20 * License along with this library; if not, write to the | 20 * License along with this library; if not, write to the |
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 * Boston, MA 02111-1307, USA. | 22 * Boston, MA 02110-1301 USA |
23 */ | 23 */ |
24 | 24 |
25 /* currently this file is included into ptp.c */ | 25 /* currently this file is included into ptp.c */ |
26 | 26 |
27 #ifdef HAVE_ICONV | 27 #ifdef HAVE_LIMITS_H |
| 28 #include <limits.h> |
| 29 #endif |
| 30 #ifndef UINT_MAX |
| 31 # define UINT_MAX 0xFFFFFFFF |
| 32 #endif |
| 33 #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H) |
28 #include <iconv.h> | 34 #include <iconv.h> |
29 #endif | 35 #endif |
30 | 36 |
31 static inline uint16_t | 37 static inline uint16_t |
32 htod16p (PTPParams *params, uint16_t var) | 38 htod16p (PTPParams *params, uint16_t var) |
33 { | 39 { |
34 return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var)); | 40 return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var)); |
35 } | 41 } |
36 | 42 |
37 static inline uint32_t | 43 static inline uint32_t |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 memcpy(string, &data[offset+1], length * sizeof(string[0])); | 145 memcpy(string, &data[offset+1], length * sizeof(string[0])); |
140 string[length] = 0x0000U; /* be paranoid! add a terminator. */ | 146 string[length] = 0x0000U; /* be paranoid! add a terminator. */ |
141 loclstr[0] = '\0'; | 147 loclstr[0] = '\0'; |
142 | 148 |
143 /* convert from camera UCS-2 to our locale */ | 149 /* convert from camera UCS-2 to our locale */ |
144 src = (char *)string; | 150 src = (char *)string; |
145 srclen = length * sizeof(string[0]); | 151 srclen = length * sizeof(string[0]); |
146 dest = loclstr; | 152 dest = loclstr; |
147 destlen = sizeof(loclstr)-1; | 153 destlen = sizeof(loclstr)-1; |
148 nconv = (size_t)-1; | 154 nconv = (size_t)-1; |
149 #ifdef HAVE_ICONV | 155 #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H) |
150 if (params->cd_ucs2_to_locale != (iconv_t)-1) | 156 if (params->cd_ucs2_to_locale != (iconv_t)-1) |
151 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, &
destlen); | 157 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, &
destlen); |
152 #endif | 158 #endif |
153 if (nconv == (size_t) -1) { /* do it the hard way */ | 159 if (nconv == (size_t) -1) { /* do it the hard way */ |
154 int i; | 160 int i; |
155 /* try the old way, in case iconv is broken */ | 161 /* try the old way, in case iconv is broken */ |
156 for (i=0;i<length;i++) { | 162 for (i=0;i<length;i++) { |
157 if (dtoh16a(&data[offset+1+2*i])>127) | 163 if (dtoh16a(&data[offset+1+2*i])>127) |
158 loclstr[i] = '?'; | 164 loclstr[i] = '?'; |
159 else | 165 else |
(...skipping 20 matching lines...) Expand all Loading... |
180 static inline void | 186 static inline void |
181 ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o
ffset, uint8_t *len) | 187 ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o
ffset, uint8_t *len) |
182 { | 188 { |
183 int packedlen = 0; | 189 int packedlen = 0; |
184 uint16_t ucs2str[PTP_MAXSTRLEN+1]; | 190 uint16_t ucs2str[PTP_MAXSTRLEN+1]; |
185 char *ucs2strp = (char *) ucs2str; | 191 char *ucs2strp = (char *) ucs2str; |
186 size_t convlen = strlen(string); | 192 size_t convlen = strlen(string); |
187 | 193 |
188 /* Cannot exceed 255 (PTP_MAXSTRLEN) since it is a single byte, duh ...
*/ | 194 /* Cannot exceed 255 (PTP_MAXSTRLEN) since it is a single byte, duh ...
*/ |
189 memset(ucs2strp, 0, sizeof(ucs2str)); /* XXX: necessary? */ | 195 memset(ucs2strp, 0, sizeof(ucs2str)); /* XXX: necessary? */ |
190 #ifdef HAVE_ICONV | 196 #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H) |
191 if (params->cd_locale_to_ucs2 != (iconv_t)-1) { | 197 if (params->cd_locale_to_ucs2 != (iconv_t)-1) { |
192 size_t nconv; | 198 size_t nconv; |
193 size_t convmax = PTP_MAXSTRLEN * 2; /* Includes the terminator *
/ | 199 size_t convmax = PTP_MAXSTRLEN * 2; /* Includes the terminator *
/ |
194 char *stringp = string; | 200 char *stringp = string; |
195 | 201 |
196 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, | 202 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, |
197 &ucs2strp, &convmax); | 203 &ucs2strp, &convmax); |
198 if (nconv == (size_t) -1) | 204 if (nconv == (size_t) -1) |
199 ucs2str[0] = 0x0000U; | 205 ucs2str[0] = 0x0000U; |
200 } else | 206 } else |
201 #endif | 207 #endif |
202 { | 208 { |
203 » » int i; | 209 » » unsigned int i; |
| 210 |
204 for (i=0;i<convlen;i++) { | 211 for (i=0;i<convlen;i++) { |
205 ucs2str[i] = string[i]; | 212 ucs2str[i] = string[i]; |
206 } | 213 } |
207 ucs2str[convlen] = 0; | 214 ucs2str[convlen] = 0; |
208 } | 215 } |
209 /* | 216 /* |
210 * XXX: isn't packedlen just ( (uint16_t *)ucs2strp - ucs2str )? | 217 * XXX: isn't packedlen just ( (uint16_t *)ucs2strp - ucs2str )? |
211 * why do we need ucs2strlen()? | 218 * why do we need ucs2strlen()? |
212 */ | 219 */ |
213 packedlen = ucs2strlen(ucs2str); | 220 packedlen = ucs2strlen(ucs2str); |
(...skipping 30 matching lines...) Expand all Loading... |
244 if (!retcopy) { | 251 if (!retcopy) { |
245 *packed_size = 0; | 252 *packed_size = 0; |
246 return NULL; | 253 return NULL; |
247 } | 254 } |
248 memcpy(retcopy, packed, plen); | 255 memcpy(retcopy, packed, plen); |
249 *packed_size = plen; | 256 *packed_size = plen; |
250 return (retcopy); | 257 return (retcopy); |
251 } | 258 } |
252 | 259 |
253 static inline uint32_t | 260 static inline uint32_t |
254 ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, uint16_t offse
t, uint32_t **array) | 261 ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, unsigned int o
ffset, unsigned int datalen, uint32_t **array) |
255 { | 262 { |
256 uint32_t n, i=0; | 263 uint32_t n, i=0; |
257 | 264 |
| 265 if (offset >= datalen) |
| 266 return 0; |
| 267 |
| 268 if (offset + sizeof(uint32_t) > datalen) |
| 269 return 0; |
| 270 |
| 271 *array = NULL; |
258 n=dtoh32a(&data[offset]); | 272 n=dtoh32a(&data[offset]); |
| 273 if (n >= UINT_MAX/sizeof(uint32_t)) |
| 274 return 0; |
| 275 if (!n) |
| 276 return 0; |
| 277 |
| 278 if (offset + sizeof(uint32_t)*(n+1) > datalen) { |
| 279 ptp_debug (params ,"array runs over datalen bufferend (%d vs %d)
", offset + sizeof(uint32_t)*(n+1) , datalen); |
| 280 return 0; |
| 281 } |
| 282 |
259 *array = malloc (n*sizeof(uint32_t)); | 283 *array = malloc (n*sizeof(uint32_t)); |
260 » while (n>i) { | 284 » for (i=0;i<n;i++) |
261 (*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]); | 285 (*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]); |
262 i++; | |
263 } | |
264 return n; | 286 return n; |
265 } | 287 } |
266 | 288 |
267 static inline uint32_t | 289 static inline uint32_t |
268 ptp_pack_uint32_t_array(PTPParams *params, uint32_t *array, uint32_t arraylen, u
nsigned char **data ) | 290 ptp_pack_uint32_t_array(PTPParams *params, uint32_t *array, uint32_t arraylen, u
nsigned char **data ) |
269 { | 291 { |
270 uint32_t i=0; | 292 uint32_t i=0; |
271 | 293 |
272 *data = malloc ((arraylen+1)*sizeof(uint32_t)); | 294 *data = malloc ((arraylen+1)*sizeof(uint32_t)); |
273 htod32a(&(*data)[0],arraylen); | 295 htod32a(&(*data)[0],arraylen); |
274 for (i=0;i<arraylen;i++) | 296 for (i=0;i<arraylen;i++) |
275 htod32a(&(*data)[sizeof(uint32_t)*(i+1)], array[i]); | 297 htod32a(&(*data)[sizeof(uint32_t)*(i+1)], array[i]); |
276 return (arraylen+1)*sizeof(uint32_t); | 298 return (arraylen+1)*sizeof(uint32_t); |
277 } | 299 } |
278 | 300 |
279 static inline uint32_t | 301 static inline uint32_t |
280 ptp_unpack_uint16_t_array(PTPParams *params, unsigned char* data, uint16_t offse
t, uint16_t **array) | 302 ptp_unpack_uint16_t_array(PTPParams *params, unsigned char* data, unsigned int o
ffset, unsigned int datalen, uint16_t **array) |
281 { | 303 { |
282 uint32_t n, i=0; | 304 uint32_t n, i=0; |
283 | 305 |
| 306 *array = NULL; |
284 n=dtoh32a(&data[offset]); | 307 n=dtoh32a(&data[offset]); |
| 308 if (n >= UINT_MAX/sizeof(uint16_t)) |
| 309 return 0; |
| 310 if (!n) |
| 311 return 0; |
| 312 if (offset + sizeof(uint32_t) > datalen) |
| 313 return 0; |
| 314 if (offset + sizeof(uint32_t)+sizeof(uint16_t)*n > datalen) { |
| 315 ptp_debug (params ,"array runs over datalen bufferend (%d vs %d)
", offset + sizeof(uint32_t)+n*sizeof(uint16_t) , datalen); |
| 316 return 0; |
| 317 } |
285 *array = malloc (n*sizeof(uint16_t)); | 318 *array = malloc (n*sizeof(uint16_t)); |
286 » while (n>i) { | 319 » for (i=0;i<n;i++) |
287 (*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]); | 320 (*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]); |
288 i++; | |
289 } | |
290 return n; | 321 return n; |
291 } | 322 } |
292 | 323 |
293 /* DeviceInfo pack/unpack */ | 324 /* DeviceInfo pack/unpack */ |
294 | 325 |
295 #define PTP_di_StandardVersion 0 | 326 #define PTP_di_StandardVersion 0 |
296 #define PTP_di_VendorExtensionID 2 | 327 #define PTP_di_VendorExtensionID 2 |
297 #define PTP_di_VendorExtensionVersion 6 | 328 #define PTP_di_VendorExtensionVersion 6 |
298 #define PTP_di_VendorExtensionDesc 8 | 329 #define PTP_di_VendorExtensionDesc 8 |
299 #define PTP_di_FunctionalMode 8 | 330 #define PTP_di_FunctionalMode 8 |
(...skipping 13 matching lines...) Expand all Loading... |
313 di->VendorExtensionVersion = | 344 di->VendorExtensionVersion = |
314 dtoh16a(&data[PTP_di_VendorExtensionVersion]); | 345 dtoh16a(&data[PTP_di_VendorExtensionVersion]); |
315 di->VendorExtensionDesc = | 346 di->VendorExtensionDesc = |
316 ptp_unpack_string(params, data, | 347 ptp_unpack_string(params, data, |
317 PTP_di_VendorExtensionDesc, &len); | 348 PTP_di_VendorExtensionDesc, &len); |
318 totallen=len*2+1; | 349 totallen=len*2+1; |
319 di->FunctionalMode = | 350 di->FunctionalMode = |
320 dtoh16a(&data[PTP_di_FunctionalMode+totallen]); | 351 dtoh16a(&data[PTP_di_FunctionalMode+totallen]); |
321 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data, | 352 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data, |
322 PTP_di_OperationsSupported+totallen, | 353 PTP_di_OperationsSupported+totallen, |
| 354 datalen, |
323 &di->OperationsSupported); | 355 &di->OperationsSupported); |
324 totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(ui
nt32_t); | 356 totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(ui
nt32_t); |
325 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data, | 357 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data, |
326 PTP_di_OperationsSupported+totallen, | 358 PTP_di_OperationsSupported+totallen, |
| 359 datalen, |
327 &di->EventsSupported); | 360 &di->EventsSupported); |
328 totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32
_t); | 361 totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32
_t); |
329 di->DevicePropertiesSupported_len = | 362 di->DevicePropertiesSupported_len = |
330 ptp_unpack_uint16_t_array(params, data, | 363 ptp_unpack_uint16_t_array(params, data, |
331 PTP_di_OperationsSupported+totallen, | 364 PTP_di_OperationsSupported+totallen, |
| 365 datalen, |
332 &di->DevicePropertiesSupported); | 366 &di->DevicePropertiesSupported); |
333 totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+siz
eof(uint32_t); | 367 totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+siz
eof(uint32_t); |
334 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data, | 368 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data, |
335 PTP_di_OperationsSupported+totallen, | 369 PTP_di_OperationsSupported+totallen, |
| 370 datalen, |
336 &di->CaptureFormats); | 371 &di->CaptureFormats); |
337 totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_
t); | 372 totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_
t); |
338 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data, | 373 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data, |
339 PTP_di_OperationsSupported+totallen, | 374 PTP_di_OperationsSupported+totallen, |
| 375 datalen, |
340 &di->ImageFormats); | 376 &di->ImageFormats); |
341 totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t)
; | 377 totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t)
; |
342 di->Manufacturer = ptp_unpack_string(params, data, | 378 di->Manufacturer = ptp_unpack_string(params, data, |
343 PTP_di_OperationsSupported+totallen, | 379 PTP_di_OperationsSupported+totallen, |
344 &len); | 380 &len); |
345 totallen+=len*2+1; | 381 totallen+=len*2+1; |
346 di->Model = ptp_unpack_string(params, data, | 382 di->Model = ptp_unpack_string(params, data, |
347 PTP_di_OperationsSupported+totallen, | 383 PTP_di_OperationsSupported+totallen, |
348 &len); | 384 &len); |
349 totallen+=len*2+1; | 385 totallen+=len*2+1; |
350 di->DeviceVersion = ptp_unpack_string(params, data, | 386 di->DeviceVersion = ptp_unpack_string(params, data, |
351 PTP_di_OperationsSupported+totallen, | 387 PTP_di_OperationsSupported+totallen, |
352 &len); | 388 &len); |
353 totallen+=len*2+1; | 389 totallen+=len*2+1; |
354 di->SerialNumber = ptp_unpack_string(params, data, | 390 di->SerialNumber = ptp_unpack_string(params, data, |
355 PTP_di_OperationsSupported+totallen, | 391 PTP_di_OperationsSupported+totallen, |
356 &len); | 392 &len); |
357 } | 393 } |
358 | 394 |
359 static void inline | 395 inline static void |
360 ptp_free_DI (PTPDeviceInfo *di) { | 396 ptp_free_DI (PTPDeviceInfo *di) { |
361 » if (di->SerialNumber) free (di->SerialNumber); | 397 » free (di->SerialNumber); |
362 » if (di->DeviceVersion) free (di->DeviceVersion); | 398 » free (di->DeviceVersion); |
363 » if (di->Model) free (di->Model); | 399 » free (di->Model); |
364 » if (di->Manufacturer) free (di->Manufacturer); | 400 » free (di->Manufacturer); |
365 » if (di->ImageFormats) free (di->ImageFormats); | 401 » free (di->ImageFormats); |
366 » if (di->CaptureFormats) free (di->CaptureFormats); | 402 » free (di->CaptureFormats); |
367 » if (di->VendorExtensionDesc) free (di->VendorExtensionDesc); | 403 » free (di->VendorExtensionDesc); |
368 » if (di->OperationsSupported) free (di->OperationsSupported); | 404 » free (di->OperationsSupported); |
369 » if (di->EventsSupported) free (di->EventsSupported); | 405 » free (di->EventsSupported); |
370 » if (di->DevicePropertiesSupported) free (di->DevicePropertiesSupported); | 406 » free (di->DevicePropertiesSupported); |
371 } | 407 } |
372 | 408 |
373 /* EOS Device Info unpack */ | 409 /* EOS Device Info unpack */ |
374 static inline void | 410 static inline void |
375 ptp_unpack_EOS_DI (PTPParams *params, unsigned char* data, PTPCanonEOSDeviceInfo
*di, unsigned int datalen) | 411 ptp_unpack_EOS_DI (PTPParams *params, unsigned char* data, PTPCanonEOSDeviceInfo
*di, unsigned int datalen) |
376 { | 412 { |
377 » int totallen = 4; | 413 » unsigned int totallen = 4; |
378 | 414 |
379 memset (di,0, sizeof(*di)); | 415 memset (di,0, sizeof(*di)); |
380 if (datalen < 8) return; | 416 if (datalen < 8) return; |
381 | 417 |
382 /* uint32_t struct len - ignore */ | 418 /* uint32_t struct len - ignore */ |
383 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data, | 419 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data, |
384 » » totallen, &di->EventsSupported); | 420 » » totallen, datalen, &di->EventsSupported); |
385 if (!di->EventsSupported) return; | 421 if (!di->EventsSupported) return; |
386 totallen += di->EventsSupported_len*sizeof(uint32_t)+4; | 422 totallen += di->EventsSupported_len*sizeof(uint32_t)+4; |
387 if (totallen >= datalen) return; | 423 if (totallen >= datalen) return; |
388 | 424 |
389 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, da
ta, | 425 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, da
ta, |
390 » » totallen, &di->DevicePropertiesSupported); | 426 » » totallen, datalen, &di->DevicePropertiesSupported); |
391 if (!di->DevicePropertiesSupported) return; | 427 if (!di->DevicePropertiesSupported) return; |
392 totallen += di->DevicePropertiesSupported_len*sizeof(uint32_t)+4; | 428 totallen += di->DevicePropertiesSupported_len*sizeof(uint32_t)+4; |
393 if (totallen >= datalen) return; | 429 if (totallen >= datalen) return; |
394 | 430 |
395 di->unk_len = ptp_unpack_uint32_t_array(params, data, | 431 di->unk_len = ptp_unpack_uint32_t_array(params, data, |
396 » » totallen, &di->unk); | 432 » » totallen, datalen, &di->unk); |
397 if (!di->unk) return; | 433 if (!di->unk) return; |
398 totallen += di->unk_len*sizeof(uint32_t)+4; | 434 totallen += di->unk_len*sizeof(uint32_t)+4; |
399 return; | 435 return; |
400 } | 436 } |
401 | 437 |
402 static inline void | 438 static inline void |
403 ptp_free_EOS_DI (PTPCanonEOSDeviceInfo *di) | 439 ptp_free_EOS_DI (PTPCanonEOSDeviceInfo *di) |
404 { | 440 { |
405 free (di->EventsSupported); | 441 free (di->EventsSupported); |
406 free (di->DevicePropertiesSupported); | 442 free (di->DevicePropertiesSupported); |
407 free (di->unk); | 443 free (di->unk); |
408 } | 444 } |
409 | 445 |
410 /* ObjectHandles array pack/unpack */ | 446 /* ObjectHandles array pack/unpack */ |
411 | 447 |
412 #define PTP_oh 0 | 448 #define PTP_oh 0 |
413 | 449 |
414 static inline void | 450 static inline void |
415 ptp_unpack_OH (PTPParams *params, unsigned char* data, PTPObjectHandles *oh, uns
igned int len) | 451 ptp_unpack_OH (PTPParams *params, unsigned char* data, PTPObjectHandles *oh, uns
igned int len) |
416 { | 452 { |
417 if (len) { | 453 if (len) { |
418 » » oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, &oh->Han
dler); | 454 » » oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, len, &oh
->Handler); |
419 } else { | 455 } else { |
420 oh->n = 0; | 456 oh->n = 0; |
421 oh->Handler = NULL; | 457 oh->Handler = NULL; |
422 } | 458 } |
423 } | 459 } |
424 | 460 |
425 /* StoreIDs array pack/unpack */ | 461 /* StoreIDs array pack/unpack */ |
426 | 462 |
427 #define PTP_sids 0 | 463 #define PTP_sids 0 |
428 | 464 |
429 static inline void | 465 static inline void |
430 ptp_unpack_SIDs (PTPParams *params, unsigned char* data, PTPStorageIDs *sids, un
signed int len) | 466 ptp_unpack_SIDs (PTPParams *params, unsigned char* data, PTPStorageIDs *sids, un
signed int len) |
431 { | 467 { |
432 if (!data && !len) { | 468 » if (!data || !len) { |
433 sids->n = 0; | 469 sids->n = 0; |
434 sids->Storage = NULL; | 470 sids->Storage = NULL; |
435 return; | 471 return; |
436 } | 472 } |
437 » sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids, | 473 » sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids, len, &sids->
Storage); |
438 » &sids->Storage); | |
439 } | 474 } |
440 | 475 |
441 /* StorageInfo pack/unpack */ | 476 /* StorageInfo pack/unpack */ |
442 | 477 |
443 #define PTP_si_StorageType 0 | 478 #define PTP_si_StorageType 0 |
444 #define PTP_si_FilesystemType 2 | 479 #define PTP_si_FilesystemType 2 |
445 #define PTP_si_AccessCapability 4 | 480 #define PTP_si_AccessCapability 4 |
446 #define PTP_si_MaxCapability 6 | 481 #define PTP_si_MaxCapability 6 |
447 #define PTP_si_FreeSpaceInBytes 14 | 482 #define PTP_si_FreeSpaceInBytes 14 |
448 #define PTP_si_FreeSpaceInImages 22 | 483 #define PTP_si_FreeSpaceInImages 22 |
449 #define PTP_si_StorageDescription 26 | 484 #define PTP_si_StorageDescription 26 |
450 | 485 |
451 static inline void | 486 static inline void |
452 ptp_unpack_SI (PTPParams *params, unsigned char* data, PTPStorageInfo *si, unsig
ned int len) | 487 ptp_unpack_SI (PTPParams *params, unsigned char* data, PTPStorageInfo *si, unsig
ned int len) |
453 { | 488 { |
454 uint8_t storagedescriptionlen; | 489 uint8_t storagedescriptionlen; |
455 | 490 |
| 491 if (len < 26) return; |
456 si->StorageType=dtoh16a(&data[PTP_si_StorageType]); | 492 si->StorageType=dtoh16a(&data[PTP_si_StorageType]); |
457 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]); | 493 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]); |
458 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]); | 494 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]); |
459 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]); | 495 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]); |
460 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]); | 496 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]); |
461 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]); | 497 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]); |
| 498 |
| 499 /* FIXME: check more lengths here */ |
462 si->StorageDescription=ptp_unpack_string(params, data, | 500 si->StorageDescription=ptp_unpack_string(params, data, |
463 PTP_si_StorageDescription, &storagedescriptionlen); | 501 PTP_si_StorageDescription, &storagedescriptionlen); |
464 si->VolumeLabel=ptp_unpack_string(params, data, | 502 si->VolumeLabel=ptp_unpack_string(params, data, |
465 PTP_si_StorageDescription+storagedescriptionlen*2+1, | 503 PTP_si_StorageDescription+storagedescriptionlen*2+1, |
466 &storagedescriptionlen); | 504 &storagedescriptionlen); |
467 } | 505 } |
468 | 506 |
469 /* ObjectInfo pack/unpack */ | 507 /* ObjectInfo pack/unpack */ |
470 | 508 |
471 #define PTP_oi_StorageID 0 | 509 #define PTP_oi_StorageID 0 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 return mktime (&tm); | 635 return mktime (&tm); |
598 } | 636 } |
599 | 637 |
600 static inline void | 638 static inline void |
601 ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsign
ed int len) | 639 ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsign
ed int len) |
602 { | 640 { |
603 uint8_t filenamelen; | 641 uint8_t filenamelen; |
604 uint8_t capturedatelen; | 642 uint8_t capturedatelen; |
605 char *capture_date; | 643 char *capture_date; |
606 | 644 |
| 645 if (len < PTP_oi_SequenceNumber) |
| 646 return; |
| 647 |
| 648 oi->Filename = oi->Keywords = NULL; |
| 649 |
| 650 /* FIXME: also handle length with all the strings at the end */ |
607 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]); | 651 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]); |
608 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]); | 652 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]); |
609 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]); | 653 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]); |
610 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]); | 654 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]); |
611 | 655 |
612 /* Stupid Samsung Galaxy developers emit a 64bit objectcompressedsize */ | 656 /* Stupid Samsung Galaxy developers emit a 64bit objectcompressedsize */ |
613 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)
) { | 657 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0)
) { |
614 params->ocs64 = 1; | 658 params->ocs64 = 1; |
615 data += 4; | 659 data += 4; |
616 } | 660 } |
(...skipping 29 matching lines...) Expand all Loading... |
646 | 690 |
647 /* Custom Type Value Assignement (without Length) macro frequently used below */ | 691 /* Custom Type Value Assignement (without Length) macro frequently used below */ |
648 #define CTVAL(target,func) { \ | 692 #define CTVAL(target,func) { \ |
649 if (total - *offset < sizeof(target)) \ | 693 if (total - *offset < sizeof(target)) \ |
650 return 0; \ | 694 return 0; \ |
651 target = func(&data[*offset]); \ | 695 target = func(&data[*offset]); \ |
652 *offset += sizeof(target); \ | 696 *offset += sizeof(target); \ |
653 } | 697 } |
654 | 698 |
655 #define RARR(val,member,func) { \ | 699 #define RARR(val,member,func) { \ |
656 » int n,j;» » » » » \ | 700 » unsigned int n,j;» » » » \ |
657 if (total - *offset < sizeof(uint32_t)) \ | 701 if (total - *offset < sizeof(uint32_t)) \ |
658 return 0; \ | 702 return 0; \ |
659 n = dtoh32a (&data[*offset]); \ | 703 n = dtoh32a (&data[*offset]); \ |
660 *offset += sizeof(uint32_t); \ | 704 *offset += sizeof(uint32_t); \ |
661 \ | 705 \ |
| 706 if (n >= UINT_MAX/sizeof(val->a.v[0])) \ |
| 707 return 0; \ |
662 val->a.count = n; \ | 708 val->a.count = n; \ |
663 val->a.v = malloc(sizeof(val->a.v[0])*n); \ | 709 val->a.v = malloc(sizeof(val->a.v[0])*n); \ |
664 if (!val->a.v) return 0; \ | 710 if (!val->a.v) return 0; \ |
665 for (j=0;j<n;j++) \ | 711 for (j=0;j<n;j++) \ |
666 CTVAL(val->a.v[j].member, func); \ | 712 CTVAL(val->a.v[j].member, func); \ |
667 } | 713 } |
668 | 714 |
669 static inline int | 715 static inline unsigned int |
670 ptp_unpack_DPV ( | 716 ptp_unpack_DPV ( |
671 » PTPParams *params, unsigned char* data, int *offset, int total, | 717 » PTPParams *params, unsigned char* data, unsigned int *offset, unsigned i
nt total, |
672 PTPPropertyValue* value, uint16_t datatype | 718 PTPPropertyValue* value, uint16_t datatype |
673 ) { | 719 ) { |
674 switch (datatype) { | 720 switch (datatype) { |
675 case PTP_DTC_INT8: | 721 case PTP_DTC_INT8: |
676 CTVAL(value->i8,dtoh8a); | 722 CTVAL(value->i8,dtoh8a); |
677 break; | 723 break; |
678 case PTP_DTC_UINT8: | 724 case PTP_DTC_UINT8: |
679 CTVAL(value->u8,dtoh8a); | 725 CTVAL(value->u8,dtoh8a); |
680 break; | 726 break; |
681 case PTP_DTC_INT16: | 727 case PTP_DTC_INT16: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 return 1; | 789 return 1; |
744 break; | 790 break; |
745 } | 791 } |
746 default: | 792 default: |
747 return 0; | 793 return 0; |
748 } | 794 } |
749 return 1; | 795 return 1; |
750 } | 796 } |
751 | 797 |
752 /* Device Property pack/unpack */ | 798 /* Device Property pack/unpack */ |
753 | |
754 #define PTP_dpd_DevicePropertyCode 0 | 799 #define PTP_dpd_DevicePropertyCode 0 |
755 #define PTP_dpd_DataType 2 | 800 #define PTP_dpd_DataType 2 |
756 #define PTP_dpd_GetSet 4 | 801 #define PTP_dpd_GetSet 4 |
757 #define PTP_dpd_FactoryDefaultValue 5 | 802 #define PTP_dpd_FactoryDefaultValue 5 |
758 | 803 |
759 static inline int | 804 static inline int |
760 ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd,
unsigned int dpdlen) | 805 ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd,
unsigned int dpdlen) |
761 { | 806 { |
762 » int offset=0, ret; | 807 » unsigned int offset = 0, ret; |
763 | 808 |
764 memset (dpd, 0, sizeof(*dpd)); | 809 memset (dpd, 0, sizeof(*dpd)); |
765 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]); | 810 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]); |
766 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]); | 811 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]); |
767 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]); | 812 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]); |
768 dpd->FormFlag=PTP_DPFF_None; | 813 dpd->FormFlag=PTP_DPFF_None; |
769 | 814 |
770 offset = PTP_dpd_FactoryDefaultValue; | 815 offset = PTP_dpd_FactoryDefaultValue; |
771 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaul
tValue, dpd->DataType); | 816 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaul
tValue, dpd->DataType); |
772 if (!ret) goto outofmemory; | 817 if (!ret) goto outofmemory; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 867 } |
823 } | 868 } |
824 } | 869 } |
825 #undef N | 870 #undef N |
826 return 1; | 871 return 1; |
827 outofmemory: | 872 outofmemory: |
828 ptp_free_devicepropdesc(dpd); | 873 ptp_free_devicepropdesc(dpd); |
829 return 0; | 874 return 0; |
830 } | 875 } |
831 | 876 |
832 /* (MTP) Object Property pack/unpack */ | 877 /* Device Property pack/unpack */ |
| 878 #define PTP_dpd_Sony_DevicePropertyCode»0 |
| 879 #define PTP_dpd_Sony_DataType» » 2 |
| 880 #define PTP_dpd_Sony_GetSet» » 4 |
| 881 #define PTP_dpd_Sony_Unknown» » 5 |
| 882 #define PTP_dpd_Sony_FactoryDefaultValue» 6 |
| 883 |
| 884 static inline int |
| 885 ptp_unpack_Sony_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *
dpd, unsigned int dpdlen, unsigned int *poffset) |
| 886 { |
| 887 » unsigned int ret; |
| 888 #if 0 |
| 889 » unsigned int unk1, unk2; |
| 890 #endif |
| 891 |
| 892 » memset (dpd, 0, sizeof(*dpd)); |
| 893 » dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_Sony_DevicePropertyCode]); |
| 894 » dpd->DataType=dtoh16a(&data[PTP_dpd_Sony_DataType]); |
| 895 |
| 896 #if 0 |
| 897 » /* get set ? */ |
| 898 » unk1 = dtoh8a(&data[PTP_dpd_Sony_GetSet]); |
| 899 » unk2 = dtoh8a(&data[PTP_dpd_Sony_Unknown]); |
| 900 » ptp_debug (params, "prop 0x%04x, datatype 0x%04x, unk1 %d unk2 %d", dpd-
>DevicePropertyCode, dpd->DataType, unk1, unk2); |
| 901 #endif |
| 902 » dpd->GetSet=1; |
| 903 |
| 904 » dpd->FormFlag=PTP_DPFF_None; |
| 905 |
| 906 » *poffset = PTP_dpd_Sony_FactoryDefaultValue; |
| 907 » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FactoryDefaul
tValue, dpd->DataType); |
| 908 » if (!ret) goto outofmemory; |
| 909 » if ((dpd->DataType == PTP_DTC_STR) && (*poffset == dpdlen)) |
| 910 » » return 1; |
| 911 » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->CurrentValue,
dpd->DataType); |
| 912 » if (!ret) goto outofmemory; |
| 913 |
| 914 » /* if offset==0 then Data Type format is not supported by this |
| 915 » code or the Data Type is a string (with two empty strings as |
| 916 » values). In both cases Form Flag should be set to 0x00 and FORM is |
| 917 » not present. */ |
| 918 |
| 919 » if (*poffset==PTP_dpd_Sony_FactoryDefaultValue) |
| 920 » » return 1; |
| 921 |
| 922 » dpd->FormFlag=dtoh8a(&data[*poffset]); |
| 923 » *poffset+=sizeof(uint8_t); |
| 924 |
| 925 » switch (dpd->FormFlag) { |
| 926 » case PTP_DPFF_Range: |
| 927 » » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.
Range.MinimumValue, dpd->DataType); |
| 928 » » if (!ret) goto outofmemory; |
| 929 » » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.
Range.MaximumValue, dpd->DataType); |
| 930 » » if (!ret) goto outofmemory; |
| 931 » » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dpd->FORM.
Range.StepSize, dpd->DataType); |
| 932 » » if (!ret) goto outofmemory; |
| 933 » » break; |
| 934 » case PTP_DPFF_Enumeration: { |
| 935 » » int i; |
| 936 #define N» dpd->FORM.Enum.NumberOfValues |
| 937 » » N = dtoh16a(&data[*poffset]); |
| 938 » » *poffset+=sizeof(uint16_t); |
| 939 » » dpd->FORM.Enum.SupportedValue = malloc(N*sizeof(dpd->FORM.Enum.S
upportedValue[0])); |
| 940 » » if (!dpd->FORM.Enum.SupportedValue) |
| 941 » » » goto outofmemory; |
| 942 |
| 943 » » memset (dpd->FORM.Enum.SupportedValue,0 , N*sizeof(dpd->FORM.Enu
m.SupportedValue[0])); |
| 944 » » for (i=0;i<N;i++) { |
| 945 » » » ret = ptp_unpack_DPV (params, data, poffset, dpdlen, &dp
d->FORM.Enum.SupportedValue[i], dpd->DataType); |
| 946 |
| 947 » » » /* Slightly different handling here. The HP PhotoSmart 1
20 |
| 948 » » » * specifies an enumeration with N in wrong endian |
| 949 » » » * 00 01 instead of 01 00, so we count the enum just unt
il the |
| 950 » » » * the end of the packet. |
| 951 » » » */ |
| 952 » » » if (!ret) { |
| 953 » » » » if (!i) |
| 954 » » » » » goto outofmemory; |
| 955 » » » » dpd->FORM.Enum.NumberOfValues = i; |
| 956 » » » » break; |
| 957 » » » } |
| 958 » » } |
| 959 » » } |
| 960 » } |
| 961 #undef N |
| 962 » return 1; |
| 963 outofmemory: |
| 964 » ptp_free_devicepropdesc(dpd); |
| 965 » return 0; |
| 966 } |
| 967 |
| 968 static inline void |
| 969 duplicate_PropertyValue (const PTPPropertyValue *src, PTPPropertyValue *dst, uin
t16_t type) { |
| 970 » if (type == PTP_DTC_STR) { |
| 971 » » if (src->str) |
| 972 » » » dst->str = strdup(src->str); |
| 973 » » else |
| 974 » » » dst->str = NULL; |
| 975 » » return; |
| 976 » } |
| 977 |
| 978 » if (type & PTP_DTC_ARRAY_MASK) { |
| 979 » » unsigned int i; |
| 980 |
| 981 » » dst->a.count = src->a.count; |
| 982 » » dst->a.v = malloc (sizeof(src->a.v[0])*src->a.count); |
| 983 » » for (i=0;i<src->a.count;i++) |
| 984 » » » duplicate_PropertyValue (&src->a.v[i], &dst->a.v[i], typ
e & ~PTP_DTC_ARRAY_MASK); |
| 985 » » return; |
| 986 » } |
| 987 » switch (type & ~PTP_DTC_ARRAY_MASK) { |
| 988 » case PTP_DTC_INT8:» dst->i8 = src->i8; break; |
| 989 » case PTP_DTC_UINT8:» dst->u8 = src->u8; break; |
| 990 » case PTP_DTC_INT16:» dst->i16 = src->i16; break; |
| 991 » case PTP_DTC_UINT16:» dst->u16 = src->u16; break; |
| 992 » case PTP_DTC_INT32:» dst->i32 = src->i32; break; |
| 993 » case PTP_DTC_UINT32:» dst->u32 = src->u32; break; |
| 994 » case PTP_DTC_UINT64:» dst->u64 = src->u64; break; |
| 995 » case PTP_DTC_INT64:» dst->i64 = src->i64; break; |
| 996 #if 0 |
| 997 » case PTP_DTC_INT128:» dst->i128 = src->i128; break; |
| 998 » case PTP_DTC_UINT128:» dst->u128 = src->u128; break; |
| 999 #endif |
| 1000 » default:» » break; |
| 1001 » } |
| 1002 » return; |
| 1003 } |
| 1004 |
| 1005 static inline void |
| 1006 duplicate_DevicePropDesc(const PTPDevicePropDesc *src, PTPDevicePropDesc *dst) { |
| 1007 » int i; |
| 1008 |
| 1009 » dst->DevicePropertyCode»= src->DevicePropertyCode; |
| 1010 » dst->DataType» » = src->DataType; |
| 1011 » dst->GetSet» » = src->GetSet; |
| 1012 » |
| 1013 » duplicate_PropertyValue (&src->FactoryDefaultValue, &dst->FactoryDefault
Value, src->DataType); |
| 1014 » duplicate_PropertyValue (&src->CurrentValue, &dst->CurrentValue, src->Da
taType); |
| 1015 |
| 1016 » dst->FormFlag» » = src->FormFlag; |
| 1017 » switch (src->FormFlag) { |
| 1018 » case PTP_DPFF_Range: |
| 1019 » » duplicate_PropertyValue (&src->FORM.Range.MinimumValue, &dst->FO
RM.Range.MinimumValue, src->DataType); |
| 1020 » » duplicate_PropertyValue (&src->FORM.Range.MaximumValue, &dst->FO
RM.Range.MaximumValue, src->DataType); |
| 1021 » » duplicate_PropertyValue (&src->FORM.Range.StepSize, &dst->FO
RM.Range.StepSize, src->DataType); |
| 1022 » » break; |
| 1023 » case PTP_DPFF_Enumeration: |
| 1024 » » dst->FORM.Enum.NumberOfValues = src->FORM.Enum.NumberOfValues; |
| 1025 » » dst->FORM.Enum.SupportedValue = malloc (sizeof(dst->FORM.Enum.Su
pportedValue[0])*src->FORM.Enum.NumberOfValues); |
| 1026 » » for (i = 0; i<src->FORM.Enum.NumberOfValues ; i++) |
| 1027 » » » duplicate_PropertyValue (&src->FORM.Enum.SupportedValue[
i], &dst->FORM.Enum.SupportedValue[i], src->DataType); |
| 1028 » » break; |
| 1029 » case PTP_DPFF_None: |
| 1030 » » break; |
| 1031 » } |
| 1032 } |
| 1033 |
833 #define PTP_opd_ObjectPropertyCode 0 | 1034 #define PTP_opd_ObjectPropertyCode 0 |
834 #define PTP_opd_DataType 2 | 1035 #define PTP_opd_DataType 2 |
835 #define PTP_opd_GetSet 4 | 1036 #define PTP_opd_GetSet 4 |
836 #define PTP_opd_FactoryDefaultValue 5 | 1037 #define PTP_opd_FactoryDefaultValue 5 |
837 | 1038 |
838 static inline int | 1039 static inline int |
839 ptp_unpack_OPD (PTPParams *params, unsigned char* data, PTPObjectPropDesc *opd,
unsigned int opdlen) | 1040 ptp_unpack_OPD (PTPParams *params, unsigned char* data, PTPObjectPropDesc *opd,
unsigned int opdlen) |
840 { | 1041 { |
841 » int offset=0, ret; | 1042 » unsigned int offset=0, ret; |
842 | 1043 |
843 memset (opd, 0, sizeof(*opd)); | 1044 memset (opd, 0, sizeof(*opd)); |
844 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]); | 1045 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]); |
845 opd->DataType=dtoh16a(&data[PTP_opd_DataType]); | 1046 opd->DataType=dtoh16a(&data[PTP_opd_DataType]); |
846 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]); | 1047 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]); |
847 | 1048 |
848 offset = PTP_opd_FactoryDefaultValue; | 1049 offset = PTP_opd_FactoryDefaultValue; |
849 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaul
tValue, opd->DataType); | 1050 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaul
tValue, opd->DataType); |
850 if (!ret) goto outofmemory; | 1051 if (!ret) goto outofmemory; |
851 | 1052 |
852 opd->GroupCode=dtoh32a(&data[offset]); | 1053 opd->GroupCode=dtoh32a(&data[offset]); |
853 offset+=sizeof(uint32_t); | 1054 offset+=sizeof(uint32_t); |
854 | 1055 |
855 opd->FormFlag=dtoh8a(&data[offset]); | 1056 opd->FormFlag=dtoh8a(&data[offset]); |
856 offset+=sizeof(uint8_t); | 1057 offset+=sizeof(uint8_t); |
857 | 1058 |
858 switch (opd->FormFlag) { | 1059 switch (opd->FormFlag) { |
859 case PTP_OPFF_Range: | 1060 case PTP_OPFF_Range: |
860 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.MinimumValue, opd->DataType); | 1061 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.MinimumValue, opd->DataType); |
861 if (!ret) goto outofmemory; | 1062 if (!ret) goto outofmemory; |
862 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.MaximumValue, opd->DataType); | 1063 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.MaximumValue, opd->DataType); |
863 if (!ret) goto outofmemory; | 1064 if (!ret) goto outofmemory; |
864 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.StepSize, opd->DataType); | 1065 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM.
Range.StepSize, opd->DataType); |
865 if (!ret) goto outofmemory; | 1066 if (!ret) goto outofmemory; |
866 break; | 1067 break; |
867 case PTP_OPFF_Enumeration: { | 1068 case PTP_OPFF_Enumeration: { |
868 » » int i; | 1069 » » unsigned int i; |
869 #define N opd->FORM.Enum.NumberOfValues | 1070 #define N opd->FORM.Enum.NumberOfValues |
870 N = dtoh16a(&data[offset]); | 1071 N = dtoh16a(&data[offset]); |
871 offset+=sizeof(uint16_t); | 1072 offset+=sizeof(uint16_t); |
872 opd->FORM.Enum.SupportedValue = malloc(N*sizeof(opd->FORM.Enum.S
upportedValue[0])); | 1073 opd->FORM.Enum.SupportedValue = malloc(N*sizeof(opd->FORM.Enum.S
upportedValue[0])); |
873 if (!opd->FORM.Enum.SupportedValue) | 1074 if (!opd->FORM.Enum.SupportedValue) |
874 goto outofmemory; | 1075 goto outofmemory; |
875 | 1076 |
876 memset (opd->FORM.Enum.SupportedValue,0 , N*sizeof(opd->FORM.Enu
m.SupportedValue[0])); | 1077 memset (opd->FORM.Enum.SupportedValue,0 , N*sizeof(opd->FORM.Enu
m.SupportedValue[0])); |
877 for (i=0;i<N;i++) { | 1078 for (i=0;i<N;i++) { |
878 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &op
d->FORM.Enum.SupportedValue[i], opd->DataType); | 1079 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &op
d->FORM.Enum.SupportedValue[i], opd->DataType); |
(...skipping 18 matching lines...) Expand all Loading... |
897 ptp_free_objectpropdesc(opd); | 1098 ptp_free_objectpropdesc(opd); |
898 return 0; | 1099 return 0; |
899 } | 1100 } |
900 | 1101 |
901 | 1102 |
902 static inline uint32_t | 1103 static inline uint32_t |
903 ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr
, uint16_t datatype) | 1104 ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr
, uint16_t datatype) |
904 { | 1105 { |
905 unsigned char* dpv=NULL; | 1106 unsigned char* dpv=NULL; |
906 uint32_t size=0; | 1107 uint32_t size=0; |
907 » int» i; | 1108 » unsigned int i; |
908 | 1109 |
909 switch (datatype) { | 1110 switch (datatype) { |
910 case PTP_DTC_INT8: | 1111 case PTP_DTC_INT8: |
911 size=sizeof(int8_t); | 1112 size=sizeof(int8_t); |
912 dpv=malloc(size); | 1113 dpv=malloc(size); |
913 htod8a(dpv,value->i8); | 1114 htod8a(dpv,value->i8); |
914 break; | 1115 break; |
915 case PTP_DTC_UINT8: | 1116 case PTP_DTC_UINT8: |
916 size=sizeof(uint8_t); | 1117 size=sizeof(uint8_t); |
917 dpv=malloc(size); | 1118 dpv=malloc(size); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 const MTPProperties *py = y; | 1279 const MTPProperties *py = y; |
1079 | 1280 |
1080 return px->ObjectHandle - py->ObjectHandle; | 1281 return px->ObjectHandle - py->ObjectHandle; |
1081 } | 1282 } |
1082 | 1283 |
1083 static inline int | 1284 static inline int |
1084 ptp_unpack_OPL (PTPParams *params, unsigned char* data, MTPProperties **pprops,
unsigned int len) | 1285 ptp_unpack_OPL (PTPParams *params, unsigned char* data, MTPProperties **pprops,
unsigned int len) |
1085 { | 1286 { |
1086 uint32_t prop_count = dtoh32a(data); | 1287 uint32_t prop_count = dtoh32a(data); |
1087 MTPProperties *props = NULL; | 1288 MTPProperties *props = NULL; |
1088 » int offset = 0, i; | 1289 » unsigned int offset = 0, i; |
1089 | 1290 |
1090 if (prop_count == 0) { | 1291 if (prop_count == 0) { |
1091 *pprops = NULL; | 1292 *pprops = NULL; |
1092 return 0; | 1293 return 0; |
1093 } | 1294 } |
1094 ptp_debug (params ,"Unpacking MTP OPL, size %d (prop_count %d)", len, pr
op_count); | 1295 ptp_debug (params ,"Unpacking MTP OPL, size %d (prop_count %d)", len, pr
op_count); |
1095 data += sizeof(uint32_t); | 1296 data += sizeof(uint32_t); |
1096 len -= sizeof(uint32_t); | 1297 len -= sizeof(uint32_t); |
1097 props = malloc(prop_count * sizeof(MTPProperties)); | 1298 props = malloc(prop_count * sizeof(MTPProperties)); |
1098 if (!props) return 0; | 1299 if (!props) return 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 #define PTP_ec_Type 4 | 1337 #define PTP_ec_Type 4 |
1137 #define PTP_ec_Code 6 | 1338 #define PTP_ec_Code 6 |
1138 #define PTP_ec_TransId 8 | 1339 #define PTP_ec_TransId 8 |
1139 #define PTP_ec_Param1 12 | 1340 #define PTP_ec_Param1 12 |
1140 #define PTP_ec_Param2 16 | 1341 #define PTP_ec_Param2 16 |
1141 #define PTP_ec_Param3 20 | 1342 #define PTP_ec_Param3 20 |
1142 | 1343 |
1143 static inline void | 1344 static inline void |
1144 ptp_unpack_EC (PTPParams *params, unsigned char* data, PTPContainer *ec, unsigne
d int len) | 1345 ptp_unpack_EC (PTPParams *params, unsigned char* data, PTPContainer *ec, unsigne
d int len) |
1145 { | 1346 { |
1146 » int» length; | 1347 » unsigned int» length; |
1147 int type; | 1348 int type; |
1148 | 1349 |
1149 if (data==NULL) | 1350 if (data==NULL) |
1150 return; | 1351 return; |
1151 memset(ec,0,sizeof(*ec)); | 1352 memset(ec,0,sizeof(*ec)); |
| 1353 |
1152 length=dtoh32a(&data[PTP_ec_Length]); | 1354 length=dtoh32a(&data[PTP_ec_Length]); |
| 1355 if (length > len) { |
| 1356 ptp_debug (params, "length %d in container, but data only %d byt
es?!", length, len); |
| 1357 return; |
| 1358 } |
1153 type = dtoh16a(&data[PTP_ec_Type]); | 1359 type = dtoh16a(&data[PTP_ec_Type]); |
1154 | 1360 |
1155 ec->Code=dtoh16a(&data[PTP_ec_Code]); | 1361 ec->Code=dtoh16a(&data[PTP_ec_Code]); |
1156 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]); | 1362 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]); |
1157 | 1363 |
1158 if (type!=PTP_USB_CONTAINER_EVENT) { | 1364 if (type!=PTP_USB_CONTAINER_EVENT) { |
1159 ptp_debug (params, "Unknown canon event type %d (code=%x,tid=%x)
, please report!",type,ec->Code,ec->Transaction_ID); | 1365 ptp_debug (params, "Unknown canon event type %d (code=%x,tid=%x)
, please report!",type,ec->Code,ec->Transaction_ID); |
1160 return; | 1366 return; |
1161 } | 1367 } |
1162 if (length>=(PTP_ec_Param1+4)) { | 1368 if (length>=(PTP_ec_Param1+4)) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 AssociationType: 0x0000 | 1439 AssociationType: 0x0000 |
1234 AssociationDesc: 0x00000000 | 1440 AssociationDesc: 0x00000000 |
1235 SequenceNumber: 0x00000000 | 1441 SequenceNumber: 0x00000000 |
1236 ModificationDate: 0x4d985ff0 | 1442 ModificationDate: 0x4d985ff0 |
1237 CaptureDate: 0x4d985ff0 | 1443 CaptureDate: 0x4d985ff0 |
1238 | 1444 |
1239 0010 38 00 00 00 Size of this entry | 1445 0010 38 00 00 00 Size of this entry |
1240 0014 72 0c 74 92 OID | 1446 0014 72 0c 74 92 OID |
1241 0018 01 00 02 00 StorageID | 1447 0018 01 00 02 00 StorageID |
1242 001c 01 38 00 00 OFC | 1448 001c 01 38 00 00 OFC |
1243 0020 00 00 00 00 00 00 00 00 ? | 1449 0020 00 00 00 00 ?? |
| 1450 0024 21 00 00 00 flags (4 bytes? 1 byte?) |
1244 0028 19 d5 21 00 Size | 1451 0028 19 d5 21 00 Size |
1245 002c 00 00 74 92 ? | 1452 002c 00 00 74 92 ? |
1246 0030 70 0c 74 92 OID | 1453 0030 70 0c 74 92 OID |
1247 0034 49 4d 47 5f-30 31 39 39 2e 4a 50 47 IMG_0199.JPG | 1454 0034 49 4d 47 5f-30 31 39 39 2e 4a 50 47 IMG_0199.JPG |
1248 0040 00 00 00 00 | 1455 0040 00 00 00 00 |
1249 0044 10 7c 98 4d Time | 1456 0044 10 7c 98 4d Time |
1250 | 1457 |
1251 | 1458 |
1252 */ | 1459 */ |
1253 #define PTP_cefe_ObjectHandle 0 | 1460 #define PTP_cefe_ObjectHandle 0 |
1254 #define PTP_cefe_StorageID 4 | 1461 #define PTP_cefe_StorageID 4 |
1255 #define PTP_cefe_ObjectFormatCode 8 | 1462 #define PTP_cefe_ObjectFormatCode 8 |
1256 #define PTP_cefe_Flags» » » 12 | 1463 #define PTP_cefe_Flags» » » 16 |
1257 #define PTP_cefe_ObjectSize 20 | 1464 #define PTP_cefe_ObjectSize 20 |
1258 #define PTP_cefe_Filename 32 | 1465 #define PTP_cefe_Filename 32 |
1259 #define PTP_cefe_Time 48 | 1466 #define PTP_cefe_Time 48 |
1260 | 1467 |
1261 static inline void | 1468 static inline void |
1262 ptp_unpack_Canon_EOS_FE (PTPParams *params, unsigned char* data, PTPCANONFolderE
ntry *fe) | 1469 ptp_unpack_Canon_EOS_FE (PTPParams *params, unsigned char* data, PTPCANONFolderE
ntry *fe) |
1263 { | 1470 { |
1264 int i; | 1471 int i; |
1265 | 1472 |
1266 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]); | 1473 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 htod32a(data+=4, ((value >> 0) & 0xF) == 4 ? 6 : 1); | 1572 htod32a(data+=4, ((value >> 0) & 0xF) == 4 ? 6 : 1); |
1366 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF)); | 1573 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF)); |
1367 htod32a(data+=4, (value >> 0) & 0xF); | 1574 htod32a(data+=4, (value >> 0) & 0xF); |
1368 } | 1575 } |
1369 | 1576 |
1370 #undef PACK_5DM3_SMALL_JPEG_SIZE | 1577 #undef PACK_5DM3_SMALL_JPEG_SIZE |
1371 | 1578 |
1372 return s; | 1579 return s; |
1373 } | 1580 } |
1374 | 1581 |
| 1582 /* 00: 32 bit size |
| 1583 * 04: 16 bit subsize |
| 1584 * 08: 16 bit version (?) |
| 1585 * 0c: 16 bit focus_points_in_struct |
| 1586 * 10: 16 bit focus_points_in_use |
| 1587 * 14: variable arrays: |
| 1588 * 16 bit sizex, 16 bit sizey |
| 1589 * 16 bit othersizex, 16 bit othersizey |
| 1590 * 16 bit array height[focus_points_in_struct] |
| 1591 * 16 bit array width[focus_points_in_struct] |
| 1592 * 16 bit array offsetheight[focus_points_in_struct] middle is 0 |
| 1593 * 16 bit array offsetwidth[focus_points_in_struct] middle is ? |
| 1594 * bitfield of selected focus points, starting with 0 [size focus_points_in_stru
ct in bits] |
| 1595 * unknown stuff , likely which are active |
| 1596 * 16 bit 0xffff |
| 1597 * |
| 1598 * size=NxN,size2=NxN,points={NxNxNxN,NxNxNxN,...},selected={0,1,2} |
| 1599 */ |
| 1600 static inline char* |
| 1601 ptp_unpack_EOS_FocusInfoEx (PTPParams* params, unsigned char** data ) |
| 1602 { |
| 1603 uint32_t size = dtoh32a( *data ); |
| 1604 uint32_t halfsize = dtoh16a( (*data) + 4); |
| 1605 uint32_t version = dtoh16a( (*data) + 6); |
| 1606 uint32_t focus_points_in_struct = dtoh16a( (*data) + 8); |
| 1607 uint32_t focus_points_in_use = dtoh16a( (*data) + 10); |
| 1608 uint32_t sizeX = dtoh16a( (*data) + 12); |
| 1609 uint32_t sizeY = dtoh16a( (*data) + 14); |
| 1610 uint32_t size2X = dtoh16a( (*data) + 16); |
| 1611 uint32_t size2Y = dtoh16a( (*data) + 18); |
| 1612 uint32_t i; |
| 1613 uint32_t maxlen; |
| 1614 char *str, *p; |
| 1615 |
| 1616 /* every focuspoint gets 4 (16 bit number and a x) and a ,*/ |
| 1617 /* inital things around lets say 100 chars at most. |
| 1618 * FIXME: check selected when we decode it */ |
| 1619 maxlen = focus_points_in_use*6*4 + focus_points_in_use + 100; |
| 1620 if (halfsize != size-4) { |
| 1621 ptp_error(params, "halfsize %d is not expected %d", halfsize, si
ze-4); |
| 1622 return "bad size"; |
| 1623 } |
| 1624 if (20 + focus_points_in_struct*8 + (focus_points_in_struct+7)/8 > size)
{ |
| 1625 ptp_error(params, "size %d is too large for fp in struct %d", fo
cus_points_in_struct*8 + 20 + (focus_points_in_struct+7)/8, size); |
| 1626 return "bad size 2"; |
| 1627 } |
| 1628 #if 0 |
| 1629 ptp_debug(params,"d1d3 content:"); |
| 1630 for (i=0;i<size;i+=2) |
| 1631 ptp_debug(params,"%d: %02x %02x", i, (*data)[i], (*data)[i+1]); |
| 1632 #endif |
| 1633 ptp_debug(params,"d1d3 version", version); |
| 1634 ptp_debug(params,"d1d3 focus points in struct %d, in use %d", focus_poin
ts_in_struct, focus_points_in_use); |
| 1635 |
| 1636 str = (char*)malloc( maxlen ); |
| 1637 if (!str) |
| 1638 return NULL; |
| 1639 p = str; |
| 1640 |
| 1641 p += sprintf(p,"eosversion=%d,size=%dx%d,size2=%dx%d,points={", version,
sizeX, sizeY, size2X, size2Y); |
| 1642 for (i=0;i<focus_points_in_use;i++) { |
| 1643 int16_t x = dtoh16a((*data) + focus_points_in_struct*4 + 20 + 2*
i); |
| 1644 int16_t y = dtoh16a((*data) + focus_points_in_struct*6 + 20 + 2*
i); |
| 1645 int16_t w = dtoh16a((*data) + focus_points_in_struct*2 + 20 + 2*
i); |
| 1646 int16_t h = dtoh16a((*data) + focus_points_in_struct*0 + 20 + 2*
i); |
| 1647 |
| 1648 p += sprintf(p,"{%d,%d,%d,%d}",x,y,w,h); |
| 1649 |
| 1650 if (i<focus_points_in_use-1) |
| 1651 p += sprintf(p,","); |
| 1652 } |
| 1653 p += sprintf(p,"},select={"); |
| 1654 for (i=0;i<focus_points_in_use;i++) { |
| 1655 if ((1<<(i%7)) & ((*data)[focus_points_in_struct*8+20+i/8])) |
| 1656 p+=sprintf(p,"%d,", i); |
| 1657 } |
| 1658 |
| 1659 p += sprintf(p,"},unknown={"); |
| 1660 for (i=focus_points_in_struct*8+(focus_points_in_struct+7)/8+20;i<size;i
++) { |
| 1661 p+=sprintf(p,"%02x", (*data)[i]); |
| 1662 } |
| 1663 p += sprintf(p,"}"); |
| 1664 return str; |
| 1665 } |
| 1666 |
| 1667 |
1375 static inline char* | 1668 static inline char* |
1376 ptp_unpack_EOS_CustomFuncEx (PTPParams* params, unsigned char** data ) | 1669 ptp_unpack_EOS_CustomFuncEx (PTPParams* params, unsigned char** data ) |
1377 { | 1670 { |
1378 uint32_t s = dtoh32a( *data ); | 1671 uint32_t s = dtoh32a( *data ); |
1379 uint32_t n = s/4, i; | 1672 uint32_t n = s/4, i; |
1380 » char* str = (char*)malloc( s ); // n is size in uint32, average len(itoa
(i)) < 4 -> alloc n chars | 1673 » char* str = (char*)malloc( s*2+s/4+1 ); /* n is size in uint32, maximum
%x len is 8 chars and \0*/ |
1381 if (!str) | 1674 if (!str) |
1382 return str; | 1675 return str; |
1383 char* p = str; | 1676 char* p = str; |
1384 | 1677 |
1385 for (i=0; i < n; ++i) | 1678 for (i=0; i < n; ++i) |
1386 p += sprintf(p, "%x,", dtoh32a( *data + 4*i )); | 1679 p += sprintf(p, "%x,", dtoh32a( *data + 4*i )); |
1387 | 1680 |
1388 return str; | 1681 return str; |
1389 } | 1682 } |
1390 | 1683 |
1391 static inline uint32_t | 1684 static inline uint32_t |
1392 ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str) | 1685 ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str) |
1393 { | 1686 { |
1394 uint32_t s = strtoul(str, NULL, 16); | 1687 uint32_t s = strtoul(str, NULL, 16); |
1395 uint32_t n = s/4, i, v; | 1688 uint32_t n = s/4, i, v; |
1396 | 1689 |
1397 if (!data) | 1690 if (!data) |
1398 return s; | 1691 return s; |
1399 | 1692 |
1400 for (i=0; i<n; i++) | 1693 for (i=0; i<n; i++) |
1401 { | 1694 { |
1402 v = strtoul(str, &str, 16); | 1695 v = strtoul(str, &str, 16); |
1403 » » str++; // skip the ',' delimiter | 1696 » » str++; /* skip the ',' delimiter */ |
1404 htod32a(data + i*4, v); | 1697 htod32a(data + i*4, v); |
1405 } | 1698 } |
1406 | 1699 |
1407 return s; | 1700 return s; |
1408 } | 1701 } |
1409 | 1702 |
1410 /* | 1703 /* |
1411 PTP EOS Changes Entry unpack | 1704 PTP EOS Changes Entry unpack |
1412 */ | 1705 */ |
1413 #define PTP_ece_Size 0 | 1706 #define PTP_ece_Size 0 |
(...skipping 12 matching lines...) Expand all Loading... |
1426 #define PTP_ece_OI_Name 0x1c | 1719 #define PTP_ece_OI_Name 0x1c |
1427 | 1720 |
1428 /* for PTP_EC_CANON_EOS_ObjectAddedEx */ | 1721 /* for PTP_EC_CANON_EOS_ObjectAddedEx */ |
1429 #define PTP_ece_OA_ObjectID 8 | 1722 #define PTP_ece_OA_ObjectID 8 |
1430 #define PTP_ece_OA_StorageID 0x0c | 1723 #define PTP_ece_OA_StorageID 0x0c |
1431 #define PTP_ece_OA_OFC 0x10 | 1724 #define PTP_ece_OA_OFC 0x10 |
1432 #define PTP_ece_OA_Size 0x1c | 1725 #define PTP_ece_OA_Size 0x1c |
1433 #define PTP_ece_OA_Parent 0x20 | 1726 #define PTP_ece_OA_Parent 0x20 |
1434 #define PTP_ece_OA_Name 0x28 | 1727 #define PTP_ece_OA_Name 0x28 |
1435 | 1728 |
| 1729 static PTPDevicePropDesc* |
| 1730 _lookup_or_allocate_canon_prop(PTPParams *params, uint16_t proptype) |
| 1731 { |
| 1732 unsigned int j; |
| 1733 |
| 1734 for (j=0;j<params->nrofcanon_props;j++) |
| 1735 if (params->canon_props[j].proptype == proptype) |
| 1736 break; |
| 1737 if (j<params->nrofcanon_props) |
| 1738 return ¶ms->canon_props[j].dpd; |
| 1739 |
| 1740 if (j) |
| 1741 params->canon_props = realloc(params->canon_props, sizeof(params
->canon_props[0])*(j+1)); |
| 1742 else |
| 1743 params->canon_props = malloc(sizeof(params->canon_props[0])); |
| 1744 params->canon_props[j].proptype = proptype; |
| 1745 params->canon_props[j].size = 0; |
| 1746 params->canon_props[j].data = NULL; |
| 1747 memset (¶ms->canon_props[j].dpd,0,sizeof(params->canon_props[j].dpd)
); |
| 1748 params->canon_props[j].dpd.GetSet = 1; |
| 1749 params->canon_props[j].dpd.FormFlag = PTP_DPFF_None; |
| 1750 params->nrofcanon_props = j+1; |
| 1751 return ¶ms->canon_props[j].dpd; |
| 1752 } |
| 1753 |
| 1754 |
1436 static inline int | 1755 static inline int |
1437 ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
PTPCanon_changes_entry **ce) | 1756 ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
PTPCanon_changes_entry **pce) |
1438 { | 1757 { |
1439 int i = 0, entries = 0; | 1758 int i = 0, entries = 0; |
1440 unsigned char *curdata = data; | 1759 unsigned char *curdata = data; |
| 1760 PTPCanon_changes_entry *ce; |
1441 | 1761 |
1442 if (data==NULL) | 1762 if (data==NULL) |
1443 return 0; | 1763 return 0; |
1444 while (curdata - data < datasize) { | 1764 while (curdata - data < datasize) { |
1445 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); | 1765 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); |
1446 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); | 1766 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); |
1447 | 1767 |
1448 curdata += size; | |
1449 if ((size == 8) && (type == 0)) | 1768 if ((size == 8) && (type == 0)) |
1450 break; | 1769 break; |
| 1770 if (type == PTP_EC_CANON_EOS_OLCInfoChanged) { |
| 1771 unsigned int j; |
| 1772 |
| 1773 for (j=0;j<31;j++) |
| 1774 if (dtoh32a(curdata+12) & (1<<j)) |
| 1775 entries++; |
| 1776 } |
| 1777 curdata += size; |
1451 entries++; | 1778 entries++; |
1452 } | 1779 } |
1453 » *ce = malloc (sizeof(PTPCanon_changes_entry)*(entries+1)); | 1780 » ce = malloc (sizeof(PTPCanon_changes_entry)*(entries+1)); |
1454 » if (!*ce) return 0; | 1781 » if (!ce) return 0; |
1455 | 1782 |
1456 curdata = data; | 1783 curdata = data; |
1457 while (curdata - data < datasize) { | 1784 while (curdata - data < datasize) { |
1458 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); | 1785 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); |
1459 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); | 1786 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); |
1460 | 1787 |
1461 » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; | 1788 » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
1462 » » (*ce)[i].u.info = NULL; | 1789 » » ce[i].u.info = NULL; |
1463 switch (type) { | 1790 switch (type) { |
1464 case PTP_EC_CANON_EOS_ObjectAddedEx: | 1791 case PTP_EC_CANON_EOS_ObjectAddedEx: |
1465 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO; | 1792 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO; |
1466 » » » (*ce)[i].u.object.oid » » = dtoh32a(&curda
ta[PTP_ece_OA_ObjectID]); | 1793 » » » ce[i].u.object.oid » » = dtoh32a(&curdata[PTP_e
ce_OA_ObjectID]); |
1467 » » » (*ce)[i].u.object.oi.StorageID »» = dtoh32a(&curda
ta[PTP_ece_OA_StorageID]); | 1794 » » » ce[i].u.object.oi.StorageID » » = dtoh32a(&curda
ta[PTP_ece_OA_StorageID]); |
1468 » » » (*ce)[i].u.object.oi.ParentObject» = dtoh32a(&curda
ta[PTP_ece_OA_Parent]); | 1795 » » » ce[i].u.object.oi.ParentObject» = dtoh32a(&curdata[PTP_e
ce_OA_Parent]); |
1469 » » » (*ce)[i].u.object.oi.ObjectFormat » = dtoh16a(&curda
ta[PTP_ece_OA_OFC]); | 1796 » » » ce[i].u.object.oi.ObjectFormat »= dtoh16a(&curdata[PTP_e
ce_OA_OFC]); |
1470 » » » (*ce)[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curd
ata[PTP_ece_OA_Size]); | 1797 » » » ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata
[PTP_ece_OA_Size]); |
1471 » » » (*ce)[i].u.object.oi.Filename » » = strdup(((char*
)&curdata[PTP_ece_OA_Name])); | 1798 » » » ce[i].u.object.oi.Filename » » = strdup(((char*
)&curdata[PTP_ece_OA_Name])); |
1472 » » » 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.obje
ct.oi.ObjectCompressedSize, (*ce)[i].u.object.oi.Filename); | 1799 » » » 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.Object
CompressedSize, ce[i].u.object.oi.Filename); |
1473 break; | 1800 break; |
1474 case PTP_EC_CANON_EOS_RequestObjectTransfer: | 1801 case PTP_EC_CANON_EOS_RequestObjectTransfer: |
1475 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFE
R; | 1802 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER; |
1476 » » » (*ce)[i].u.object.oid » » = dtoh32a(&curda
ta[PTP_ece_OI_ObjectID]); | 1803 » » » ce[i].u.object.oid » » = dtoh32a(&curdata[PTP_e
ce_OI_ObjectID]); |
1477 » » » (*ce)[i].u.object.oi.StorageID »» = 0; /* use as m
arker */ | 1804 » » » ce[i].u.object.oi.StorageID » » = 0; /* use as m
arker */ |
1478 » » » (*ce)[i].u.object.oi.ObjectFormat » = dtoh16a(&curda
ta[PTP_ece_OI_OFC]); | 1805 » » » ce[i].u.object.oi.ObjectFormat »= dtoh16a(&curdata[PTP_e
ce_OI_OFC]); |
1479 » » » (*ce)[i].u.object.oi.ParentObject» = 0; /* check, b
ut use as marker */ | 1806 » » » ce[i].u.object.oi.ParentObject» = 0; /* check, but use a
s marker */ |
1480 » » » (*ce)[i].u.object.oi.ObjectCompressedSize = dtoh32a(&cur
data[PTP_ece_OI_Size]); | 1807 » » » ce[i].u.object.oi.ObjectCompressedSize = dtoh32a(&curdat
a[PTP_ece_OI_Size]); |
1481 » » » (*ce)[i].u.object.oi.Filename » » = strdup(((char*
)&curdata[PTP_ece_OI_Name])); | 1808 » » » ce[i].u.object.oi.Filename » » = strdup(((char*
)&curdata[PTP_ece_OI_Name])); |
1482 | 1809 |
1483 » » » ptp_debug (params, "event %d: request object transfer oi
d %08lx, ofc %04x, size %d, filename %s", i, (*ce)[i].u.object.oid, (*ce)[i].u.o
bject.oi.ObjectFormat, (*ce)[i].u.object.oi.ObjectCompressedSize, (*ce)[i].u.obj
ect.oi.Filename); | 1810 » » » ptp_debug (params, "event %d: request object transfer oi
d %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.Filen
ame); |
1484 break; | 1811 break; |
1485 case PTP_EC_CANON_EOS_AvailListChanged: { /* property desc
*/ | 1812 case PTP_EC_CANON_EOS_AvailListChanged: { /* property desc
*/ |
1486 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop
_Subtype]); | 1813 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop
_Subtype]); |
1487 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Pro
p_Desc_Type]); | 1814 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Pro
p_Desc_Type]); |
1488 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop
_Desc_Count]); | 1815 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop
_Desc_Count]); |
1489 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data
]; | 1816 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data
]; |
1490 » » » int» » j; | 1817 » » » unsigned int» j; |
1491 PTPDevicePropDesc *dpd; | 1818 PTPDevicePropDesc *dpd; |
1492 | 1819 |
1493 ptp_debug (params, "event %d: EOS prop %04x desc record,
datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype
); | 1820 ptp_debug (params, "event %d: EOS prop %04x desc record,
datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype
); |
1494 for (j=0;j<params->nrofcanon_props;j++) | 1821 for (j=0;j<params->nrofcanon_props;j++) |
1495 if (params->canon_props[j].proptype == proptype) | 1822 if (params->canon_props[j].proptype == proptype) |
1496 break; | 1823 break; |
1497 if (j==params->nrofcanon_props) { | 1824 if (j==params->nrofcanon_props) { |
1498 ptp_debug (params, "event %d: propdesc %x, defau
lt value not found.", i, proptype); | 1825 ptp_debug (params, "event %d: propdesc %x, defau
lt value not found.", i, proptype); |
1499 break; | 1826 break; |
1500 } | 1827 } |
1501 dpd = ¶ms->canon_props[j].dpd; | 1828 dpd = ¶ms->canon_props[j].dpd; |
1502 /* 1 - uint16 ? | 1829 /* 1 - uint16 ? |
1503 * 3 - uint16 | 1830 * 3 - uint16 |
1504 * 7 - string? | 1831 * 7 - string? |
1505 */ | 1832 */ |
1506 if (propxtype != 3) { | 1833 if (propxtype != 3) { |
1507 ptp_debug (params, "event %d: propxtype is %x fo
r %04x, unhandled.", i, propxtype, proptype); | 1834 ptp_debug (params, "event %d: propxtype is %x fo
r %04x, unhandled.", i, propxtype, proptype); |
1508 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++) | 1835 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++) |
1509 ptp_debug (params, " %d: %02x", j, xd
ata[j]); | 1836 ptp_debug (params, " %d: %02x", j, xd
ata[j]); |
1510 break; | 1837 break; |
1511 } | 1838 } |
1512 if (! propxcnt) | 1839 if (! propxcnt) |
1513 break; | 1840 break; |
| 1841 if (propxcnt >= 2<<16) /* buggy or exploit */ |
| 1842 break; |
1514 | 1843 |
1515 ptp_debug (params, "event %d: propxtype is %x, prop is 0
x%04x, data type is 0x%04x, propxcnt is %d.", | 1844 ptp_debug (params, "event %d: propxtype is %x, prop is 0
x%04x, data type is 0x%04x, propxcnt is %d.", |
1516 i, propxtype, proptype, dpd->DataType, propxc
nt); | 1845 i, propxtype, proptype, dpd->DataType, propxc
nt); |
1517 dpd->FormFlag = PTP_DPFF_Enumeration; | 1846 dpd->FormFlag = PTP_DPFF_Enumeration; |
1518 dpd->FORM.Enum.NumberOfValues = propxcnt; | 1847 dpd->FORM.Enum.NumberOfValues = propxcnt; |
1519 » » » if (dpd->FORM.Enum.SupportedValue) free (dpd->FORM.Enum.
SupportedValue); | 1848 » » » free (dpd->FORM.Enum.SupportedValue); |
1520 dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPrope
rtyValue)*propxcnt); | 1849 dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPrope
rtyValue)*propxcnt); |
1521 | 1850 |
1522 switch (proptype) { | 1851 switch (proptype) { |
1523 case PTP_DPC_CANON_EOS_ImageFormat: | 1852 case PTP_DPC_CANON_EOS_ImageFormat: |
1524 case PTP_DPC_CANON_EOS_ImageFormatCF: | 1853 case PTP_DPC_CANON_EOS_ImageFormatCF: |
1525 case PTP_DPC_CANON_EOS_ImageFormatSD: | 1854 case PTP_DPC_CANON_EOS_ImageFormatSD: |
1526 case PTP_DPC_CANON_EOS_ImageFormatExtHD: | 1855 case PTP_DPC_CANON_EOS_ImageFormatExtHD: |
1527 /* special handling of ImageFormat properties */ | 1856 /* special handling of ImageFormat properties */ |
1528 for (j=0;j<propxcnt;j++) { | 1857 for (j=0;j<propxcnt;j++) { |
1529 dpd->FORM.Enum.SupportedValue[j].u16 = | 1858 dpd->FORM.Enum.SupportedValue[j].u16 = |
1530 » » » » » » » dtoh16( ptp_unpack_EOS_I
mageFormat( params, &xdata ) ); | 1859 » » » » » » » ptp_unpack_EOS_ImageForm
at( params, &xdata ); |
1531 ptp_debug (params, "event %d: suppval[%d
] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16); | 1860 ptp_debug (params, "event %d: suppval[%d
] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16); |
1532 } | 1861 } |
1533 break; | 1862 break; |
1534 default: | 1863 default: |
1535 /* 'normal' enumerated types */ | 1864 /* 'normal' enumerated types */ |
1536 switch (dpd->DataType) { | 1865 switch (dpd->DataType) { |
1537 #define XX( TYPE, CONV )\ | 1866 #define XX( TYPE, CONV )\ |
1538 for (j=0;j<propxcnt;j++) { \ | 1867 for (j=0;j<propxcnt;j++) { \ |
1539 dpd->FORM.Enum.SupportedValue[j]
.TYPE = CONV(xdata); \ | 1868 dpd->FORM.Enum.SupportedValue[j]
.TYPE = CONV(xdata); \ |
1540 ptp_debug (params, "event %d: su
ppval[%d] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \ | 1869 ptp_debug (params, "event %d: su
ppval[%d] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \ |
(...skipping 10 matching lines...) Expand all Loading... |
1551 ptp_debug (params ,"event %d: data type
0x%04x of %x unhandled, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata)
); | 1880 ptp_debug (params ,"event %d: data type
0x%04x of %x unhandled, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata)
); |
1552 for (j=0;j<(size-PTP_ece_Prop_Desc_Data)
/4;j++, xdata+=4) /* 4 is good for propxtype 3 */ | 1881 for (j=0;j<(size-PTP_ece_Prop_Desc_Data)
/4;j++, xdata+=4) /* 4 is good for propxtype 3 */ |
1553 ptp_debug (params, " %3d: 0x%
8x", j, dtoh32a(xdata)); | 1882 ptp_debug (params, " %3d: 0x%
8x", j, dtoh32a(xdata)); |
1554 break; | 1883 break; |
1555 } | 1884 } |
1556 } | 1885 } |
1557 break; | 1886 break; |
1558 } | 1887 } |
1559 case PTP_EC_CANON_EOS_PropValueChanged: | 1888 case PTP_EC_CANON_EOS_PropValueChanged: |
1560 if (size >= 0xc) { /* property info */ | 1889 if (size >= 0xc) { /* property info */ |
1561 » » » » int j; | 1890 » » » » unsigned int j; |
1562 uint32_t proptype = dtoh32a(&curdata[PTP_
ece_Prop_Subtype]); | 1891 uint32_t proptype = dtoh32a(&curdata[PTP_
ece_Prop_Subtype]); |
1563 unsigned char *xdata = &curdata[PTP_ece_Prop_V
al_Data]; | 1892 unsigned char *xdata = &curdata[PTP_ece_Prop_V
al_Data]; |
1564 PTPDevicePropDesc *dpd; | 1893 PTPDevicePropDesc *dpd; |
1565 | 1894 |
1566 ptp_debug (params, "event %d: EOS prop %04x info
record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data); | 1895 ptp_debug (params, "event %d: EOS prop %04x info
record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data); |
1567 for (j=0;j<params->nrofcanon_props;j++) | 1896 for (j=0;j<params->nrofcanon_props;j++) |
1568 if (params->canon_props[j].proptype == p
roptype) | 1897 if (params->canon_props[j].proptype == p
roptype) |
1569 break; | 1898 break; |
1570 if (j<params->nrofcanon_props) { | 1899 if (j<params->nrofcanon_props) { |
1571 if ( (params->canon_props[j].size !=
size) || | 1900 if ( (params->canon_props[j].size !=
size) || |
1572 (memcmp(params->canon_props[j].d
ata,xdata,size-PTP_ece_Prop_Val_Data))) { | 1901 (memcmp(params->canon_props[j].d
ata,xdata,size-PTP_ece_Prop_Val_Data))) { |
1573 params->canon_props[j].data = re
alloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data); | 1902 params->canon_props[j].data = re
alloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data); |
1574 memcpy (params->canon_props[j].d
ata,xdata,size-PTP_ece_Prop_Val_Data); | 1903 memcpy (params->canon_props[j].d
ata,xdata,size-PTP_ece_Prop_Val_Data); |
1575 } | 1904 } |
1576 } else { | 1905 } else { |
1577 if (j) | 1906 if (j) |
1578 params->canon_props = realloc(pa
rams->canon_props, sizeof(params->canon_props[0])*(j+1)); | 1907 params->canon_props = realloc(pa
rams->canon_props, sizeof(params->canon_props[0])*(j+1)); |
1579 else | 1908 else |
1580 params->canon_props = malloc(siz
eof(params->canon_props[0])); | 1909 params->canon_props = malloc(siz
eof(params->canon_props[0])); |
1581 params->canon_props[j].type = type; | |
1582 params->canon_props[j].proptype = propty
pe; | 1910 params->canon_props[j].proptype = propty
pe; |
1583 params->canon_props[j].size = size; | 1911 params->canon_props[j].size = size; |
1584 params->canon_props[j].data = malloc(siz
e-PTP_ece_Prop_Val_Data); | 1912 params->canon_props[j].data = malloc(siz
e-PTP_ece_Prop_Val_Data); |
1585 memcpy(params->canon_props[j].data, xdat
a, size-PTP_ece_Prop_Val_Data); | 1913 memcpy(params->canon_props[j].data, xdat
a, size-PTP_ece_Prop_Val_Data); |
1586 memset (¶ms->canon_props[j].dpd,0,si
zeof(params->canon_props[j].dpd)); | 1914 memset (¶ms->canon_props[j].dpd,0,si
zeof(params->canon_props[j].dpd)); |
1587 params->canon_props[j].dpd.GetSet = 1; | 1915 params->canon_props[j].dpd.GetSet = 1; |
1588 params->canon_props[j].dpd.FormFlag = PT
P_DPFF_None; | 1916 params->canon_props[j].dpd.FormFlag = PT
P_DPFF_None; |
1589 params->nrofcanon_props = j+1; | 1917 params->nrofcanon_props = j+1; |
1590 } | 1918 } |
1591 dpd = ¶ms->canon_props[j].dpd; | 1919 dpd = ¶ms->canon_props[j].dpd; |
1592 | 1920 |
1593 » » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPE
RTY; | 1921 » » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY
; |
1594 » » » » (*ce)[i].u.propid = proptype; | 1922 » » » » ce[i].u.propid = proptype; |
1595 | 1923 |
1596 /* fix GetSet value */ | 1924 /* fix GetSet value */ |
1597 switch (proptype) { | 1925 switch (proptype) { |
1598 #define XX(x) case PTP_DPC_CANON_##x: | 1926 #define XX(x) case PTP_DPC_CANON_##x: |
1599 XX(EOS_FocusMode) | 1927 XX(EOS_FocusMode) |
1600 XX(EOS_BatteryPower) | 1928 XX(EOS_BatteryPower) |
1601 XX(EOS_BatterySelect) | 1929 XX(EOS_BatterySelect) |
1602 XX(EOS_ModelID) | 1930 XX(EOS_ModelID) |
1603 XX(EOS_PTPExtensionVersion) | 1931 XX(EOS_PTPExtensionVersion) |
1604 XX(EOS_DPOFVersion) | 1932 XX(EOS_DPOFVersion) |
(...skipping 20 matching lines...) Expand all Loading... |
1625 XX(EOS_LensName) | 1953 XX(EOS_LensName) |
1626 XX(EOS_LensID) | 1954 XX(EOS_LensID) |
1627 #undef XX | 1955 #undef XX |
1628 dpd->GetSet = PTP_DPGS_Get; | 1956 dpd->GetSet = PTP_DPGS_Get; |
1629 break; | 1957 break; |
1630 } | 1958 } |
1631 | 1959 |
1632 /* set DataType */ | 1960 /* set DataType */ |
1633 switch (proptype) { | 1961 switch (proptype) { |
1634 case PTP_DPC_CANON_EOS_CameraTime: | 1962 case PTP_DPC_CANON_EOS_CameraTime: |
| 1963 case PTP_DPC_CANON_EOS_UTCTime: |
| 1964 case PTP_DPC_CANON_EOS_Summertime: /* basical th
e DST flag */ |
1635 case PTP_DPC_CANON_EOS_AvailableShots: | 1965 case PTP_DPC_CANON_EOS_AvailableShots: |
1636 case PTP_DPC_CANON_EOS_CaptureDestination: | 1966 case PTP_DPC_CANON_EOS_CaptureDestination: |
1637 case PTP_DPC_CANON_EOS_WhiteBalanceXA: | 1967 case PTP_DPC_CANON_EOS_WhiteBalanceXA: |
1638 case PTP_DPC_CANON_EOS_WhiteBalanceXB: | 1968 case PTP_DPC_CANON_EOS_WhiteBalanceXB: |
1639 case PTP_DPC_CANON_EOS_CurrentStorage: | 1969 case PTP_DPC_CANON_EOS_CurrentStorage: |
1640 case PTP_DPC_CANON_EOS_CurrentFolder: | 1970 case PTP_DPC_CANON_EOS_CurrentFolder: |
1641 case PTP_DPC_CANON_EOS_ShutterCounter: | 1971 case PTP_DPC_CANON_EOS_ShutterCounter: |
1642 case PTP_DPC_CANON_EOS_ModelID: | 1972 case PTP_DPC_CANON_EOS_ModelID: |
1643 case PTP_DPC_CANON_EOS_LensID: | 1973 case PTP_DPC_CANON_EOS_LensID: |
1644 case PTP_DPC_CANON_EOS_StroboFiring: | 1974 case PTP_DPC_CANON_EOS_StroboFiring: |
| 1975 case PTP_DPC_CANON_EOS_AFSelectFocusArea: |
| 1976 case PTP_DPC_CANON_EOS_ContinousAFMode: |
1645 dpd->DataType = PTP_DTC_UINT32; | 1977 dpd->DataType = PTP_DTC_UINT32; |
1646 break; | 1978 break; |
1647 /* enumeration for AEM is never provided, but is
available to set */ | 1979 /* enumeration for AEM is never provided, but is
available to set */ |
1648 case PTP_DPC_CANON_EOS_AutoExposureMode: | 1980 case PTP_DPC_CANON_EOS_AutoExposureMode: |
1649 dpd->DataType = PTP_DTC_UINT16; | 1981 dpd->DataType = PTP_DTC_UINT16; |
1650 dpd->FormFlag = PTP_DPFF_Enumeration; | 1982 dpd->FormFlag = PTP_DPFF_Enumeration; |
1651 dpd->FORM.Enum.NumberOfValues = 0; | 1983 dpd->FORM.Enum.NumberOfValues = 0; |
1652 break; | 1984 break; |
1653 case PTP_DPC_CANON_EOS_Aperture: | 1985 case PTP_DPC_CANON_EOS_Aperture: |
1654 case PTP_DPC_CANON_EOS_ShutterSpeed: | 1986 case PTP_DPC_CANON_EOS_ShutterSpeed: |
1655 case PTP_DPC_CANON_EOS_ISOSpeed: | 1987 case PTP_DPC_CANON_EOS_ISOSpeed: |
1656 case PTP_DPC_CANON_EOS_FocusMode: | 1988 case PTP_DPC_CANON_EOS_FocusMode: |
1657 case PTP_DPC_CANON_EOS_ColorSpace: | 1989 case PTP_DPC_CANON_EOS_ColorSpace: |
1658 case PTP_DPC_CANON_EOS_BatteryPower: | 1990 case PTP_DPC_CANON_EOS_BatteryPower: |
1659 case PTP_DPC_CANON_EOS_BatterySelect: | 1991 case PTP_DPC_CANON_EOS_BatterySelect: |
1660 case PTP_DPC_CANON_EOS_PTPExtensionVersion: | 1992 case PTP_DPC_CANON_EOS_PTPExtensionVersion: |
1661 case PTP_DPC_CANON_EOS_DriveMode: | 1993 case PTP_DPC_CANON_EOS_DriveMode: |
1662 case PTP_DPC_CANON_EOS_AEB: | 1994 case PTP_DPC_CANON_EOS_AEB: |
1663 case PTP_DPC_CANON_EOS_BracketMode: | 1995 case PTP_DPC_CANON_EOS_BracketMode: |
1664 case PTP_DPC_CANON_EOS_QuickReviewTime: | 1996 case PTP_DPC_CANON_EOS_QuickReviewTime: |
1665 case PTP_DPC_CANON_EOS_EVFMode: | 1997 case PTP_DPC_CANON_EOS_EVFMode: |
1666 case PTP_DPC_CANON_EOS_EVFOutputDevice: | 1998 case PTP_DPC_CANON_EOS_EVFOutputDevice: |
| 1999 case PTP_DPC_CANON_EOS_AutoPowerOff: |
| 2000 case PTP_DPC_CANON_EOS_EVFRecordStatus: |
1667 dpd->DataType = PTP_DTC_UINT16; | 2001 dpd->DataType = PTP_DTC_UINT16; |
1668 break; | 2002 break; |
1669 case PTP_DPC_CANON_EOS_PictureStyle: | 2003 case PTP_DPC_CANON_EOS_PictureStyle: |
1670 case PTP_DPC_CANON_EOS_WhiteBalance: | 2004 case PTP_DPC_CANON_EOS_WhiteBalance: |
1671 case PTP_DPC_CANON_EOS_MeteringMode: | 2005 case PTP_DPC_CANON_EOS_MeteringMode: |
1672 » » » » case PTP_DPC_CANON_EOS_ExpCompensation: /* actua
lly int8 if you calculate */ | 2006 » » » » case PTP_DPC_CANON_EOS_ExpCompensation: |
1673 dpd->DataType = PTP_DTC_UINT8; | 2007 dpd->DataType = PTP_DTC_UINT8; |
1674 break; | 2008 break; |
1675 case PTP_DPC_CANON_EOS_Owner: | 2009 case PTP_DPC_CANON_EOS_Owner: |
1676 case PTP_DPC_CANON_EOS_Artist: | 2010 case PTP_DPC_CANON_EOS_Artist: |
1677 case PTP_DPC_CANON_EOS_Copyright: | 2011 case PTP_DPC_CANON_EOS_Copyright: |
1678 case PTP_DPC_CANON_EOS_SerialNumber: | 2012 case PTP_DPC_CANON_EOS_SerialNumber: |
1679 case PTP_DPC_CANON_EOS_LensName: | 2013 case PTP_DPC_CANON_EOS_LensName: |
1680 dpd->DataType = PTP_DTC_STR; | 2014 dpd->DataType = PTP_DTC_STR; |
1681 break; | 2015 break; |
1682 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA: | 2016 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA: |
1683 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB: | 2017 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB: |
1684 dpd->DataType = PTP_DTC_INT16; | 2018 dpd->DataType = PTP_DTC_INT16; |
1685 break; | 2019 break; |
1686 /* unknown props, listed from dump.... all 16 bi
t, but vals might be smaller */ | 2020 /* unknown props, listed from dump.... all 16 bi
t, but vals might be smaller */ |
1687 case 0xd114: | |
1688 case PTP_DPC_CANON_EOS_DPOFVersion: | 2021 case PTP_DPC_CANON_EOS_DPOFVersion: |
1689 dpd->DataType = PTP_DTC_UINT16; | 2022 dpd->DataType = PTP_DTC_UINT16; |
1690 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d, using uint16", i ,proptype, size-PTP_ece_Prop_V
al_Data); | 2023 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d, using uint16", i ,proptype, size-PTP_ece_Prop_V
al_Data); |
1691 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+
+) | 2024 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+
+) |
1692 ptp_debug (params, " %d: %02x
", j, xdata[j]); | 2025 ptp_debug (params, " %d: %02x
", j, xdata[j]); |
1693 break; | 2026 break; |
1694 case PTP_DPC_CANON_EOS_CustomFunc1: | 2027 case PTP_DPC_CANON_EOS_CustomFunc1: |
1695 case PTP_DPC_CANON_EOS_CustomFunc2: | 2028 case PTP_DPC_CANON_EOS_CustomFunc2: |
1696 case PTP_DPC_CANON_EOS_CustomFunc3: | 2029 case PTP_DPC_CANON_EOS_CustomFunc3: |
1697 case PTP_DPC_CANON_EOS_CustomFunc4: | 2030 case PTP_DPC_CANON_EOS_CustomFunc4: |
(...skipping 16 matching lines...) Expand all Loading... |
1714 case PTP_DPC_CANON_EOS_WftStatus: | 2047 case PTP_DPC_CANON_EOS_WftStatus: |
1715 case PTP_DPC_CANON_EOS_LensStatus: | 2048 case PTP_DPC_CANON_EOS_LensStatus: |
1716 case PTP_DPC_CANON_EOS_CardExtension: | 2049 case PTP_DPC_CANON_EOS_CardExtension: |
1717 case PTP_DPC_CANON_EOS_TempStatus: | 2050 case PTP_DPC_CANON_EOS_TempStatus: |
1718 case PTP_DPC_CANON_EOS_PhotoStudioMode: | 2051 case PTP_DPC_CANON_EOS_PhotoStudioMode: |
1719 case PTP_DPC_CANON_EOS_DepthOfFieldPreview: | 2052 case PTP_DPC_CANON_EOS_DepthOfFieldPreview: |
1720 case PTP_DPC_CANON_EOS_EVFSharpness: | 2053 case PTP_DPC_CANON_EOS_EVFSharpness: |
1721 case PTP_DPC_CANON_EOS_EVFWBMode: | 2054 case PTP_DPC_CANON_EOS_EVFWBMode: |
1722 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs: | 2055 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs: |
1723 case PTP_DPC_CANON_EOS_EVFColorTemp: | 2056 case PTP_DPC_CANON_EOS_EVFColorTemp: |
1724 case PTP_DPC_CANON_EOS_EVFRecordStatus: | |
1725 case PTP_DPC_CANON_EOS_ExposureSimMode: | 2057 case PTP_DPC_CANON_EOS_ExposureSimMode: |
1726 case PTP_DPC_CANON_EOS_LvAfSystem: | 2058 case PTP_DPC_CANON_EOS_LvAfSystem: |
1727 case PTP_DPC_CANON_EOS_MovSize: | 2059 case PTP_DPC_CANON_EOS_MovSize: |
1728 case PTP_DPC_CANON_EOS_DepthOfField: | 2060 case PTP_DPC_CANON_EOS_DepthOfField: |
1729 case PTP_DPC_CANON_EOS_LvViewTypeSelect: | 2061 case PTP_DPC_CANON_EOS_LvViewTypeSelect: |
| 2062 case PTP_DPC_CANON_EOS_AloMode: |
| 2063 case PTP_DPC_CANON_EOS_Brightness: |
1730 dpd->DataType = PTP_DTC_UINT32; | 2064 dpd->DataType = PTP_DTC_UINT32; |
1731 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_V
al_Data); | 2065 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d, using uint32", i ,proptype, size-PTP_ece_Prop_V
al_Data); |
1732 if ((size-PTP_ece_Prop_Val_Data) % sizeo
f(uint32_t) != 0) | 2066 if ((size-PTP_ece_Prop_Val_Data) % sizeo
f(uint32_t) != 0) |
1733 ptp_debug (params, "event %d: Wa
rning: datasize modulo sizeof(uint32) is not 0: ", i, (size-PTP_ece_Prop_Val_Dat
a) % sizeof(uint32_t) ); | 2067 ptp_debug (params, "event %d: Wa
rning: datasize modulo sizeof(uint32) is not 0: ", i, (size-PTP_ece_Prop_Val_Dat
a) % sizeof(uint32_t) ); |
1734 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/
sizeof(uint32_t);j++) | 2068 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/
sizeof(uint32_t);j++) |
1735 » » » » » » ptp_debug (params, " %d: 0x%8
x", j, ((uint32_t*)xdata)[j]); | 2069 » » » » » » ptp_debug (params, " %d: 0x%8
x", j, dtoh32a(xdata+j*4)); |
1736 break; | 2070 break; |
1737 /* ImageFormat properties have to be ignored her
e, see special handling below */ | 2071 /* ImageFormat properties have to be ignored her
e, see special handling below */ |
1738 case PTP_DPC_CANON_EOS_ImageFormat: | 2072 case PTP_DPC_CANON_EOS_ImageFormat: |
1739 case PTP_DPC_CANON_EOS_ImageFormatCF: | 2073 case PTP_DPC_CANON_EOS_ImageFormatCF: |
1740 case PTP_DPC_CANON_EOS_ImageFormatSD: | 2074 case PTP_DPC_CANON_EOS_ImageFormatSD: |
1741 case PTP_DPC_CANON_EOS_ImageFormatExtHD: | 2075 case PTP_DPC_CANON_EOS_ImageFormatExtHD: |
1742 case PTP_DPC_CANON_EOS_CustomFuncEx: | 2076 case PTP_DPC_CANON_EOS_CustomFuncEx: |
| 2077 case PTP_DPC_CANON_EOS_FocusInfoEx: |
1743 break; | 2078 break; |
1744 default: | 2079 default: |
1745 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data); | 2080 ptp_debug (params, "event %d: Unknown EO
S property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data); |
1746 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+
+) | 2081 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+
+) |
1747 ptp_debug (params, " %d: %02x
", j, xdata[j]); | 2082 ptp_debug (params, " %d: %02x
", j, xdata[j]); |
1748 break; | 2083 break; |
1749 } | 2084 } |
1750 switch (dpd->DataType) { | 2085 switch (dpd->DataType) { |
1751 case PTP_DTC_UINT32: | 2086 case PTP_DTC_UINT32: |
1752 dpd->FactoryDefaultValue.u32 = dtoh32
a(xdata); | 2087 dpd->FactoryDefaultValue.u32 = dtoh32
a(xdata); |
1753 dpd->CurrentValue.u32 = dtoh32
a(xdata); | 2088 dpd->CurrentValue.u32 = dtoh32
a(xdata); |
1754 ptp_debug (params ,"event %d: currentval
ue of %x is %x", i, proptype, dpd->CurrentValue.u32); | 2089 ptp_debug (params ,"event %d: currentval
ue of %x is %x", i, proptype, dpd->CurrentValue.u32); |
1755 break; | 2090 break; |
| 2091 case PTP_DTC_INT16: |
| 2092 dpd->FactoryDefaultValue.i16 = dtoh16
a(xdata); |
| 2093 dpd->CurrentValue.i16 = dtoh16
a(xdata); |
| 2094 ptp_debug (params,"event %d: currentvalu
e of %x is %d", i, proptype, dpd->CurrentValue.i16); |
| 2095 break; |
1756 case PTP_DTC_UINT16: | 2096 case PTP_DTC_UINT16: |
1757 dpd->FactoryDefaultValue.u16 = dtoh16
a(xdata); | 2097 dpd->FactoryDefaultValue.u16 = dtoh16
a(xdata); |
1758 dpd->CurrentValue.u16 = dtoh16
a(xdata); | 2098 dpd->CurrentValue.u16 = dtoh16
a(xdata); |
1759 ptp_debug (params,"event %d: currentvalu
e of %x is %x", i, proptype, dpd->CurrentValue.u16); | 2099 ptp_debug (params,"event %d: currentvalu
e of %x is %x", i, proptype, dpd->CurrentValue.u16); |
1760 break; | 2100 break; |
1761 case PTP_DTC_UINT8: | 2101 case PTP_DTC_UINT8: |
1762 dpd->FactoryDefaultValue.u8 = dtoh8a
(xdata); | 2102 dpd->FactoryDefaultValue.u8 = dtoh8a
(xdata); |
1763 dpd->CurrentValue.u8 = dtoh8a
(xdata); | 2103 dpd->CurrentValue.u8 = dtoh8a
(xdata); |
1764 ptp_debug (params,"event %d: currentvalu
e of %x is %x", i, proptype, dpd->CurrentValue.u8); | 2104 ptp_debug (params,"event %d: currentvalu
e of %x is %x", i, proptype, dpd->CurrentValue.u8); |
1765 break; | 2105 break; |
| 2106 case PTP_DTC_INT8: |
| 2107 dpd->FactoryDefaultValue.i8 = dtoh8a
(xdata); |
| 2108 dpd->CurrentValue.i8 = dtoh8a
(xdata); |
| 2109 ptp_debug (params,"event %d: currentvalu
e of %x is %x", i, proptype, dpd->CurrentValue.i8); |
| 2110 break; |
1766 case PTP_DTC_STR: { | 2111 case PTP_DTC_STR: { |
1767 #if 0 /* 5D MII and 400D aktually store plain ASCII in their string properties *
/ | 2112 #if 0 /* 5D MII and 400D aktually store plain ASCII in their string properties *
/ |
1768 uint8_t len = 0; | 2113 uint8_t len = 0; |
1769 dpd->FactoryDefaultValue.str = ptp_un
pack_string(params, data, 0, &len); | 2114 dpd->FactoryDefaultValue.str = ptp_un
pack_string(params, data, 0, &len); |
1770 dpd->CurrentValue.str = ptp_un
pack_string(params, data, 0, &len); | 2115 dpd->CurrentValue.str = ptp_un
pack_string(params, data, 0, &len); |
1771 #else | 2116 #else |
1772 » » » » » if (dpd->FactoryDefaultValue.str) free (
dpd->FactoryDefaultValue.str); | 2117 » » » » » free (dpd->FactoryDefaultValue.str); |
1773 dpd->FactoryDefaultValue.str = strdup
( (char*)xdata ); | 2118 dpd->FactoryDefaultValue.str = strdup
( (char*)xdata ); |
1774 | 2119 |
1775 » » » » » if (dpd->CurrentValue.str) free (dpd->Cu
rrentValue.str); | 2120 » » » » » free (dpd->CurrentValue.str); |
1776 dpd->CurrentValue.str = strdup
( (char*)xdata ); | 2121 dpd->CurrentValue.str = strdup
( (char*)xdata ); |
1777 #endif | 2122 #endif |
1778 ptp_debug (params,"event %d: currentvalu
e of %x is %s", i, proptype, dpd->CurrentValue.str); | 2123 ptp_debug (params,"event %d: currentvalu
e of %x is %s", i, proptype, dpd->CurrentValue.str); |
1779 break; | 2124 break; |
1780 } | 2125 } |
1781 default: | 2126 default: |
1782 /* debug is printed in switch above this
one */ | 2127 /* debug is printed in switch above this
one */ |
1783 break; | 2128 break; |
1784 } | 2129 } |
1785 | 2130 |
1786 /* ImageFormat and customFuncEx special handling
(WARNING: dont move this in front of the dpd->DataType switch!) */ | 2131 /* ImageFormat and customFuncEx special handling
(WARNING: dont move this in front of the dpd->DataType switch!) */ |
1787 switch (proptype) { | 2132 switch (proptype) { |
1788 case PTP_DPC_CANON_EOS_ImageFormat: | 2133 case PTP_DPC_CANON_EOS_ImageFormat: |
1789 case PTP_DPC_CANON_EOS_ImageFormatCF: | 2134 case PTP_DPC_CANON_EOS_ImageFormatCF: |
1790 case PTP_DPC_CANON_EOS_ImageFormatSD: | 2135 case PTP_DPC_CANON_EOS_ImageFormatSD: |
1791 case PTP_DPC_CANON_EOS_ImageFormatExtHD: | 2136 case PTP_DPC_CANON_EOS_ImageFormatExtHD: |
1792 dpd->DataType = PTP_DTC_UINT16; | 2137 dpd->DataType = PTP_DTC_UINT16; |
1793 dpd->FactoryDefaultValue.u16 = ptp_un
pack_EOS_ImageFormat( params, &xdata ); | 2138 dpd->FactoryDefaultValue.u16 = ptp_un
pack_EOS_ImageFormat( params, &xdata ); |
1794 dpd->CurrentValue.u16 = dpd->F
actoryDefaultValue.u16; | 2139 dpd->CurrentValue.u16 = dpd->F
actoryDefaultValue.u16; |
1795 ptp_debug (params,"event %d: decoded ima
geformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16); | 2140 ptp_debug (params,"event %d: decoded ima
geformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16); |
1796 break; | 2141 break; |
1797 case PTP_DPC_CANON_EOS_CustomFuncEx: | 2142 case PTP_DPC_CANON_EOS_CustomFuncEx: |
1798 dpd->DataType = PTP_DTC_STR; | 2143 dpd->DataType = PTP_DTC_STR; |
1799 » » » » » if (dpd->FactoryDefaultValue.str) free (
dpd->FactoryDefaultValue.str); | 2144 » » » » » free (dpd->FactoryDefaultValue.str); |
1800 » » » » » if (dpd->CurrentValue.str)» free (
dpd->CurrentValue.str); | 2145 » » » » » free (dpd->CurrentValue.str); |
1801 » » » » » dpd->FactoryDefaultValue.str» = ptp_un
pack_EOS_CustomFuncEx( params, &data ); | 2146 » » » » » dpd->FactoryDefaultValue.str» = ptp_un
pack_EOS_CustomFuncEx( params, &xdata ); |
1802 dpd->CurrentValue.str = strdup
( (char*)dpd->FactoryDefaultValue.str ); | 2147 dpd->CurrentValue.str = strdup
( (char*)dpd->FactoryDefaultValue.str ); |
1803 ptp_debug (params,"event %d: decoded cus
tom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str); | 2148 ptp_debug (params,"event %d: decoded cus
tom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str); |
1804 break; | 2149 break; |
| 2150 case PTP_DPC_CANON_EOS_FocusInfoEx: |
| 2151 dpd->DataType = PTP_DTC_STR; |
| 2152 free (dpd->FactoryDefaultValue.str); |
| 2153 free (dpd->CurrentValue.str); |
| 2154 dpd->FactoryDefaultValue.str = ptp_un
pack_EOS_FocusInfoEx( params, &xdata ); |
| 2155 dpd->CurrentValue.str = strdup
( (char*)dpd->FactoryDefaultValue.str ); |
| 2156 ptp_debug (params,"event %d: decoded foc
us info, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str); |
| 2157 break; |
1805 } | 2158 } |
1806 | 2159 |
1807 break; | 2160 break; |
1808 } | 2161 } |
| 2162 /* one more information record handed to us */ |
| 2163 case PTP_EC_CANON_EOS_OLCInfoChanged: { |
| 2164 uint32_t len, curoff; |
| 2165 uint16_t mask,proptype; |
| 2166 PTPDevicePropDesc *dpd; |
| 2167 |
| 2168 /* unclear what OLC stands for */ |
| 2169 ptp_debug (params, "event %d: EOS event OLCInfoChanged (
size %d)", i, size); |
| 2170 if (size >= 0x8) { /* event info */ |
| 2171 unsigned int k; |
| 2172 for (k=8;k<size;k++) |
| 2173 ptp_debug (params, " %d: %02x", k-8,
curdata[k]); |
| 2174 } |
| 2175 len = dtoh32a(curdata+8); |
| 2176 if (len != size-8) { |
| 2177 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2178 ptp_debug (params, "event %d: size %d, len %d",
i, size, len); |
| 2179 break; |
| 2180 } |
| 2181 mask = dtoh16a(curdata+8+4); |
| 2182 curoff = 8+4+4; |
| 2183 if (mask & CANON_EOS_OLC_BUTTON) { |
| 2184 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2185 ce[i].u.info = malloc(strlen("Button 1234567")); |
| 2186 sprintf(ce[i].u.info, "Button %d", dtoh16a(curd
ata+curoff)); |
| 2187 i++; |
| 2188 curoff += 2; |
| 2189 } |
| 2190 |
| 2191 if (mask & CANON_EOS_OLC_SHUTTERSPEED) { |
| 2192 /* 6 bytes: 01 01 98 10 00 60 */ |
| 2193 /* this seesm to be the shutter speed record */ |
| 2194 proptype = PTP_DPC_CANON_EOS_ShutterSpeed; |
| 2195 dpd = _lookup_or_allocate_canon_prop(params, pro
ptype); |
| 2196 dpd->CurrentValue.u16 = curdata[curoff+5]; /* ju
st use last byte */ |
| 2197 |
| 2198 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY
; |
| 2199 ce[i].u.propid = proptype; |
| 2200 curoff += 6; |
| 2201 i++; |
| 2202 } |
| 2203 if (mask & CANON_EOS_OLC_APERTURE) { |
| 2204 /* 5 bytes: 01 01 5b 30 30 */ |
| 2205 /* this seesm to be the aperture record */ |
| 2206 proptype = PTP_DPC_CANON_EOS_Aperture; |
| 2207 dpd = _lookup_or_allocate_canon_prop(params, pro
ptype); |
| 2208 dpd->CurrentValue.u16 = curdata[curoff+4]; /* ju
st use last byte */ |
| 2209 |
| 2210 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY
; |
| 2211 ce[i].u.propid = proptype; |
| 2212 curoff += 5; |
| 2213 i++; |
| 2214 } |
| 2215 if (mask & CANON_EOS_OLC_ISO) { |
| 2216 /* 5 bytes: 01 01 00 78 */ |
| 2217 /* this seesm to be the aperture record */ |
| 2218 proptype = PTP_DPC_CANON_EOS_ISOSpeed; |
| 2219 dpd = _lookup_or_allocate_canon_prop(params, pro
ptype); |
| 2220 dpd->CurrentValue.u16 = curdata[curoff+3]; /* ju
st use last byte */ |
| 2221 |
| 2222 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY
; |
| 2223 ce[i].u.propid = proptype; |
| 2224 curoff += 4; |
| 2225 i++; |
| 2226 } |
| 2227 if (mask & 0x0010) { |
| 2228 /* mask 0x0010: 4 bytes, 04 00 00 00 observed */ |
| 2229 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2230 ce[i].u.info = malloc(strlen("OLCInfo event 0x00
10 content 01234567")+1); |
| 2231 sprintf(ce[i].u.info,"OLCInfo event 0x0010 conte
nt %02x%02x%02x%02x", |
| 2232 curdata[curoff], |
| 2233 curdata[curoff+1], |
| 2234 curdata[curoff+2], |
| 2235 curdata[curoff+3] |
| 2236 ); |
| 2237 curoff += 4; |
| 2238 i++; |
| 2239 } |
| 2240 if (mask & 0x0020) { |
| 2241 /* mask 0x0020: 6 bytes, 00 00 00 00 00 00 obser
ved */ |
| 2242 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2243 ce[i].u.info = malloc(strlen("OLCInfo event 0x00
20 content 0123456789ab")+1); |
| 2244 sprintf(ce[i].u.info,"OLCInfo event 0x0020 conte
nt %02x%02x%02x%02x%02x%02x", |
| 2245 curdata[curoff], |
| 2246 curdata[curoff+1], |
| 2247 curdata[curoff+2], |
| 2248 curdata[curoff+3], |
| 2249 curdata[curoff+4], |
| 2250 curdata[curoff+5] |
| 2251 ); |
| 2252 curoff += 6; |
| 2253 i++; |
| 2254 } |
| 2255 if (mask & 0x0040) { |
| 2256 int value = (signed char)curdata[curoff+2]; |
| 2257 /* mask 0x0040: 7 bytes, 01 01 00 00 00 00 00 ob
served */ |
| 2258 /* exposure indicator */ |
| 2259 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2260 ce[i].u.info = malloc(strlen("OLCInfo exposure i
ndicator 012345678901234567890123456789abcd")+1); |
| 2261 sprintf(ce[i].u.info,"OLCInfo exposure indicator
%d,%d,%d.%d (%02x%02x%02x%02x)", |
| 2262 curdata[curoff], |
| 2263 curdata[curoff+1], |
| 2264 value/10,abs(value)%10, |
| 2265 curdata[curoff+3], |
| 2266 curdata[curoff+4], |
| 2267 curdata[curoff+5], |
| 2268 curdata[curoff+6] |
| 2269 ); |
| 2270 curoff += 7; |
| 2271 i++; |
| 2272 } |
| 2273 if (mask & 0x0080) { |
| 2274 /* mask 0x0080: 4 bytes, 00 00 00 00 observed */ |
| 2275 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2276 ce[i].u.info = malloc(strlen("OLCInfo event 0x00
80 content 01234567")+1); |
| 2277 sprintf(ce[i].u.info,"OLCInfo event 0x0080 conte
nt %02x%02x%02x%02x", |
| 2278 curdata[curoff], |
| 2279 curdata[curoff+1], |
| 2280 curdata[curoff+2], |
| 2281 curdata[curoff+3] |
| 2282 ); |
| 2283 curoff += 4; |
| 2284 i++; |
| 2285 } |
| 2286 if (mask & 0x0100) { |
| 2287 /* mask 0x0100: 6 bytes, 00 00 00 00 00 00 (befo
re focus) and 00 00 00 00 01 00 (on focus) observed */ |
| 2288 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSINF
O; |
| 2289 ce[i].u.info = malloc(strlen("0123456789ab")+1);
|
| 2290 sprintf(ce[i].u.info,"%02x%02x%02x%02x%02x%02x", |
| 2291 curdata[curoff], |
| 2292 curdata[curoff+1], |
| 2293 curdata[curoff+2], |
| 2294 curdata[curoff+3], |
| 2295 curdata[curoff+4], |
| 2296 curdata[curoff+5] |
| 2297 ); |
| 2298 curoff += 6; |
| 2299 i++; |
| 2300 } |
| 2301 if (mask & 0x0200) { |
| 2302 /* mask 0x0200: 7 bytes, 00 00 00 00 00 00 00 ob
served */ |
| 2303 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_FOCUSMAS
K; |
| 2304 ce[i].u.info = malloc(strlen("0123456789abcd0123
456789abcdef")+1); |
| 2305 sprintf(ce[i].u.info,"%02x%02x%02x%02x%02x%02x%0
2x", |
| 2306 curdata[curoff], |
| 2307 curdata[curoff+1], |
| 2308 curdata[curoff+2], |
| 2309 curdata[curoff+3], |
| 2310 curdata[curoff+4], |
| 2311 curdata[curoff+5], |
| 2312 curdata[curoff+6] |
| 2313 ); |
| 2314 curoff += 7; |
| 2315 i++; |
| 2316 } |
| 2317 if (mask & 0x0400) { |
| 2318 /* mask 0x0400: 7 bytes, 00 00 00 00 00 00 00 ob
served */ |
| 2319 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2320 ce[i].u.info = malloc(strlen("OLCInfo event 0x04
00 content 0123456789abcd")+1); |
| 2321 sprintf(ce[i].u.info,"OLCInfo event 0x0400 conte
nt %02x%02x%02x%02x%02x%02x%02x", |
| 2322 curdata[curoff], |
| 2323 curdata[curoff+1], |
| 2324 curdata[curoff+2], |
| 2325 curdata[curoff+3], |
| 2326 curdata[curoff+4], |
| 2327 curdata[curoff+5], |
| 2328 curdata[curoff+6] |
| 2329 ); |
| 2330 curoff += 7; |
| 2331 i++; |
| 2332 } |
| 2333 if (mask & 0x0800) { |
| 2334 /* mask 0x0800: 8 bytes, 00 00 00 00 00 00 00 00
and 19 01 00 00 00 00 00 00 and others observed */ |
| 2335 /* might be mask of focus points selected */ |
| 2336 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2337 ce[i].u.info = malloc(strlen("OLCInfo event 0x08
00 content 0123456789abcdef")+1); |
| 2338 sprintf(ce[i].u.info,"OLCInfo event 0x0800 conte
nt %02x%02x%02x%02x%02x%02x%02x%02x", |
| 2339 curdata[curoff], |
| 2340 curdata[curoff+1], |
| 2341 curdata[curoff+2], |
| 2342 curdata[curoff+3], |
| 2343 curdata[curoff+4], |
| 2344 curdata[curoff+5], |
| 2345 curdata[curoff+6], |
| 2346 curdata[curoff+7] |
| 2347 ); |
| 2348 curoff += 8; |
| 2349 i++; |
| 2350 } |
| 2351 if (mask & 0x1000) { |
| 2352 /* mask 0x1000: 1 byte, 00 observed */ |
| 2353 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2354 ce[i].u.info = malloc(strlen("OLCInfo event 0x10
00 content 01")+1); |
| 2355 sprintf(ce[i].u.info,"OLCInfo event 0x1000 conte
nt %02x", |
| 2356 curdata[curoff] |
| 2357 ); |
| 2358 curoff += 1; |
| 2359 i++; |
| 2360 } |
| 2361 /* handle more masks */ |
| 2362 ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
| 2363 ce[i].u.info = malloc(strlen("OLCInfo event mask 0123456
789")+1); |
| 2364 sprintf(ce[i].u.info, "OLCInfo event mask=%x", mask); |
| 2365 break; |
| 2366 } |
1809 case PTP_EC_CANON_EOS_CameraStatusChanged: | 2367 case PTP_EC_CANON_EOS_CameraStatusChanged: |
1810 » » » ptp_debug (params, "event %d: EOS event CameraStatusChan
ged (size %d)", i, size); | 2368 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS; |
1811 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS; | 2369 » » » ce[i].u.status = dtoh32a(curdata+8); |
1812 » » » (*ce)[i].u.status = dtoh32a(curdata+8); | 2370 » » » ptp_debug (params, "event %d: EOS event CameraStatusChan
ged (size %d) = %d", i, size, dtoh32a(curdata+8)); |
1813 params->eos_camerastatus = dtoh32a(curdata+8); | 2371 params->eos_camerastatus = dtoh32a(curdata+8); |
1814 break; | 2372 break; |
1815 case 0: /* end marker */ | 2373 case 0: /* end marker */ |
1816 if (size == 8) /* no output */ | 2374 if (size == 8) /* no output */ |
1817 break; | 2375 break; |
1818 ptp_debug (params, "event %d: EOS event 0, but size %d",
i, size); | 2376 ptp_debug (params, "event %d: EOS event 0, but size %d",
i, size); |
1819 break; | 2377 break; |
1820 case PTP_EC_CANON_EOS_BulbExposureTime: | 2378 case PTP_EC_CANON_EOS_BulbExposureTime: |
1821 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; | 2379 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
1822 » » » (*ce)[i].u.info = malloc(strlen("BulbExposureTime 123456
789")); | 2380 » » » ce[i].u.info = malloc(strlen("BulbExposureTime 123456789
")); |
1823 » » » sprintf ((*ce)[i].u.info, "BulbExposureTime %d", dtoh32
a(curdata+8)); | 2381 » » » sprintf (ce[i].u.info, "BulbExposureTime %d", dtoh32a(c
urdata+8)); |
| 2382 » » » break; |
| 2383 » » case PTP_EC_CANON_EOS_ObjectRemoved: |
| 2384 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTREMOVED; |
| 2385 » » » ce[i].u.object.oid = dtoh32a(curdata+8); |
1824 break; | 2386 break; |
1825 default: | 2387 default: |
1826 switch (type) { | 2388 switch (type) { |
1827 #define XX(x) case PTP_EC_CANON_EOS_##x:
\ | 2389 #define XX(x) case PTP_EC_CANON_EOS_##x:
\ |
1828 ptp_debug (params, "event %d: unhandled EOS even
t "#x" (size %d)", i, size); \ | 2390 ptp_debug (params, "event %d: unhandled EOS even
t "#x" (size %d)", i, size); \ |
1829 » » » » (*ce)[i].u.info = malloc(strlen("unhandled EOS e
vent "#x" (size 123456789)"));» \ | 2391 » » » » ce[i].u.info = malloc(strlen("unhandled EOS even
t "#x" (size 123456789)"));» \ |
1830 » » » » sprintf ((*ce)[i].u.info, "unhandled EOS event "
#x" (size %d)", size);»» \ | 2392 » » » » sprintf (ce[i].u.info, "unhandled EOS event "#x"
(size %d)", size);» » \ |
1831 break; | 2393 break; |
1832 XX(RequestGetEvent) | 2394 XX(RequestGetEvent) |
1833 XX(ObjectRemoved) | |
1834 XX(RequestGetObjectInfoEx) | 2395 XX(RequestGetObjectInfoEx) |
1835 XX(StorageStatusChanged) | 2396 XX(StorageStatusChanged) |
1836 XX(StorageInfoChanged) | 2397 XX(StorageInfoChanged) |
1837 XX(ObjectInfoChangedEx) | 2398 XX(ObjectInfoChangedEx) |
1838 XX(ObjectContentChanged) | 2399 XX(ObjectContentChanged) |
1839 XX(WillSoonShutdown) | 2400 XX(WillSoonShutdown) |
1840 XX(ShutdownTimerUpdated) | 2401 XX(ShutdownTimerUpdated) |
1841 XX(RequestCancelTransfer) | 2402 XX(RequestCancelTransfer) |
1842 XX(RequestObjectTransferDT) | 2403 XX(RequestObjectTransferDT) |
1843 XX(RequestCancelTransferDT) | 2404 XX(RequestCancelTransferDT) |
1844 XX(StoreAdded) | 2405 XX(StoreAdded) |
1845 XX(StoreRemoved) | 2406 XX(StoreRemoved) |
1846 XX(BulbExposureTime) | 2407 XX(BulbExposureTime) |
1847 XX(RecordingTime) | 2408 XX(RecordingTime) |
1848 XX(RequestObjectTransferTS) | 2409 XX(RequestObjectTransferTS) |
1849 XX(AfResult) | 2410 XX(AfResult) |
1850 #undef XX | 2411 #undef XX |
1851 default: | 2412 default: |
1852 ptp_debug (params, "event %d: unknown EOS event
%04x", i, type); | 2413 ptp_debug (params, "event %d: unknown EOS event
%04x", i, type); |
1853 break; | 2414 break; |
1854 } | 2415 } |
1855 if (size >= 0x8) { /* event info */ | 2416 if (size >= 0x8) { /* event info */ |
1856 » » » » int j; | 2417 » » » » unsigned int j; |
1857 for (j=8;j<size;j++) | 2418 for (j=8;j<size;j++) |
1858 ptp_debug (params, " %d: %02x", j, cu
rdata[j]); | 2419 ptp_debug (params, " %d: %02x", j, cu
rdata[j]); |
1859 } | 2420 } |
1860 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; | 2421 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; |
1861 break; | 2422 break; |
1862 } | 2423 } |
1863 curdata += size; | 2424 curdata += size; |
1864 i++; | |
1865 if ((size == 8) && (type == 0)) | 2425 if ((size == 8) && (type == 0)) |
1866 break; | 2426 break; |
| 2427 i++; |
1867 } | 2428 } |
1868 » if (!entries) { | 2429 » if (!i) { |
1869 » » free (*ce); | 2430 » » free (ce); |
1870 » » *ce = NULL; | 2431 » » ce = NULL; |
1871 } | 2432 } |
1872 » return entries; | 2433 » *pce = ce; |
| 2434 » return i; |
1873 } | 2435 } |
1874 | 2436 |
1875 /* | 2437 /* |
1876 PTP USB Event container unpack for Nikon events. | 2438 PTP USB Event container unpack for Nikon events. |
1877 */ | 2439 */ |
1878 #define PTP_nikon_ec_Length 0 | 2440 #define PTP_nikon_ec_Length 0 |
1879 #define PTP_nikon_ec_Code 2 | 2441 #define PTP_nikon_ec_Code 2 |
1880 #define PTP_nikon_ec_Param1 4 | 2442 #define PTP_nikon_ec_Param1 4 |
1881 #define PTP_nikon_ec_Size 6 | 2443 #define PTP_nikon_ec_Size 6 |
1882 static inline void | 2444 static inline void |
1883 ptp_unpack_Nikon_EC (PTPParams *params, unsigned char* data, unsigned int len, P
TPContainer **ec, int *cnt) | 2445 ptp_unpack_Nikon_EC (PTPParams *params, unsigned char* data, unsigned int len, P
TPContainer **ec, unsigned int *cnt) |
1884 { | 2446 { |
1885 » int i; | 2447 » unsigned int i; |
1886 | 2448 |
1887 *ec = NULL; | 2449 *ec = NULL; |
1888 if (data == NULL) | 2450 if (data == NULL) |
1889 return; | 2451 return; |
1890 if (len < PTP_nikon_ec_Code) | 2452 if (len < PTP_nikon_ec_Code) |
1891 return; | 2453 return; |
1892 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]); | 2454 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]); |
1893 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) /* broken cnt? */ | 2455 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) /* broken cnt? */ |
1894 return; | 2456 return; |
1895 if (!*cnt) | 2457 if (!*cnt) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 PTPObjectHandles *handles, | 2541 PTPObjectHandles *handles, |
1980 PTPObjectInfo **oinfos, /* size(handles->n) */ | 2542 PTPObjectInfo **oinfos, /* size(handles->n) */ |
1981 uint32_t **flags /* size(handles->n) */ | 2543 uint32_t **flags /* size(handles->n) */ |
1982 ) { | 2544 ) { |
1983 unsigned int i, j, nrofobs = 0, curob = 0; | 2545 unsigned int i, j, nrofobs = 0, curob = 0; |
1984 | 2546 |
1985 #define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff) | 2547 #define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff) |
1986 for (i=0;i<cnt;i++) | 2548 for (i=0;i<cnt;i++) |
1987 if (ISOBJECT(dir+i*0x4c)) nrofobs++; | 2549 if (ISOBJECT(dir+i*0x4c)) nrofobs++; |
1988 handles->n = nrofobs; | 2550 handles->n = nrofobs; |
1989 » handles->Handler = calloc(sizeof(handles->Handler[0]),nrofobs); | 2551 » handles->Handler = calloc(nrofobs,sizeof(handles->Handler[0])); |
1990 if (!handles->Handler) return PTP_RC_GeneralError; | 2552 if (!handles->Handler) return PTP_RC_GeneralError; |
1991 » *oinfos = calloc(sizeof((*oinfos)[0]),nrofobs); | 2553 » *oinfos = calloc(nrofobs,sizeof((*oinfos)[0])); |
1992 if (!*oinfos) return PTP_RC_GeneralError; | 2554 if (!*oinfos) return PTP_RC_GeneralError; |
1993 » *flags = calloc(sizeof((*flags)[0]),nrofobs); | 2555 » *flags = calloc(nrofobs,sizeof((*flags)[0])); |
1994 if (!*flags) return PTP_RC_GeneralError; | 2556 if (!*flags) return PTP_RC_GeneralError; |
1995 | 2557 |
1996 /* Migrate data into objects ids, handles into | 2558 /* Migrate data into objects ids, handles into |
1997 * the object handler array. | 2559 * the object handler array. |
1998 */ | 2560 */ |
1999 curob = 0; | 2561 curob = 0; |
2000 for (i=0;i<cnt;i++) { | 2562 for (i=0;i<cnt;i++) { |
2001 unsigned char *cur = dir+i*0x4c; | 2563 unsigned char *cur = dir+i*0x4c; |
2002 PTPObjectInfo *oi = (*oinfos)+curob; | 2564 PTPObjectInfo *oi = (*oinfos)+curob; |
2003 | 2565 |
(...skipping 20 matching lines...) Expand all Loading... |
2024 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchil
d); | 2586 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchil
d); |
2025 | 2587 |
2026 if (ISOBJECT(cur)) | 2588 if (ISOBJECT(cur)) |
2027 continue; | 2589 continue; |
2028 for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j])
break; | 2590 for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j])
break; |
2029 if (j == handles->n) continue; | 2591 if (j == handles->n) continue; |
2030 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid); | 2592 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid); |
2031 } | 2593 } |
2032 /* Walk over all objects and distribute the storage ids */ | 2594 /* Walk over all objects and distribute the storage ids */ |
2033 while (1) { | 2595 while (1) { |
2034 » » int changed = 0; | 2596 » » unsigned int changed = 0; |
2035 for (i=0;i<cnt;i++) { | 2597 for (i=0;i<cnt;i++) { |
2036 unsigned char *cur = dir+i*0x4c; | 2598 unsigned char *cur = dir+i*0x4c; |
2037 uint32_t oid = dtoh32a(cur + ptp_canon_dir_object
id); | 2599 uint32_t oid = dtoh32a(cur + ptp_canon_dir_object
id); |
2038 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_ne
xtid); | 2600 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_ne
xtid); |
2039 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_
nextchild); | 2601 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_
nextchild); |
2040 uint32_t storageid; | 2602 uint32_t storageid; |
2041 | 2603 |
2042 if (!ISOBJECT(cur)) | 2604 if (!ISOBJECT(cur)) |
2043 continue; | 2605 continue; |
2044 for (j=0;j<handles->n;j++) if (oid == handles->Handler[j
]) break; | 2606 for (j=0;j<handles->n;j++) if (oid == handles->Handler[j
]) break; |
(...skipping 30 matching lines...) Expand all Loading... |
2075 * - changed no entry (nothing more to do) | 2637 * - changed no entry (nothing more to do) |
2076 * - changed all of them at once (usually happens) | 2638 * - changed all of them at once (usually happens) |
2077 * break if we do. | 2639 * break if we do. |
2078 */ | 2640 */ |
2079 if (!changed || (changed==nrofobs-1)) | 2641 if (!changed || (changed==nrofobs-1)) |
2080 break; | 2642 break; |
2081 } | 2643 } |
2082 #undef ISOBJECT | 2644 #undef ISOBJECT |
2083 return PTP_RC_OK; | 2645 return PTP_RC_OK; |
2084 } | 2646 } |
OLD | NEW |