Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/ptp-pack.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ptp.c ('k') | src/util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2014 Marcus Meissner <marcus@jet.franken.de> 4 * Copyright (C) 2003-2012 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., 51 Franklin Street, Fifth Floor, 21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02110-1301 USA 22 * Boston, MA 02111-1307, 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_LIMITS_H 27 #ifdef HAVE_ICONV
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)
34 #include <iconv.h> 28 #include <iconv.h>
35 #endif 29 #endif
36 30
37 static inline uint16_t 31 static inline uint16_t
38 htod16p (PTPParams *params, uint16_t var) 32 htod16p (PTPParams *params, uint16_t var)
39 { 33 {
40 return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var)); 34 return ((params->byteorder==PTP_DL_LE)?htole16(var):htobe16(var));
41 } 35 }
42 36
43 static inline uint32_t 37 static inline uint32_t
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 memcpy(string, &data[offset+1], length * sizeof(string[0])); 139 memcpy(string, &data[offset+1], length * sizeof(string[0]));
146 string[length] = 0x0000U; /* be paranoid! add a terminator. */ 140 string[length] = 0x0000U; /* be paranoid! add a terminator. */
147 loclstr[0] = '\0'; 141 loclstr[0] = '\0';
148 142
149 /* convert from camera UCS-2 to our locale */ 143 /* convert from camera UCS-2 to our locale */
150 src = (char *)string; 144 src = (char *)string;
151 srclen = length * sizeof(string[0]); 145 srclen = length * sizeof(string[0]);
152 dest = loclstr; 146 dest = loclstr;
153 destlen = sizeof(loclstr)-1; 147 destlen = sizeof(loclstr)-1;
154 nconv = (size_t)-1; 148 nconv = (size_t)-1;
155 #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H) 149 #ifdef HAVE_ICONV
156 if (params->cd_ucs2_to_locale != (iconv_t)-1) 150 if (params->cd_ucs2_to_locale != (iconv_t)-1)
157 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, & destlen); 151 nconv = iconv(params->cd_ucs2_to_locale, &src, &srclen, &dest, & destlen);
158 #endif 152 #endif
159 if (nconv == (size_t) -1) { /* do it the hard way */ 153 if (nconv == (size_t) -1) { /* do it the hard way */
160 int i; 154 int i;
161 /* try the old way, in case iconv is broken */ 155 /* try the old way, in case iconv is broken */
162 for (i=0;i<length;i++) { 156 for (i=0;i<length;i++) {
163 if (dtoh16a(&data[offset+1+2*i])>127) 157 if (dtoh16a(&data[offset+1+2*i])>127)
164 loclstr[i] = '?'; 158 loclstr[i] = '?';
165 else 159 else
(...skipping 20 matching lines...) Expand all
186 static inline void 180 static inline void
187 ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o ffset, uint8_t *len) 181 ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o ffset, uint8_t *len)
188 { 182 {
189 int packedlen = 0; 183 int packedlen = 0;
190 uint16_t ucs2str[PTP_MAXSTRLEN+1]; 184 uint16_t ucs2str[PTP_MAXSTRLEN+1];
191 char *ucs2strp = (char *) ucs2str; 185 char *ucs2strp = (char *) ucs2str;
192 size_t convlen = strlen(string); 186 size_t convlen = strlen(string);
193 187
194 /* Cannot exceed 255 (PTP_MAXSTRLEN) since it is a single byte, duh ... */ 188 /* Cannot exceed 255 (PTP_MAXSTRLEN) since it is a single byte, duh ... */
195 memset(ucs2strp, 0, sizeof(ucs2str)); /* XXX: necessary? */ 189 memset(ucs2strp, 0, sizeof(ucs2str)); /* XXX: necessary? */
196 #if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H) 190 #ifdef HAVE_ICONV
197 if (params->cd_locale_to_ucs2 != (iconv_t)-1) { 191 if (params->cd_locale_to_ucs2 != (iconv_t)-1) {
198 size_t nconv; 192 size_t nconv;
199 size_t convmax = PTP_MAXSTRLEN * 2; /* Includes the terminator * / 193 size_t convmax = PTP_MAXSTRLEN * 2; /* Includes the terminator * /
200 char *stringp = string; 194 char *stringp = string;
201 195
202 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, 196 nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen,
203 &ucs2strp, &convmax); 197 &ucs2strp, &convmax);
204 if (nconv == (size_t) -1) 198 if (nconv == (size_t) -1)
205 ucs2str[0] = 0x0000U; 199 ucs2str[0] = 0x0000U;
206 } else 200 } else
207 #endif 201 #endif
208 { 202 {
209 » » unsigned int i; 203 » » int i;
210
211 for (i=0;i<convlen;i++) { 204 for (i=0;i<convlen;i++) {
212 ucs2str[i] = string[i]; 205 ucs2str[i] = string[i];
213 } 206 }
214 ucs2str[convlen] = 0; 207 ucs2str[convlen] = 0;
215 } 208 }
216 /* 209 /*
217 * XXX: isn't packedlen just ( (uint16_t *)ucs2strp - ucs2str )? 210 * XXX: isn't packedlen just ( (uint16_t *)ucs2strp - ucs2str )?
218 * why do we need ucs2strlen()? 211 * why do we need ucs2strlen()?
219 */ 212 */
220 packedlen = ucs2strlen(ucs2str); 213 packedlen = ucs2strlen(ucs2str);
(...skipping 30 matching lines...) Expand all
251 if (!retcopy) { 244 if (!retcopy) {
252 *packed_size = 0; 245 *packed_size = 0;
253 return NULL; 246 return NULL;
254 } 247 }
255 memcpy(retcopy, packed, plen); 248 memcpy(retcopy, packed, plen);
256 *packed_size = plen; 249 *packed_size = plen;
257 return (retcopy); 250 return (retcopy);
258 } 251 }
259 252
260 static inline uint32_t 253 static inline uint32_t
261 ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, unsigned int o ffset, unsigned int datalen, uint32_t **array) 254 ptp_unpack_uint32_t_array(PTPParams *params, unsigned char* data, uint16_t offse t, uint32_t **array)
262 { 255 {
263 uint32_t n, i=0; 256 uint32_t n, i=0;
264 257
265 if (offset >= datalen)
266 return 0;
267
268 if (offset + sizeof(uint32_t) > datalen)
269 return 0;
270
271 *array = NULL;
272 n=dtoh32a(&data[offset]); 258 n=dtoh32a(&data[offset]);
273 » if (n >= UINT_MAX/sizeof(uint32_t)) 259 » *array = malloc (n*sizeof(uint32_t));
274 » » return 0; 260 » while (n>i) {
275 » if (!n) 261 » » (*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]);
276 » » return 0; 262 » » i++;
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 } 263 }
282
283 *array = malloc (n*sizeof(uint32_t));
284 for (i=0;i<n;i++)
285 (*array)[i]=dtoh32a(&data[offset+(sizeof(uint32_t)*(i+1))]);
286 return n; 264 return n;
287 } 265 }
288 266
289 static inline uint32_t 267 static inline uint32_t
290 ptp_pack_uint32_t_array(PTPParams *params, uint32_t *array, uint32_t arraylen, u nsigned char **data ) 268 ptp_pack_uint32_t_array(PTPParams *params, uint32_t *array, uint32_t arraylen, u nsigned char **data )
291 { 269 {
292 uint32_t i=0; 270 uint32_t i=0;
293 271
294 *data = malloc ((arraylen+1)*sizeof(uint32_t)); 272 *data = malloc ((arraylen+1)*sizeof(uint32_t));
295 htod32a(&(*data)[0],arraylen); 273 htod32a(&(*data)[0],arraylen);
296 for (i=0;i<arraylen;i++) 274 for (i=0;i<arraylen;i++)
297 htod32a(&(*data)[sizeof(uint32_t)*(i+1)], array[i]); 275 htod32a(&(*data)[sizeof(uint32_t)*(i+1)], array[i]);
298 return (arraylen+1)*sizeof(uint32_t); 276 return (arraylen+1)*sizeof(uint32_t);
299 } 277 }
300 278
301 static inline uint32_t 279 static inline uint32_t
302 ptp_unpack_uint16_t_array(PTPParams *params, unsigned char* data, unsigned int o ffset, unsigned int datalen, uint16_t **array) 280 ptp_unpack_uint16_t_array(PTPParams *params, unsigned char* data, uint16_t offse t, uint16_t **array)
303 { 281 {
304 uint32_t n, i=0; 282 uint32_t n, i=0;
305 283
306 *array = NULL;
307 n=dtoh32a(&data[offset]); 284 n=dtoh32a(&data[offset]);
308 » if (n >= UINT_MAX/sizeof(uint16_t)) 285 » *array = malloc (n*sizeof(uint16_t));
309 » » return 0; 286 » while (n>i) {
310 » if (!n) 287 » » (*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]);
311 » » return 0; 288 » » i++;
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 } 289 }
318 *array = malloc (n*sizeof(uint16_t));
319 for (i=0;i<n;i++)
320 (*array)[i]=dtoh16a(&data[offset+(sizeof(uint16_t)*(i+2))]);
321 return n; 290 return n;
322 } 291 }
323 292
324 /* DeviceInfo pack/unpack */ 293 /* DeviceInfo pack/unpack */
325 294
326 #define PTP_di_StandardVersion 0 295 #define PTP_di_StandardVersion 0
327 #define PTP_di_VendorExtensionID 2 296 #define PTP_di_VendorExtensionID 2
328 #define PTP_di_VendorExtensionVersion 6 297 #define PTP_di_VendorExtensionVersion 6
329 #define PTP_di_VendorExtensionDesc 8 298 #define PTP_di_VendorExtensionDesc 8
330 #define PTP_di_FunctionalMode 8 299 #define PTP_di_FunctionalMode 8
(...skipping 13 matching lines...) Expand all
344 di->VendorExtensionVersion = 313 di->VendorExtensionVersion =
345 dtoh16a(&data[PTP_di_VendorExtensionVersion]); 314 dtoh16a(&data[PTP_di_VendorExtensionVersion]);
346 di->VendorExtensionDesc = 315 di->VendorExtensionDesc =
347 ptp_unpack_string(params, data, 316 ptp_unpack_string(params, data,
348 PTP_di_VendorExtensionDesc, &len); 317 PTP_di_VendorExtensionDesc, &len);
349 totallen=len*2+1; 318 totallen=len*2+1;
350 di->FunctionalMode = 319 di->FunctionalMode =
351 dtoh16a(&data[PTP_di_FunctionalMode+totallen]); 320 dtoh16a(&data[PTP_di_FunctionalMode+totallen]);
352 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data, 321 di->OperationsSupported_len = ptp_unpack_uint16_t_array(params, data,
353 PTP_di_OperationsSupported+totallen, 322 PTP_di_OperationsSupported+totallen,
354 datalen,
355 &di->OperationsSupported); 323 &di->OperationsSupported);
356 totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(ui nt32_t); 324 totallen=totallen+di->OperationsSupported_len*sizeof(uint16_t)+sizeof(ui nt32_t);
357 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data, 325 di->EventsSupported_len = ptp_unpack_uint16_t_array(params, data,
358 PTP_di_OperationsSupported+totallen, 326 PTP_di_OperationsSupported+totallen,
359 datalen,
360 &di->EventsSupported); 327 &di->EventsSupported);
361 totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32 _t); 328 totallen=totallen+di->EventsSupported_len*sizeof(uint16_t)+sizeof(uint32 _t);
362 di->DevicePropertiesSupported_len = 329 di->DevicePropertiesSupported_len =
363 ptp_unpack_uint16_t_array(params, data, 330 ptp_unpack_uint16_t_array(params, data,
364 PTP_di_OperationsSupported+totallen, 331 PTP_di_OperationsSupported+totallen,
365 datalen,
366 &di->DevicePropertiesSupported); 332 &di->DevicePropertiesSupported);
367 totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+siz eof(uint32_t); 333 totallen=totallen+di->DevicePropertiesSupported_len*sizeof(uint16_t)+siz eof(uint32_t);
368 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data, 334 di->CaptureFormats_len = ptp_unpack_uint16_t_array(params, data,
369 PTP_di_OperationsSupported+totallen, 335 PTP_di_OperationsSupported+totallen,
370 datalen,
371 &di->CaptureFormats); 336 &di->CaptureFormats);
372 totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_ t); 337 totallen=totallen+di->CaptureFormats_len*sizeof(uint16_t)+sizeof(uint32_ t);
373 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data, 338 di->ImageFormats_len = ptp_unpack_uint16_t_array(params, data,
374 PTP_di_OperationsSupported+totallen, 339 PTP_di_OperationsSupported+totallen,
375 datalen,
376 &di->ImageFormats); 340 &di->ImageFormats);
377 totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t) ; 341 totallen=totallen+di->ImageFormats_len*sizeof(uint16_t)+sizeof(uint32_t) ;
378 di->Manufacturer = ptp_unpack_string(params, data, 342 di->Manufacturer = ptp_unpack_string(params, data,
379 PTP_di_OperationsSupported+totallen, 343 PTP_di_OperationsSupported+totallen,
380 &len); 344 &len);
381 totallen+=len*2+1; 345 totallen+=len*2+1;
382 di->Model = ptp_unpack_string(params, data, 346 di->Model = ptp_unpack_string(params, data,
383 PTP_di_OperationsSupported+totallen, 347 PTP_di_OperationsSupported+totallen,
384 &len); 348 &len);
385 totallen+=len*2+1; 349 totallen+=len*2+1;
386 di->DeviceVersion = ptp_unpack_string(params, data, 350 di->DeviceVersion = ptp_unpack_string(params, data,
387 PTP_di_OperationsSupported+totallen, 351 PTP_di_OperationsSupported+totallen,
388 &len); 352 &len);
389 totallen+=len*2+1; 353 totallen+=len*2+1;
390 di->SerialNumber = ptp_unpack_string(params, data, 354 di->SerialNumber = ptp_unpack_string(params, data,
391 PTP_di_OperationsSupported+totallen, 355 PTP_di_OperationsSupported+totallen,
392 &len); 356 &len);
393 } 357 }
394 358
395 inline static void 359 static void inline
396 ptp_free_DI (PTPDeviceInfo *di) { 360 ptp_free_DI (PTPDeviceInfo *di) {
397 » free (di->SerialNumber); 361 » if (di->SerialNumber) free (di->SerialNumber);
398 » free (di->DeviceVersion); 362 » if (di->DeviceVersion) free (di->DeviceVersion);
399 » free (di->Model); 363 » if (di->Model) free (di->Model);
400 » free (di->Manufacturer); 364 » if (di->Manufacturer) free (di->Manufacturer);
401 » free (di->ImageFormats); 365 » if (di->ImageFormats) free (di->ImageFormats);
402 » free (di->CaptureFormats); 366 » if (di->CaptureFormats) free (di->CaptureFormats);
403 » free (di->VendorExtensionDesc); 367 » if (di->VendorExtensionDesc) free (di->VendorExtensionDesc);
404 » free (di->OperationsSupported); 368 » if (di->OperationsSupported) free (di->OperationsSupported);
405 » free (di->EventsSupported); 369 » if (di->EventsSupported) free (di->EventsSupported);
406 » free (di->DevicePropertiesSupported); 370 » if (di->DevicePropertiesSupported) free (di->DevicePropertiesSupported);
407 } 371 }
408 372
409 /* EOS Device Info unpack */ 373 /* EOS Device Info unpack */
410 static inline void 374 static inline void
411 ptp_unpack_EOS_DI (PTPParams *params, unsigned char* data, PTPCanonEOSDeviceInfo *di, unsigned int datalen) 375 ptp_unpack_EOS_DI (PTPParams *params, unsigned char* data, PTPCanonEOSDeviceInfo *di, unsigned int datalen)
412 { 376 {
413 » unsigned int totallen = 4; 377 » int totallen = 4;
414 378
415 memset (di,0, sizeof(*di)); 379 memset (di,0, sizeof(*di));
416 if (datalen < 8) return; 380 if (datalen < 8) return;
417 381
418 /* uint32_t struct len - ignore */ 382 /* uint32_t struct len - ignore */
419 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data, 383 di->EventsSupported_len = ptp_unpack_uint32_t_array(params, data,
420 » » totallen, datalen, &di->EventsSupported); 384 » » totallen, &di->EventsSupported);
421 if (!di->EventsSupported) return; 385 if (!di->EventsSupported) return;
422 totallen += di->EventsSupported_len*sizeof(uint32_t)+4; 386 totallen += di->EventsSupported_len*sizeof(uint32_t)+4;
423 if (totallen >= datalen) return; 387 if (totallen >= datalen) return;
424 388
425 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, da ta, 389 di->DevicePropertiesSupported_len = ptp_unpack_uint32_t_array(params, da ta,
426 » » totallen, datalen, &di->DevicePropertiesSupported); 390 » » totallen, &di->DevicePropertiesSupported);
427 if (!di->DevicePropertiesSupported) return; 391 if (!di->DevicePropertiesSupported) return;
428 totallen += di->DevicePropertiesSupported_len*sizeof(uint32_t)+4; 392 totallen += di->DevicePropertiesSupported_len*sizeof(uint32_t)+4;
429 if (totallen >= datalen) return; 393 if (totallen >= datalen) return;
430 394
431 di->unk_len = ptp_unpack_uint32_t_array(params, data, 395 di->unk_len = ptp_unpack_uint32_t_array(params, data,
432 » » totallen, datalen, &di->unk); 396 » » totallen, &di->unk);
433 if (!di->unk) return; 397 if (!di->unk) return;
434 totallen += di->unk_len*sizeof(uint32_t)+4; 398 totallen += di->unk_len*sizeof(uint32_t)+4;
435 return; 399 return;
436 } 400 }
437 401
438 static inline void 402 static inline void
439 ptp_free_EOS_DI (PTPCanonEOSDeviceInfo *di) 403 ptp_free_EOS_DI (PTPCanonEOSDeviceInfo *di)
440 { 404 {
441 free (di->EventsSupported); 405 free (di->EventsSupported);
442 free (di->DevicePropertiesSupported); 406 free (di->DevicePropertiesSupported);
443 free (di->unk); 407 free (di->unk);
444 } 408 }
445 409
446 /* ObjectHandles array pack/unpack */ 410 /* ObjectHandles array pack/unpack */
447 411
448 #define PTP_oh 0 412 #define PTP_oh 0
449 413
450 static inline void 414 static inline void
451 ptp_unpack_OH (PTPParams *params, unsigned char* data, PTPObjectHandles *oh, uns igned int len) 415 ptp_unpack_OH (PTPParams *params, unsigned char* data, PTPObjectHandles *oh, uns igned int len)
452 { 416 {
453 if (len) { 417 if (len) {
454 » » oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, len, &oh ->Handler); 418 » » oh->n = ptp_unpack_uint32_t_array(params, data, PTP_oh, &oh->Han dler);
455 } else { 419 } else {
456 oh->n = 0; 420 oh->n = 0;
457 oh->Handler = NULL; 421 oh->Handler = NULL;
458 } 422 }
459 } 423 }
460 424
461 /* StoreIDs array pack/unpack */ 425 /* StoreIDs array pack/unpack */
462 426
463 #define PTP_sids 0 427 #define PTP_sids 0
464 428
465 static inline void 429 static inline void
466 ptp_unpack_SIDs (PTPParams *params, unsigned char* data, PTPStorageIDs *sids, un signed int len) 430 ptp_unpack_SIDs (PTPParams *params, unsigned char* data, PTPStorageIDs *sids, un signed int len)
467 { 431 {
468 » if (!data || !len) { 432 if (!data && !len) {
469 sids->n = 0; 433 sids->n = 0;
470 sids->Storage = NULL; 434 sids->Storage = NULL;
471 return; 435 return;
472 } 436 }
473 » sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids, len, &sids-> Storage); 437 » sids->n = ptp_unpack_uint32_t_array(params, data, PTP_sids,
438 » &sids->Storage);
474 } 439 }
475 440
476 /* StorageInfo pack/unpack */ 441 /* StorageInfo pack/unpack */
477 442
478 #define PTP_si_StorageType 0 443 #define PTP_si_StorageType 0
479 #define PTP_si_FilesystemType 2 444 #define PTP_si_FilesystemType 2
480 #define PTP_si_AccessCapability 4 445 #define PTP_si_AccessCapability 4
481 #define PTP_si_MaxCapability 6 446 #define PTP_si_MaxCapability 6
482 #define PTP_si_FreeSpaceInBytes 14 447 #define PTP_si_FreeSpaceInBytes 14
483 #define PTP_si_FreeSpaceInImages 22 448 #define PTP_si_FreeSpaceInImages 22
484 #define PTP_si_StorageDescription 26 449 #define PTP_si_StorageDescription 26
485 450
486 static inline void 451 static inline void
487 ptp_unpack_SI (PTPParams *params, unsigned char* data, PTPStorageInfo *si, unsig ned int len) 452 ptp_unpack_SI (PTPParams *params, unsigned char* data, PTPStorageInfo *si, unsig ned int len)
488 { 453 {
489 uint8_t storagedescriptionlen; 454 uint8_t storagedescriptionlen;
490 455
491 if (len < 26) return;
492 si->StorageType=dtoh16a(&data[PTP_si_StorageType]); 456 si->StorageType=dtoh16a(&data[PTP_si_StorageType]);
493 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]); 457 si->FilesystemType=dtoh16a(&data[PTP_si_FilesystemType]);
494 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]); 458 si->AccessCapability=dtoh16a(&data[PTP_si_AccessCapability]);
495 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]); 459 si->MaxCapability=dtoh64a(&data[PTP_si_MaxCapability]);
496 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]); 460 si->FreeSpaceInBytes=dtoh64a(&data[PTP_si_FreeSpaceInBytes]);
497 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]); 461 si->FreeSpaceInImages=dtoh32a(&data[PTP_si_FreeSpaceInImages]);
498
499 /* FIXME: check more lengths here */
500 si->StorageDescription=ptp_unpack_string(params, data, 462 si->StorageDescription=ptp_unpack_string(params, data,
501 PTP_si_StorageDescription, &storagedescriptionlen); 463 PTP_si_StorageDescription, &storagedescriptionlen);
502 si->VolumeLabel=ptp_unpack_string(params, data, 464 si->VolumeLabel=ptp_unpack_string(params, data,
503 PTP_si_StorageDescription+storagedescriptionlen*2+1, 465 PTP_si_StorageDescription+storagedescriptionlen*2+1,
504 &storagedescriptionlen); 466 &storagedescriptionlen);
505 } 467 }
506 468
507 /* ObjectInfo pack/unpack */ 469 /* ObjectInfo pack/unpack */
508 470
509 #define PTP_oi_StorageID 0 471 #define PTP_oi_StorageID 0
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 return mktime (&tm); 597 return mktime (&tm);
636 } 598 }
637 599
638 static inline void 600 static inline void
639 ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsign ed int len) 601 ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsign ed int len)
640 { 602 {
641 uint8_t filenamelen; 603 uint8_t filenamelen;
642 uint8_t capturedatelen; 604 uint8_t capturedatelen;
643 char *capture_date; 605 char *capture_date;
644 606
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 */
651 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]); 607 oi->StorageID=dtoh32a(&data[PTP_oi_StorageID]);
652 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]); 608 oi->ObjectFormat=dtoh16a(&data[PTP_oi_ObjectFormat]);
653 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]); 609 oi->ProtectionStatus=dtoh16a(&data[PTP_oi_ProtectionStatus]);
654 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]); 610 oi->ObjectCompressedSize=dtoh32a(&data[PTP_oi_ObjectCompressedSize]);
655 611
656 /* Stupid Samsung Galaxy developers emit a 64bit objectcompressedsize */ 612 /* Stupid Samsung Galaxy developers emit a 64bit objectcompressedsize */
657 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0) ) { 613 if ((data[PTP_oi_filenamelen] == 0) && (data[PTP_oi_filenamelen+4] != 0) ) {
658 params->ocs64 = 1; 614 params->ocs64 = 1;
659 data += 4; 615 data += 4;
660 } 616 }
(...skipping 29 matching lines...) Expand all
690 646
691 /* Custom Type Value Assignement (without Length) macro frequently used below */ 647 /* Custom Type Value Assignement (without Length) macro frequently used below */
692 #define CTVAL(target,func) { \ 648 #define CTVAL(target,func) { \
693 if (total - *offset < sizeof(target)) \ 649 if (total - *offset < sizeof(target)) \
694 return 0; \ 650 return 0; \
695 target = func(&data[*offset]); \ 651 target = func(&data[*offset]); \
696 *offset += sizeof(target); \ 652 *offset += sizeof(target); \
697 } 653 }
698 654
699 #define RARR(val,member,func) { \ 655 #define RARR(val,member,func) { \
700 » unsigned int n,j;» » » » \ 656 » int n,j;» » » » » \
701 if (total - *offset < sizeof(uint32_t)) \ 657 if (total - *offset < sizeof(uint32_t)) \
702 return 0; \ 658 return 0; \
703 n = dtoh32a (&data[*offset]); \ 659 n = dtoh32a (&data[*offset]); \
704 *offset += sizeof(uint32_t); \ 660 *offset += sizeof(uint32_t); \
705 \ 661 \
706 if (n >= UINT_MAX/sizeof(val->a.v[0])) \
707 return 0; \
708 val->a.count = n; \ 662 val->a.count = n; \
709 val->a.v = malloc(sizeof(val->a.v[0])*n); \ 663 val->a.v = malloc(sizeof(val->a.v[0])*n); \
710 if (!val->a.v) return 0; \ 664 if (!val->a.v) return 0; \
711 for (j=0;j<n;j++) \ 665 for (j=0;j<n;j++) \
712 CTVAL(val->a.v[j].member, func); \ 666 CTVAL(val->a.v[j].member, func); \
713 } 667 }
714 668
715 static inline unsigned int 669 static inline int
716 ptp_unpack_DPV ( 670 ptp_unpack_DPV (
717 » PTPParams *params, unsigned char* data, unsigned int *offset, unsigned i nt total, 671 » PTPParams *params, unsigned char* data, int *offset, int total,
718 PTPPropertyValue* value, uint16_t datatype 672 PTPPropertyValue* value, uint16_t datatype
719 ) { 673 ) {
720 switch (datatype) { 674 switch (datatype) {
721 case PTP_DTC_INT8: 675 case PTP_DTC_INT8:
722 CTVAL(value->i8,dtoh8a); 676 CTVAL(value->i8,dtoh8a);
723 break; 677 break;
724 case PTP_DTC_UINT8: 678 case PTP_DTC_UINT8:
725 CTVAL(value->u8,dtoh8a); 679 CTVAL(value->u8,dtoh8a);
726 break; 680 break;
727 case PTP_DTC_INT16: 681 case PTP_DTC_INT16:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 return 1; 743 return 1;
790 break; 744 break;
791 } 745 }
792 default: 746 default:
793 return 0; 747 return 0;
794 } 748 }
795 return 1; 749 return 1;
796 } 750 }
797 751
798 /* Device Property pack/unpack */ 752 /* Device Property pack/unpack */
753
799 #define PTP_dpd_DevicePropertyCode 0 754 #define PTP_dpd_DevicePropertyCode 0
800 #define PTP_dpd_DataType 2 755 #define PTP_dpd_DataType 2
801 #define PTP_dpd_GetSet 4 756 #define PTP_dpd_GetSet 4
802 #define PTP_dpd_FactoryDefaultValue 5 757 #define PTP_dpd_FactoryDefaultValue 5
803 758
804 static inline int 759 static inline int
805 ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd, unsigned int dpdlen) 760 ptp_unpack_DPD (PTPParams *params, unsigned char* data, PTPDevicePropDesc *dpd, unsigned int dpdlen)
806 { 761 {
807 » unsigned int offset = 0, ret; 762 » int offset=0, ret;
808 763
809 memset (dpd, 0, sizeof(*dpd)); 764 memset (dpd, 0, sizeof(*dpd));
810 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]); 765 dpd->DevicePropertyCode=dtoh16a(&data[PTP_dpd_DevicePropertyCode]);
811 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]); 766 dpd->DataType=dtoh16a(&data[PTP_dpd_DataType]);
812 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]); 767 dpd->GetSet=dtoh8a(&data[PTP_dpd_GetSet]);
813 dpd->FormFlag=PTP_DPFF_None; 768 dpd->FormFlag=PTP_DPFF_None;
814 769
815 offset = PTP_dpd_FactoryDefaultValue; 770 offset = PTP_dpd_FactoryDefaultValue;
816 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaul tValue, dpd->DataType); 771 ret = ptp_unpack_DPV (params, data, &offset, dpdlen, &dpd->FactoryDefaul tValue, dpd->DataType);
817 if (!ret) goto outofmemory; 772 if (!ret) goto outofmemory;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 822 }
868 } 823 }
869 } 824 }
870 #undef N 825 #undef N
871 return 1; 826 return 1;
872 outofmemory: 827 outofmemory:
873 ptp_free_devicepropdesc(dpd); 828 ptp_free_devicepropdesc(dpd);
874 return 0; 829 return 0;
875 } 830 }
876 831
877 /* Device Property pack/unpack */ 832 /* (MTP) Object 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
1034 #define PTP_opd_ObjectPropertyCode 0 833 #define PTP_opd_ObjectPropertyCode 0
1035 #define PTP_opd_DataType 2 834 #define PTP_opd_DataType 2
1036 #define PTP_opd_GetSet 4 835 #define PTP_opd_GetSet 4
1037 #define PTP_opd_FactoryDefaultValue 5 836 #define PTP_opd_FactoryDefaultValue 5
1038 837
1039 static inline int 838 static inline int
1040 ptp_unpack_OPD (PTPParams *params, unsigned char* data, PTPObjectPropDesc *opd, unsigned int opdlen) 839 ptp_unpack_OPD (PTPParams *params, unsigned char* data, PTPObjectPropDesc *opd, unsigned int opdlen)
1041 { 840 {
1042 » unsigned int offset=0, ret; 841 » int offset=0, ret;
1043 842
1044 memset (opd, 0, sizeof(*opd)); 843 memset (opd, 0, sizeof(*opd));
1045 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]); 844 opd->ObjectPropertyCode=dtoh16a(&data[PTP_opd_ObjectPropertyCode]);
1046 opd->DataType=dtoh16a(&data[PTP_opd_DataType]); 845 opd->DataType=dtoh16a(&data[PTP_opd_DataType]);
1047 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]); 846 opd->GetSet=dtoh8a(&data[PTP_opd_GetSet]);
1048 847
1049 offset = PTP_opd_FactoryDefaultValue; 848 offset = PTP_opd_FactoryDefaultValue;
1050 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaul tValue, opd->DataType); 849 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FactoryDefaul tValue, opd->DataType);
1051 if (!ret) goto outofmemory; 850 if (!ret) goto outofmemory;
1052 851
1053 opd->GroupCode=dtoh32a(&data[offset]); 852 opd->GroupCode=dtoh32a(&data[offset]);
1054 offset+=sizeof(uint32_t); 853 offset+=sizeof(uint32_t);
1055 854
1056 opd->FormFlag=dtoh8a(&data[offset]); 855 opd->FormFlag=dtoh8a(&data[offset]);
1057 offset+=sizeof(uint8_t); 856 offset+=sizeof(uint8_t);
1058 857
1059 switch (opd->FormFlag) { 858 switch (opd->FormFlag) {
1060 case PTP_OPFF_Range: 859 case PTP_OPFF_Range:
1061 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.MinimumValue, opd->DataType); 860 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.MinimumValue, opd->DataType);
1062 if (!ret) goto outofmemory; 861 if (!ret) goto outofmemory;
1063 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.MaximumValue, opd->DataType); 862 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.MaximumValue, opd->DataType);
1064 if (!ret) goto outofmemory; 863 if (!ret) goto outofmemory;
1065 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.StepSize, opd->DataType); 864 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &opd->FORM. Range.StepSize, opd->DataType);
1066 if (!ret) goto outofmemory; 865 if (!ret) goto outofmemory;
1067 break; 866 break;
1068 case PTP_OPFF_Enumeration: { 867 case PTP_OPFF_Enumeration: {
1069 » » unsigned int i; 868 » » int i;
1070 #define N opd->FORM.Enum.NumberOfValues 869 #define N opd->FORM.Enum.NumberOfValues
1071 N = dtoh16a(&data[offset]); 870 N = dtoh16a(&data[offset]);
1072 offset+=sizeof(uint16_t); 871 offset+=sizeof(uint16_t);
1073 opd->FORM.Enum.SupportedValue = malloc(N*sizeof(opd->FORM.Enum.S upportedValue[0])); 872 opd->FORM.Enum.SupportedValue = malloc(N*sizeof(opd->FORM.Enum.S upportedValue[0]));
1074 if (!opd->FORM.Enum.SupportedValue) 873 if (!opd->FORM.Enum.SupportedValue)
1075 goto outofmemory; 874 goto outofmemory;
1076 875
1077 memset (opd->FORM.Enum.SupportedValue,0 , N*sizeof(opd->FORM.Enu m.SupportedValue[0])); 876 memset (opd->FORM.Enum.SupportedValue,0 , N*sizeof(opd->FORM.Enu m.SupportedValue[0]));
1078 for (i=0;i<N;i++) { 877 for (i=0;i<N;i++) {
1079 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &op d->FORM.Enum.SupportedValue[i], opd->DataType); 878 ret = ptp_unpack_DPV (params, data, &offset, opdlen, &op d->FORM.Enum.SupportedValue[i], opd->DataType);
(...skipping 18 matching lines...) Expand all
1098 ptp_free_objectpropdesc(opd); 897 ptp_free_objectpropdesc(opd);
1099 return 0; 898 return 0;
1100 } 899 }
1101 900
1102 901
1103 static inline uint32_t 902 static inline uint32_t
1104 ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr , uint16_t datatype) 903 ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr , uint16_t datatype)
1105 { 904 {
1106 unsigned char* dpv=NULL; 905 unsigned char* dpv=NULL;
1107 uint32_t size=0; 906 uint32_t size=0;
1108 » unsigned int i; 907 » int» i;
1109 908
1110 switch (datatype) { 909 switch (datatype) {
1111 case PTP_DTC_INT8: 910 case PTP_DTC_INT8:
1112 size=sizeof(int8_t); 911 size=sizeof(int8_t);
1113 dpv=malloc(size); 912 dpv=malloc(size);
1114 htod8a(dpv,value->i8); 913 htod8a(dpv,value->i8);
1115 break; 914 break;
1116 case PTP_DTC_UINT8: 915 case PTP_DTC_UINT8:
1117 size=sizeof(uint8_t); 916 size=sizeof(uint8_t);
1118 dpv=malloc(size); 917 dpv=malloc(size);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 const MTPProperties *py = y; 1078 const MTPProperties *py = y;
1280 1079
1281 return px->ObjectHandle - py->ObjectHandle; 1080 return px->ObjectHandle - py->ObjectHandle;
1282 } 1081 }
1283 1082
1284 static inline int 1083 static inline int
1285 ptp_unpack_OPL (PTPParams *params, unsigned char* data, MTPProperties **pprops, unsigned int len) 1084 ptp_unpack_OPL (PTPParams *params, unsigned char* data, MTPProperties **pprops, unsigned int len)
1286 { 1085 {
1287 uint32_t prop_count = dtoh32a(data); 1086 uint32_t prop_count = dtoh32a(data);
1288 MTPProperties *props = NULL; 1087 MTPProperties *props = NULL;
1289 » unsigned int offset = 0, i; 1088 » int offset = 0, i;
1290 1089
1291 if (prop_count == 0) { 1090 if (prop_count == 0) {
1292 *pprops = NULL; 1091 *pprops = NULL;
1293 return 0; 1092 return 0;
1294 } 1093 }
1295 ptp_debug (params ,"Unpacking MTP OPL, size %d (prop_count %d)", len, pr op_count); 1094 ptp_debug (params ,"Unpacking MTP OPL, size %d (prop_count %d)", len, pr op_count);
1296 data += sizeof(uint32_t); 1095 data += sizeof(uint32_t);
1297 len -= sizeof(uint32_t); 1096 len -= sizeof(uint32_t);
1298 props = malloc(prop_count * sizeof(MTPProperties)); 1097 props = malloc(prop_count * sizeof(MTPProperties));
1299 if (!props) return 0; 1098 if (!props) return 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 #define PTP_ec_Type 4 1136 #define PTP_ec_Type 4
1338 #define PTP_ec_Code 6 1137 #define PTP_ec_Code 6
1339 #define PTP_ec_TransId 8 1138 #define PTP_ec_TransId 8
1340 #define PTP_ec_Param1 12 1139 #define PTP_ec_Param1 12
1341 #define PTP_ec_Param2 16 1140 #define PTP_ec_Param2 16
1342 #define PTP_ec_Param3 20 1141 #define PTP_ec_Param3 20
1343 1142
1344 static inline void 1143 static inline void
1345 ptp_unpack_EC (PTPParams *params, unsigned char* data, PTPContainer *ec, unsigne d int len) 1144 ptp_unpack_EC (PTPParams *params, unsigned char* data, PTPContainer *ec, unsigne d int len)
1346 { 1145 {
1347 » unsigned int» length; 1146 » int» length;
1348 int type; 1147 int type;
1349 1148
1350 if (data==NULL) 1149 if (data==NULL)
1351 return; 1150 return;
1352 memset(ec,0,sizeof(*ec)); 1151 memset(ec,0,sizeof(*ec));
1353
1354 length=dtoh32a(&data[PTP_ec_Length]); 1152 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 }
1359 type = dtoh16a(&data[PTP_ec_Type]); 1153 type = dtoh16a(&data[PTP_ec_Type]);
1360 1154
1361 ec->Code=dtoh16a(&data[PTP_ec_Code]); 1155 ec->Code=dtoh16a(&data[PTP_ec_Code]);
1362 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]); 1156 ec->Transaction_ID=dtoh32a(&data[PTP_ec_TransId]);
1363 1157
1364 if (type!=PTP_USB_CONTAINER_EVENT) { 1158 if (type!=PTP_USB_CONTAINER_EVENT) {
1365 ptp_debug (params, "Unknown canon event type %d (code=%x,tid=%x) , please report!",type,ec->Code,ec->Transaction_ID); 1159 ptp_debug (params, "Unknown canon event type %d (code=%x,tid=%x) , please report!",type,ec->Code,ec->Transaction_ID);
1366 return; 1160 return;
1367 } 1161 }
1368 if (length>=(PTP_ec_Param1+4)) { 1162 if (length>=(PTP_ec_Param1+4)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 AssociationType: 0x0000 1233 AssociationType: 0x0000
1440 AssociationDesc: 0x00000000 1234 AssociationDesc: 0x00000000
1441 SequenceNumber: 0x00000000 1235 SequenceNumber: 0x00000000
1442 ModificationDate: 0x4d985ff0 1236 ModificationDate: 0x4d985ff0
1443 CaptureDate: 0x4d985ff0 1237 CaptureDate: 0x4d985ff0
1444 1238
1445 0010 38 00 00 00 Size of this entry 1239 0010 38 00 00 00 Size of this entry
1446 0014 72 0c 74 92 OID 1240 0014 72 0c 74 92 OID
1447 0018 01 00 02 00 StorageID 1241 0018 01 00 02 00 StorageID
1448 001c 01 38 00 00 OFC 1242 001c 01 38 00 00 OFC
1449 0020 00 00 00 00 ?? 1243 0020 00 00 00 00 00 00 00 00 ?
1450 0024 21 00 00 00 flags (4 bytes? 1 byte?)
1451 0028 19 d5 21 00 Size 1244 0028 19 d5 21 00 Size
1452 002c 00 00 74 92 ? 1245 002c 00 00 74 92 ?
1453 0030 70 0c 74 92 OID 1246 0030 70 0c 74 92 OID
1454 0034 49 4d 47 5f-30 31 39 39 2e 4a 50 47 IMG_0199.JPG 1247 0034 49 4d 47 5f-30 31 39 39 2e 4a 50 47 IMG_0199.JPG
1455 0040 00 00 00 00 1248 0040 00 00 00 00
1456 0044 10 7c 98 4d Time 1249 0044 10 7c 98 4d Time
1457 1250
1458 1251
1459 */ 1252 */
1460 #define PTP_cefe_ObjectHandle 0 1253 #define PTP_cefe_ObjectHandle 0
1461 #define PTP_cefe_StorageID 4 1254 #define PTP_cefe_StorageID 4
1462 #define PTP_cefe_ObjectFormatCode 8 1255 #define PTP_cefe_ObjectFormatCode 8
1463 #define PTP_cefe_Flags» » » 16 1256 #define PTP_cefe_Flags» » » 12
1464 #define PTP_cefe_ObjectSize 20 1257 #define PTP_cefe_ObjectSize 20
1465 #define PTP_cefe_Filename 32 1258 #define PTP_cefe_Filename 32
1466 #define PTP_cefe_Time 48 1259 #define PTP_cefe_Time 48
1467 1260
1468 static inline void 1261 static inline void
1469 ptp_unpack_Canon_EOS_FE (PTPParams *params, unsigned char* data, PTPCANONFolderE ntry *fe) 1262 ptp_unpack_Canon_EOS_FE (PTPParams *params, unsigned char* data, PTPCANONFolderE ntry *fe)
1470 { 1263 {
1471 int i; 1264 int i;
1472 1265
1473 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]); 1266 fe->ObjectHandle=dtoh32a(&data[PTP_cefe_ObjectHandle]);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 htod32a(data+=4, ((value >> 0) & 0xF) == 4 ? 6 : 1); 1365 htod32a(data+=4, ((value >> 0) & 0xF) == 4 ? 6 : 1);
1573 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF)); 1366 htod32a(data+=4, PACK_5DM3_SMALL_JPEG_SIZE((value >> 4) & 0xF));
1574 htod32a(data+=4, (value >> 0) & 0xF); 1367 htod32a(data+=4, (value >> 0) & 0xF);
1575 } 1368 }
1576 1369
1577 #undef PACK_5DM3_SMALL_JPEG_SIZE 1370 #undef PACK_5DM3_SMALL_JPEG_SIZE
1578 1371
1579 return s; 1372 return s;
1580 } 1373 }
1581 1374
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
1668 static inline char* 1375 static inline char*
1669 ptp_unpack_EOS_CustomFuncEx (PTPParams* params, unsigned char** data ) 1376 ptp_unpack_EOS_CustomFuncEx (PTPParams* params, unsigned char** data )
1670 { 1377 {
1671 uint32_t s = dtoh32a( *data ); 1378 uint32_t s = dtoh32a( *data );
1672 uint32_t n = s/4, i; 1379 uint32_t n = s/4, i;
1673 » char* str = (char*)malloc( s*2+s/4+1 ); /* n is size in uint32, maximum %x len is 8 chars and \0*/ 1380 » char* str = (char*)malloc( s ); // n is size in uint32, average len(itoa (i)) < 4 -> alloc n chars
1674 if (!str) 1381 if (!str)
1675 return str; 1382 return str;
1676 char* p = str; 1383 char* p = str;
1677 1384
1678 for (i=0; i < n; ++i) 1385 for (i=0; i < n; ++i)
1679 p += sprintf(p, "%x,", dtoh32a( *data + 4*i )); 1386 p += sprintf(p, "%x,", dtoh32a( *data + 4*i ));
1680 1387
1681 return str; 1388 return str;
1682 } 1389 }
1683 1390
1684 static inline uint32_t 1391 static inline uint32_t
1685 ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str) 1392 ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str)
1686 { 1393 {
1687 uint32_t s = strtoul(str, NULL, 16); 1394 uint32_t s = strtoul(str, NULL, 16);
1688 uint32_t n = s/4, i, v; 1395 uint32_t n = s/4, i, v;
1689 1396
1690 if (!data) 1397 if (!data)
1691 return s; 1398 return s;
1692 1399
1693 for (i=0; i<n; i++) 1400 for (i=0; i<n; i++)
1694 { 1401 {
1695 v = strtoul(str, &str, 16); 1402 v = strtoul(str, &str, 16);
1696 » » str++; /* skip the ',' delimiter */ 1403 » » str++; // skip the ',' delimiter
1697 htod32a(data + i*4, v); 1404 htod32a(data + i*4, v);
1698 } 1405 }
1699 1406
1700 return s; 1407 return s;
1701 } 1408 }
1702 1409
1703 /* 1410 /*
1704 PTP EOS Changes Entry unpack 1411 PTP EOS Changes Entry unpack
1705 */ 1412 */
1706 #define PTP_ece_Size 0 1413 #define PTP_ece_Size 0
(...skipping 12 matching lines...) Expand all
1719 #define PTP_ece_OI_Name 0x1c 1426 #define PTP_ece_OI_Name 0x1c
1720 1427
1721 /* for PTP_EC_CANON_EOS_ObjectAddedEx */ 1428 /* for PTP_EC_CANON_EOS_ObjectAddedEx */
1722 #define PTP_ece_OA_ObjectID 8 1429 #define PTP_ece_OA_ObjectID 8
1723 #define PTP_ece_OA_StorageID 0x0c 1430 #define PTP_ece_OA_StorageID 0x0c
1724 #define PTP_ece_OA_OFC 0x10 1431 #define PTP_ece_OA_OFC 0x10
1725 #define PTP_ece_OA_Size 0x1c 1432 #define PTP_ece_OA_Size 0x1c
1726 #define PTP_ece_OA_Parent 0x20 1433 #define PTP_ece_OA_Parent 0x20
1727 #define PTP_ece_OA_Name 0x28 1434 #define PTP_ece_OA_Name 0x28
1728 1435
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 &params->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 (&params->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 &params->canon_props[j].dpd;
1752 }
1753
1754
1755 static inline int 1436 static inline int
1756 ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, PTPCanon_changes_entry **pce) 1437 ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize, PTPCanon_changes_entry **ce)
1757 { 1438 {
1758 int i = 0, entries = 0; 1439 int i = 0, entries = 0;
1759 unsigned char *curdata = data; 1440 unsigned char *curdata = data;
1760 PTPCanon_changes_entry *ce;
1761 1441
1762 if (data==NULL) 1442 if (data==NULL)
1763 return 0; 1443 return 0;
1764 while (curdata - data < datasize) { 1444 while (curdata - data < datasize) {
1765 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); 1445 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
1766 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); 1446 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
1767 1447
1448 curdata += size;
1768 if ((size == 8) && (type == 0)) 1449 if ((size == 8) && (type == 0))
1769 break; 1450 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;
1778 entries++; 1451 entries++;
1779 } 1452 }
1780 » ce = malloc (sizeof(PTPCanon_changes_entry)*(entries+1)); 1453 » *ce = malloc (sizeof(PTPCanon_changes_entry)*(entries+1));
1781 » if (!ce) return 0; 1454 » if (!*ce) return 0;
1782 1455
1783 curdata = data; 1456 curdata = data;
1784 while (curdata - data < datasize) { 1457 while (curdata - data < datasize) {
1785 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]); 1458 uint32_t size = dtoh32a(&curdata[PTP_ece_Size]);
1786 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]); 1459 uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
1787 1460
1788 » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; 1461 » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
1789 » » ce[i].u.info = NULL; 1462 » » (*ce)[i].u.info = NULL;
1790 switch (type) { 1463 switch (type) {
1791 case PTP_EC_CANON_EOS_ObjectAddedEx: 1464 case PTP_EC_CANON_EOS_ObjectAddedEx:
1792 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO; 1465 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO;
1793 » » » ce[i].u.object.oid » » = dtoh32a(&curdata[PTP_e ce_OA_ObjectID]); 1466 » » » (*ce)[i].u.object.oid » » = dtoh32a(&curda ta[PTP_ece_OA_ObjectID]);
1794 » » » ce[i].u.object.oi.StorageID » » = dtoh32a(&curda ta[PTP_ece_OA_StorageID]); 1467 » » » (*ce)[i].u.object.oi.StorageID »» = dtoh32a(&curda ta[PTP_ece_OA_StorageID]);
1795 » » » ce[i].u.object.oi.ParentObject» = dtoh32a(&curdata[PTP_e ce_OA_Parent]); 1468 » » » (*ce)[i].u.object.oi.ParentObject» = dtoh32a(&curda ta[PTP_ece_OA_Parent]);
1796 » » » ce[i].u.object.oi.ObjectFormat »= dtoh16a(&curdata[PTP_e ce_OA_OFC]); 1469 » » » (*ce)[i].u.object.oi.ObjectFormat » = dtoh16a(&curda ta[PTP_ece_OA_OFC]);
1797 » » » ce[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curdata [PTP_ece_OA_Size]); 1470 » » » (*ce)[i].u.object.oi.ObjectCompressedSize= dtoh32a(&curd ata[PTP_ece_OA_Size]);
1798 » » » ce[i].u.object.oi.Filename » » = strdup(((char* )&curdata[PTP_ece_OA_Name])); 1471 » » » (*ce)[i].u.object.oi.Filename » » = strdup(((char* )&curdata[PTP_ece_OA_Name]));
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); 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);
1800 break; 1473 break;
1801 case PTP_EC_CANON_EOS_RequestObjectTransfer: 1474 case PTP_EC_CANON_EOS_RequestObjectTransfer:
1802 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER; 1475 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFE R;
1803 » » » ce[i].u.object.oid » » = dtoh32a(&curdata[PTP_e ce_OI_ObjectID]); 1476 » » » (*ce)[i].u.object.oid » » = dtoh32a(&curda ta[PTP_ece_OI_ObjectID]);
1804 » » » ce[i].u.object.oi.StorageID » » = 0; /* use as m arker */ 1477 » » » (*ce)[i].u.object.oi.StorageID »» = 0; /* use as m arker */
1805 » » » ce[i].u.object.oi.ObjectFormat »= dtoh16a(&curdata[PTP_e ce_OI_OFC]); 1478 » » » (*ce)[i].u.object.oi.ObjectFormat » = dtoh16a(&curda ta[PTP_ece_OI_OFC]);
1806 » » » ce[i].u.object.oi.ParentObject» = 0; /* check, but use a s marker */ 1479 » » » (*ce)[i].u.object.oi.ParentObject» = 0; /* check, b ut use as marker */
1807 » » » ce[i].u.object.oi.ObjectCompressedSize = dtoh32a(&curdat a[PTP_ece_OI_Size]); 1480 » » » (*ce)[i].u.object.oi.ObjectCompressedSize = dtoh32a(&cur data[PTP_ece_OI_Size]);
1808 » » » ce[i].u.object.oi.Filename » » = strdup(((char* )&curdata[PTP_ece_OI_Name])); 1481 » » » (*ce)[i].u.object.oi.Filename » » = strdup(((char* )&curdata[PTP_ece_OI_Name]));
1809 1482
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); 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);
1811 break; 1484 break;
1812 case PTP_EC_CANON_EOS_AvailListChanged: { /* property desc */ 1485 case PTP_EC_CANON_EOS_AvailListChanged: { /* property desc */
1813 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop _Subtype]); 1486 uint32_t proptype = dtoh32a(&curdata[PTP_ece_Prop _Subtype]);
1814 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Pro p_Desc_Type]); 1487 uint32_t propxtype = dtoh32a(&curdata[PTP_ece_Pro p_Desc_Type]);
1815 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop _Desc_Count]); 1488 uint32_t propxcnt = dtoh32a(&curdata[PTP_ece_Prop _Desc_Count]);
1816 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data ]; 1489 unsigned char *xdata = &curdata[PTP_ece_Prop_Desc_Data ];
1817 » » » unsigned int» j; 1490 » » » int» » j;
1818 PTPDevicePropDesc *dpd; 1491 PTPDevicePropDesc *dpd;
1819 1492
1820 ptp_debug (params, "event %d: EOS prop %04x desc record, datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype ); 1493 ptp_debug (params, "event %d: EOS prop %04x desc record, datasize %d, propxtype %d", i, proptype, size-PTP_ece_Prop_Desc_Data, propxtype );
1821 for (j=0;j<params->nrofcanon_props;j++) 1494 for (j=0;j<params->nrofcanon_props;j++)
1822 if (params->canon_props[j].proptype == proptype) 1495 if (params->canon_props[j].proptype == proptype)
1823 break; 1496 break;
1824 if (j==params->nrofcanon_props) { 1497 if (j==params->nrofcanon_props) {
1825 ptp_debug (params, "event %d: propdesc %x, defau lt value not found.", i, proptype); 1498 ptp_debug (params, "event %d: propdesc %x, defau lt value not found.", i, proptype);
1826 break; 1499 break;
1827 } 1500 }
1828 dpd = &params->canon_props[j].dpd; 1501 dpd = &params->canon_props[j].dpd;
1829 /* 1 - uint16 ? 1502 /* 1 - uint16 ?
1830 * 3 - uint16 1503 * 3 - uint16
1831 * 7 - string? 1504 * 7 - string?
1832 */ 1505 */
1833 if (propxtype != 3) { 1506 if (propxtype != 3) {
1834 ptp_debug (params, "event %d: propxtype is %x fo r %04x, unhandled.", i, propxtype, proptype); 1507 ptp_debug (params, "event %d: propxtype is %x fo r %04x, unhandled.", i, propxtype, proptype);
1835 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++) 1508 for (j=0;j<size-PTP_ece_Prop_Desc_Data;j++)
1836 ptp_debug (params, " %d: %02x", j, xd ata[j]); 1509 ptp_debug (params, " %d: %02x", j, xd ata[j]);
1837 break; 1510 break;
1838 } 1511 }
1839 if (! propxcnt) 1512 if (! propxcnt)
1840 break; 1513 break;
1841 if (propxcnt >= 2<<16) /* buggy or exploit */
1842 break;
1843 1514
1844 ptp_debug (params, "event %d: propxtype is %x, prop is 0 x%04x, data type is 0x%04x, propxcnt is %d.", 1515 ptp_debug (params, "event %d: propxtype is %x, prop is 0 x%04x, data type is 0x%04x, propxcnt is %d.",
1845 i, propxtype, proptype, dpd->DataType, propxc nt); 1516 i, propxtype, proptype, dpd->DataType, propxc nt);
1846 dpd->FormFlag = PTP_DPFF_Enumeration; 1517 dpd->FormFlag = PTP_DPFF_Enumeration;
1847 dpd->FORM.Enum.NumberOfValues = propxcnt; 1518 dpd->FORM.Enum.NumberOfValues = propxcnt;
1848 » » » free (dpd->FORM.Enum.SupportedValue); 1519 » » » if (dpd->FORM.Enum.SupportedValue) free (dpd->FORM.Enum. SupportedValue);
1849 dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPrope rtyValue)*propxcnt); 1520 dpd->FORM.Enum.SupportedValue = malloc (sizeof (PTPPrope rtyValue)*propxcnt);
1850 1521
1851 switch (proptype) { 1522 switch (proptype) {
1852 case PTP_DPC_CANON_EOS_ImageFormat: 1523 case PTP_DPC_CANON_EOS_ImageFormat:
1853 case PTP_DPC_CANON_EOS_ImageFormatCF: 1524 case PTP_DPC_CANON_EOS_ImageFormatCF:
1854 case PTP_DPC_CANON_EOS_ImageFormatSD: 1525 case PTP_DPC_CANON_EOS_ImageFormatSD:
1855 case PTP_DPC_CANON_EOS_ImageFormatExtHD: 1526 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
1856 /* special handling of ImageFormat properties */ 1527 /* special handling of ImageFormat properties */
1857 for (j=0;j<propxcnt;j++) { 1528 for (j=0;j<propxcnt;j++) {
1858 dpd->FORM.Enum.SupportedValue[j].u16 = 1529 dpd->FORM.Enum.SupportedValue[j].u16 =
1859 » » » » » » » ptp_unpack_EOS_ImageForm at( params, &xdata ); 1530 » » » » » » » dtoh16( ptp_unpack_EOS_I mageFormat( params, &xdata ) );
1860 ptp_debug (params, "event %d: suppval[%d ] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16); 1531 ptp_debug (params, "event %d: suppval[%d ] of %x is 0x%x.", i, j, proptype, dpd->FORM.Enum.SupportedValue[j].u16);
1861 } 1532 }
1862 break; 1533 break;
1863 default: 1534 default:
1864 /* 'normal' enumerated types */ 1535 /* 'normal' enumerated types */
1865 switch (dpd->DataType) { 1536 switch (dpd->DataType) {
1866 #define XX( TYPE, CONV )\ 1537 #define XX( TYPE, CONV )\
1867 for (j=0;j<propxcnt;j++) { \ 1538 for (j=0;j<propxcnt;j++) { \
1868 dpd->FORM.Enum.SupportedValue[j] .TYPE = CONV(xdata); \ 1539 dpd->FORM.Enum.SupportedValue[j] .TYPE = CONV(xdata); \
1869 ptp_debug (params, "event %d: su ppval[%d] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \ 1540 ptp_debug (params, "event %d: su ppval[%d] of %x is 0x%x.", i, j, proptype, CONV(xdata)); \
(...skipping 10 matching lines...) Expand all
1880 ptp_debug (params ,"event %d: data type 0x%04x of %x unhandled, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata) ); 1551 ptp_debug (params ,"event %d: data type 0x%04x of %x unhandled, raw values:", i, dpd->DataType, proptype, dtoh32a(xdata) );
1881 for (j=0;j<(size-PTP_ece_Prop_Desc_Data) /4;j++, xdata+=4) /* 4 is good for propxtype 3 */ 1552 for (j=0;j<(size-PTP_ece_Prop_Desc_Data) /4;j++, xdata+=4) /* 4 is good for propxtype 3 */
1882 ptp_debug (params, " %3d: 0x% 8x", j, dtoh32a(xdata)); 1553 ptp_debug (params, " %3d: 0x% 8x", j, dtoh32a(xdata));
1883 break; 1554 break;
1884 } 1555 }
1885 } 1556 }
1886 break; 1557 break;
1887 } 1558 }
1888 case PTP_EC_CANON_EOS_PropValueChanged: 1559 case PTP_EC_CANON_EOS_PropValueChanged:
1889 if (size >= 0xc) { /* property info */ 1560 if (size >= 0xc) { /* property info */
1890 » » » » unsigned int j; 1561 » » » » int j;
1891 uint32_t proptype = dtoh32a(&curdata[PTP_ ece_Prop_Subtype]); 1562 uint32_t proptype = dtoh32a(&curdata[PTP_ ece_Prop_Subtype]);
1892 unsigned char *xdata = &curdata[PTP_ece_Prop_V al_Data]; 1563 unsigned char *xdata = &curdata[PTP_ece_Prop_V al_Data];
1893 PTPDevicePropDesc *dpd; 1564 PTPDevicePropDesc *dpd;
1894 1565
1895 ptp_debug (params, "event %d: EOS prop %04x info record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data); 1566 ptp_debug (params, "event %d: EOS prop %04x info record, datasize is %d", i, proptype, size-PTP_ece_Prop_Val_Data);
1896 for (j=0;j<params->nrofcanon_props;j++) 1567 for (j=0;j<params->nrofcanon_props;j++)
1897 if (params->canon_props[j].proptype == p roptype) 1568 if (params->canon_props[j].proptype == p roptype)
1898 break; 1569 break;
1899 if (j<params->nrofcanon_props) { 1570 if (j<params->nrofcanon_props) {
1900 if ( (params->canon_props[j].size != size) || 1571 if ( (params->canon_props[j].size != size) ||
1901 (memcmp(params->canon_props[j].d ata,xdata,size-PTP_ece_Prop_Val_Data))) { 1572 (memcmp(params->canon_props[j].d ata,xdata,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); 1573 params->canon_props[j].data = re alloc(params->canon_props[j].data,size-PTP_ece_Prop_Val_Data);
1903 memcpy (params->canon_props[j].d ata,xdata,size-PTP_ece_Prop_Val_Data); 1574 memcpy (params->canon_props[j].d ata,xdata,size-PTP_ece_Prop_Val_Data);
1904 } 1575 }
1905 } else { 1576 } else {
1906 if (j) 1577 if (j)
1907 params->canon_props = realloc(pa rams->canon_props, sizeof(params->canon_props[0])*(j+1)); 1578 params->canon_props = realloc(pa rams->canon_props, sizeof(params->canon_props[0])*(j+1));
1908 else 1579 else
1909 params->canon_props = malloc(siz eof(params->canon_props[0])); 1580 params->canon_props = malloc(siz eof(params->canon_props[0]));
1581 params->canon_props[j].type = type;
1910 params->canon_props[j].proptype = propty pe; 1582 params->canon_props[j].proptype = propty pe;
1911 params->canon_props[j].size = size; 1583 params->canon_props[j].size = size;
1912 params->canon_props[j].data = malloc(siz e-PTP_ece_Prop_Val_Data); 1584 params->canon_props[j].data = malloc(siz e-PTP_ece_Prop_Val_Data);
1913 memcpy(params->canon_props[j].data, xdat a, size-PTP_ece_Prop_Val_Data); 1585 memcpy(params->canon_props[j].data, xdat a, size-PTP_ece_Prop_Val_Data);
1914 memset (&params->canon_props[j].dpd,0,si zeof(params->canon_props[j].dpd)); 1586 memset (&params->canon_props[j].dpd,0,si zeof(params->canon_props[j].dpd));
1915 params->canon_props[j].dpd.GetSet = 1; 1587 params->canon_props[j].dpd.GetSet = 1;
1916 params->canon_props[j].dpd.FormFlag = PT P_DPFF_None; 1588 params->canon_props[j].dpd.FormFlag = PT P_DPFF_None;
1917 params->nrofcanon_props = j+1; 1589 params->nrofcanon_props = j+1;
1918 } 1590 }
1919 dpd = &params->canon_props[j].dpd; 1591 dpd = &params->canon_props[j].dpd;
1920 1592
1921 » » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY ; 1593 » » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPE RTY;
1922 » » » » ce[i].u.propid = proptype; 1594 » » » » (*ce)[i].u.propid = proptype;
1923 1595
1924 /* fix GetSet value */ 1596 /* fix GetSet value */
1925 switch (proptype) { 1597 switch (proptype) {
1926 #define XX(x) case PTP_DPC_CANON_##x: 1598 #define XX(x) case PTP_DPC_CANON_##x:
1927 XX(EOS_FocusMode) 1599 XX(EOS_FocusMode)
1928 XX(EOS_BatteryPower) 1600 XX(EOS_BatteryPower)
1929 XX(EOS_BatterySelect) 1601 XX(EOS_BatterySelect)
1930 XX(EOS_ModelID) 1602 XX(EOS_ModelID)
1931 XX(EOS_PTPExtensionVersion) 1603 XX(EOS_PTPExtensionVersion)
1932 XX(EOS_DPOFVersion) 1604 XX(EOS_DPOFVersion)
(...skipping 20 matching lines...) Expand all
1953 XX(EOS_LensName) 1625 XX(EOS_LensName)
1954 XX(EOS_LensID) 1626 XX(EOS_LensID)
1955 #undef XX 1627 #undef XX
1956 dpd->GetSet = PTP_DPGS_Get; 1628 dpd->GetSet = PTP_DPGS_Get;
1957 break; 1629 break;
1958 } 1630 }
1959 1631
1960 /* set DataType */ 1632 /* set DataType */
1961 switch (proptype) { 1633 switch (proptype) {
1962 case PTP_DPC_CANON_EOS_CameraTime: 1634 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 */
1965 case PTP_DPC_CANON_EOS_AvailableShots: 1635 case PTP_DPC_CANON_EOS_AvailableShots:
1966 case PTP_DPC_CANON_EOS_CaptureDestination: 1636 case PTP_DPC_CANON_EOS_CaptureDestination:
1967 case PTP_DPC_CANON_EOS_WhiteBalanceXA: 1637 case PTP_DPC_CANON_EOS_WhiteBalanceXA:
1968 case PTP_DPC_CANON_EOS_WhiteBalanceXB: 1638 case PTP_DPC_CANON_EOS_WhiteBalanceXB:
1969 case PTP_DPC_CANON_EOS_CurrentStorage: 1639 case PTP_DPC_CANON_EOS_CurrentStorage:
1970 case PTP_DPC_CANON_EOS_CurrentFolder: 1640 case PTP_DPC_CANON_EOS_CurrentFolder:
1971 case PTP_DPC_CANON_EOS_ShutterCounter: 1641 case PTP_DPC_CANON_EOS_ShutterCounter:
1972 case PTP_DPC_CANON_EOS_ModelID: 1642 case PTP_DPC_CANON_EOS_ModelID:
1973 case PTP_DPC_CANON_EOS_LensID: 1643 case PTP_DPC_CANON_EOS_LensID:
1974 case PTP_DPC_CANON_EOS_StroboFiring: 1644 case PTP_DPC_CANON_EOS_StroboFiring:
1975 case PTP_DPC_CANON_EOS_AFSelectFocusArea:
1976 case PTP_DPC_CANON_EOS_ContinousAFMode:
1977 dpd->DataType = PTP_DTC_UINT32; 1645 dpd->DataType = PTP_DTC_UINT32;
1978 break; 1646 break;
1979 /* enumeration for AEM is never provided, but is available to set */ 1647 /* enumeration for AEM is never provided, but is available to set */
1980 case PTP_DPC_CANON_EOS_AutoExposureMode: 1648 case PTP_DPC_CANON_EOS_AutoExposureMode:
1981 dpd->DataType = PTP_DTC_UINT16; 1649 dpd->DataType = PTP_DTC_UINT16;
1982 dpd->FormFlag = PTP_DPFF_Enumeration; 1650 dpd->FormFlag = PTP_DPFF_Enumeration;
1983 dpd->FORM.Enum.NumberOfValues = 0; 1651 dpd->FORM.Enum.NumberOfValues = 0;
1984 break; 1652 break;
1985 case PTP_DPC_CANON_EOS_Aperture: 1653 case PTP_DPC_CANON_EOS_Aperture:
1986 case PTP_DPC_CANON_EOS_ShutterSpeed: 1654 case PTP_DPC_CANON_EOS_ShutterSpeed:
1987 case PTP_DPC_CANON_EOS_ISOSpeed: 1655 case PTP_DPC_CANON_EOS_ISOSpeed:
1988 case PTP_DPC_CANON_EOS_FocusMode: 1656 case PTP_DPC_CANON_EOS_FocusMode:
1989 case PTP_DPC_CANON_EOS_ColorSpace: 1657 case PTP_DPC_CANON_EOS_ColorSpace:
1990 case PTP_DPC_CANON_EOS_BatteryPower: 1658 case PTP_DPC_CANON_EOS_BatteryPower:
1991 case PTP_DPC_CANON_EOS_BatterySelect: 1659 case PTP_DPC_CANON_EOS_BatterySelect:
1992 case PTP_DPC_CANON_EOS_PTPExtensionVersion: 1660 case PTP_DPC_CANON_EOS_PTPExtensionVersion:
1993 case PTP_DPC_CANON_EOS_DriveMode: 1661 case PTP_DPC_CANON_EOS_DriveMode:
1994 case PTP_DPC_CANON_EOS_AEB: 1662 case PTP_DPC_CANON_EOS_AEB:
1995 case PTP_DPC_CANON_EOS_BracketMode: 1663 case PTP_DPC_CANON_EOS_BracketMode:
1996 case PTP_DPC_CANON_EOS_QuickReviewTime: 1664 case PTP_DPC_CANON_EOS_QuickReviewTime:
1997 case PTP_DPC_CANON_EOS_EVFMode: 1665 case PTP_DPC_CANON_EOS_EVFMode:
1998 case PTP_DPC_CANON_EOS_EVFOutputDevice: 1666 case PTP_DPC_CANON_EOS_EVFOutputDevice:
1999 case PTP_DPC_CANON_EOS_AutoPowerOff:
2000 case PTP_DPC_CANON_EOS_EVFRecordStatus:
2001 dpd->DataType = PTP_DTC_UINT16; 1667 dpd->DataType = PTP_DTC_UINT16;
2002 break; 1668 break;
2003 case PTP_DPC_CANON_EOS_PictureStyle: 1669 case PTP_DPC_CANON_EOS_PictureStyle:
2004 case PTP_DPC_CANON_EOS_WhiteBalance: 1670 case PTP_DPC_CANON_EOS_WhiteBalance:
2005 case PTP_DPC_CANON_EOS_MeteringMode: 1671 case PTP_DPC_CANON_EOS_MeteringMode:
2006 » » » » case PTP_DPC_CANON_EOS_ExpCompensation: 1672 » » » » case PTP_DPC_CANON_EOS_ExpCompensation: /* actua lly int8 if you calculate */
2007 dpd->DataType = PTP_DTC_UINT8; 1673 dpd->DataType = PTP_DTC_UINT8;
2008 break; 1674 break;
2009 case PTP_DPC_CANON_EOS_Owner: 1675 case PTP_DPC_CANON_EOS_Owner:
2010 case PTP_DPC_CANON_EOS_Artist: 1676 case PTP_DPC_CANON_EOS_Artist:
2011 case PTP_DPC_CANON_EOS_Copyright: 1677 case PTP_DPC_CANON_EOS_Copyright:
2012 case PTP_DPC_CANON_EOS_SerialNumber: 1678 case PTP_DPC_CANON_EOS_SerialNumber:
2013 case PTP_DPC_CANON_EOS_LensName: 1679 case PTP_DPC_CANON_EOS_LensName:
2014 dpd->DataType = PTP_DTC_STR; 1680 dpd->DataType = PTP_DTC_STR;
2015 break; 1681 break;
2016 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA: 1682 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustA:
2017 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB: 1683 case PTP_DPC_CANON_EOS_WhiteBalanceAdjustB:
2018 dpd->DataType = PTP_DTC_INT16; 1684 dpd->DataType = PTP_DTC_INT16;
2019 break; 1685 break;
2020 /* unknown props, listed from dump.... all 16 bi t, but vals might be smaller */ 1686 /* unknown props, listed from dump.... all 16 bi t, but vals might be smaller */
1687 case 0xd114:
2021 case PTP_DPC_CANON_EOS_DPOFVersion: 1688 case PTP_DPC_CANON_EOS_DPOFVersion:
2022 dpd->DataType = PTP_DTC_UINT16; 1689 dpd->DataType = PTP_DTC_UINT16;
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); 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);
2024 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+ +) 1691 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+ +)
2025 ptp_debug (params, " %d: %02x ", j, xdata[j]); 1692 ptp_debug (params, " %d: %02x ", j, xdata[j]);
2026 break; 1693 break;
2027 case PTP_DPC_CANON_EOS_CustomFunc1: 1694 case PTP_DPC_CANON_EOS_CustomFunc1:
2028 case PTP_DPC_CANON_EOS_CustomFunc2: 1695 case PTP_DPC_CANON_EOS_CustomFunc2:
2029 case PTP_DPC_CANON_EOS_CustomFunc3: 1696 case PTP_DPC_CANON_EOS_CustomFunc3:
2030 case PTP_DPC_CANON_EOS_CustomFunc4: 1697 case PTP_DPC_CANON_EOS_CustomFunc4:
(...skipping 16 matching lines...) Expand all
2047 case PTP_DPC_CANON_EOS_WftStatus: 1714 case PTP_DPC_CANON_EOS_WftStatus:
2048 case PTP_DPC_CANON_EOS_LensStatus: 1715 case PTP_DPC_CANON_EOS_LensStatus:
2049 case PTP_DPC_CANON_EOS_CardExtension: 1716 case PTP_DPC_CANON_EOS_CardExtension:
2050 case PTP_DPC_CANON_EOS_TempStatus: 1717 case PTP_DPC_CANON_EOS_TempStatus:
2051 case PTP_DPC_CANON_EOS_PhotoStudioMode: 1718 case PTP_DPC_CANON_EOS_PhotoStudioMode:
2052 case PTP_DPC_CANON_EOS_DepthOfFieldPreview: 1719 case PTP_DPC_CANON_EOS_DepthOfFieldPreview:
2053 case PTP_DPC_CANON_EOS_EVFSharpness: 1720 case PTP_DPC_CANON_EOS_EVFSharpness:
2054 case PTP_DPC_CANON_EOS_EVFWBMode: 1721 case PTP_DPC_CANON_EOS_EVFWBMode:
2055 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs: 1722 case PTP_DPC_CANON_EOS_EVFClickWBCoeffs:
2056 case PTP_DPC_CANON_EOS_EVFColorTemp: 1723 case PTP_DPC_CANON_EOS_EVFColorTemp:
1724 case PTP_DPC_CANON_EOS_EVFRecordStatus:
2057 case PTP_DPC_CANON_EOS_ExposureSimMode: 1725 case PTP_DPC_CANON_EOS_ExposureSimMode:
2058 case PTP_DPC_CANON_EOS_LvAfSystem: 1726 case PTP_DPC_CANON_EOS_LvAfSystem:
2059 case PTP_DPC_CANON_EOS_MovSize: 1727 case PTP_DPC_CANON_EOS_MovSize:
2060 case PTP_DPC_CANON_EOS_DepthOfField: 1728 case PTP_DPC_CANON_EOS_DepthOfField:
2061 case PTP_DPC_CANON_EOS_LvViewTypeSelect: 1729 case PTP_DPC_CANON_EOS_LvViewTypeSelect:
2062 case PTP_DPC_CANON_EOS_AloMode:
2063 case PTP_DPC_CANON_EOS_Brightness:
2064 dpd->DataType = PTP_DTC_UINT32; 1730 dpd->DataType = PTP_DTC_UINT32;
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); 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);
2066 if ((size-PTP_ece_Prop_Val_Data) % sizeo f(uint32_t) != 0) 1732 if ((size-PTP_ece_Prop_Val_Data) % sizeo f(uint32_t) != 0)
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) ); 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) );
2068 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/ sizeof(uint32_t);j++) 1734 for (j=0;j<(size-PTP_ece_Prop_Val_Data)/ sizeof(uint32_t);j++)
2069 » » » » » » ptp_debug (params, " %d: 0x%8 x", j, dtoh32a(xdata+j*4)); 1735 » » » » » » ptp_debug (params, " %d: 0x%8 x", j, ((uint32_t*)xdata)[j]);
2070 break; 1736 break;
2071 /* ImageFormat properties have to be ignored her e, see special handling below */ 1737 /* ImageFormat properties have to be ignored her e, see special handling below */
2072 case PTP_DPC_CANON_EOS_ImageFormat: 1738 case PTP_DPC_CANON_EOS_ImageFormat:
2073 case PTP_DPC_CANON_EOS_ImageFormatCF: 1739 case PTP_DPC_CANON_EOS_ImageFormatCF:
2074 case PTP_DPC_CANON_EOS_ImageFormatSD: 1740 case PTP_DPC_CANON_EOS_ImageFormatSD:
2075 case PTP_DPC_CANON_EOS_ImageFormatExtHD: 1741 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2076 case PTP_DPC_CANON_EOS_CustomFuncEx: 1742 case PTP_DPC_CANON_EOS_CustomFuncEx:
2077 case PTP_DPC_CANON_EOS_FocusInfoEx:
2078 break; 1743 break;
2079 default: 1744 default:
2080 ptp_debug (params, "event %d: Unknown EO S property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data); 1745 ptp_debug (params, "event %d: Unknown EO S property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data);
2081 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+ +) 1746 for (j=0;j<size-PTP_ece_Prop_Val_Data;j+ +)
2082 ptp_debug (params, " %d: %02x ", j, xdata[j]); 1747 ptp_debug (params, " %d: %02x ", j, xdata[j]);
2083 break; 1748 break;
2084 } 1749 }
2085 switch (dpd->DataType) { 1750 switch (dpd->DataType) {
2086 case PTP_DTC_UINT32: 1751 case PTP_DTC_UINT32:
2087 dpd->FactoryDefaultValue.u32 = dtoh32 a(xdata); 1752 dpd->FactoryDefaultValue.u32 = dtoh32 a(xdata);
2088 dpd->CurrentValue.u32 = dtoh32 a(xdata); 1753 dpd->CurrentValue.u32 = dtoh32 a(xdata);
2089 ptp_debug (params ,"event %d: currentval ue of %x is %x", i, proptype, dpd->CurrentValue.u32); 1754 ptp_debug (params ,"event %d: currentval ue of %x is %x", i, proptype, dpd->CurrentValue.u32);
2090 break; 1755 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;
2096 case PTP_DTC_UINT16: 1756 case PTP_DTC_UINT16:
2097 dpd->FactoryDefaultValue.u16 = dtoh16 a(xdata); 1757 dpd->FactoryDefaultValue.u16 = dtoh16 a(xdata);
2098 dpd->CurrentValue.u16 = dtoh16 a(xdata); 1758 dpd->CurrentValue.u16 = dtoh16 a(xdata);
2099 ptp_debug (params,"event %d: currentvalu e of %x is %x", i, proptype, dpd->CurrentValue.u16); 1759 ptp_debug (params,"event %d: currentvalu e of %x is %x", i, proptype, dpd->CurrentValue.u16);
2100 break; 1760 break;
2101 case PTP_DTC_UINT8: 1761 case PTP_DTC_UINT8:
2102 dpd->FactoryDefaultValue.u8 = dtoh8a (xdata); 1762 dpd->FactoryDefaultValue.u8 = dtoh8a (xdata);
2103 dpd->CurrentValue.u8 = dtoh8a (xdata); 1763 dpd->CurrentValue.u8 = dtoh8a (xdata);
2104 ptp_debug (params,"event %d: currentvalu e of %x is %x", i, proptype, dpd->CurrentValue.u8); 1764 ptp_debug (params,"event %d: currentvalu e of %x is %x", i, proptype, dpd->CurrentValue.u8);
2105 break; 1765 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;
2111 case PTP_DTC_STR: { 1766 case PTP_DTC_STR: {
2112 #if 0 /* 5D MII and 400D aktually store plain ASCII in their string properties * / 1767 #if 0 /* 5D MII and 400D aktually store plain ASCII in their string properties * /
2113 uint8_t len = 0; 1768 uint8_t len = 0;
2114 dpd->FactoryDefaultValue.str = ptp_un pack_string(params, data, 0, &len); 1769 dpd->FactoryDefaultValue.str = ptp_un pack_string(params, data, 0, &len);
2115 dpd->CurrentValue.str = ptp_un pack_string(params, data, 0, &len); 1770 dpd->CurrentValue.str = ptp_un pack_string(params, data, 0, &len);
2116 #else 1771 #else
2117 » » » » » free (dpd->FactoryDefaultValue.str); 1772 » » » » » if (dpd->FactoryDefaultValue.str) free ( dpd->FactoryDefaultValue.str);
2118 dpd->FactoryDefaultValue.str = strdup ( (char*)xdata ); 1773 dpd->FactoryDefaultValue.str = strdup ( (char*)xdata );
2119 1774
2120 » » » » » free (dpd->CurrentValue.str); 1775 » » » » » if (dpd->CurrentValue.str) free (dpd->Cu rrentValue.str);
2121 dpd->CurrentValue.str = strdup ( (char*)xdata ); 1776 dpd->CurrentValue.str = strdup ( (char*)xdata );
2122 #endif 1777 #endif
2123 ptp_debug (params,"event %d: currentvalu e of %x is %s", i, proptype, dpd->CurrentValue.str); 1778 ptp_debug (params,"event %d: currentvalu e of %x is %s", i, proptype, dpd->CurrentValue.str);
2124 break; 1779 break;
2125 } 1780 }
2126 default: 1781 default:
2127 /* debug is printed in switch above this one */ 1782 /* debug is printed in switch above this one */
2128 break; 1783 break;
2129 } 1784 }
2130 1785
2131 /* ImageFormat and customFuncEx special handling (WARNING: dont move this in front of the dpd->DataType switch!) */ 1786 /* ImageFormat and customFuncEx special handling (WARNING: dont move this in front of the dpd->DataType switch!) */
2132 switch (proptype) { 1787 switch (proptype) {
2133 case PTP_DPC_CANON_EOS_ImageFormat: 1788 case PTP_DPC_CANON_EOS_ImageFormat:
2134 case PTP_DPC_CANON_EOS_ImageFormatCF: 1789 case PTP_DPC_CANON_EOS_ImageFormatCF:
2135 case PTP_DPC_CANON_EOS_ImageFormatSD: 1790 case PTP_DPC_CANON_EOS_ImageFormatSD:
2136 case PTP_DPC_CANON_EOS_ImageFormatExtHD: 1791 case PTP_DPC_CANON_EOS_ImageFormatExtHD:
2137 dpd->DataType = PTP_DTC_UINT16; 1792 dpd->DataType = PTP_DTC_UINT16;
2138 dpd->FactoryDefaultValue.u16 = ptp_un pack_EOS_ImageFormat( params, &xdata ); 1793 dpd->FactoryDefaultValue.u16 = ptp_un pack_EOS_ImageFormat( params, &xdata );
2139 dpd->CurrentValue.u16 = dpd->F actoryDefaultValue.u16; 1794 dpd->CurrentValue.u16 = dpd->F actoryDefaultValue.u16;
2140 ptp_debug (params,"event %d: decoded ima geformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16); 1795 ptp_debug (params,"event %d: decoded ima geformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
2141 break; 1796 break;
2142 case PTP_DPC_CANON_EOS_CustomFuncEx: 1797 case PTP_DPC_CANON_EOS_CustomFuncEx:
2143 dpd->DataType = PTP_DTC_STR; 1798 dpd->DataType = PTP_DTC_STR;
2144 » » » » » free (dpd->FactoryDefaultValue.str); 1799 » » » » » if (dpd->FactoryDefaultValue.str) free ( dpd->FactoryDefaultValue.str);
2145 » » » » » free (dpd->CurrentValue.str); 1800 » » » » » if (dpd->CurrentValue.str)» free ( dpd->CurrentValue.str);
2146 » » » » » dpd->FactoryDefaultValue.str» = ptp_un pack_EOS_CustomFuncEx( params, &xdata ); 1801 » » » » » dpd->FactoryDefaultValue.str» = ptp_un pack_EOS_CustomFuncEx( params, &data );
2147 dpd->CurrentValue.str = strdup ( (char*)dpd->FactoryDefaultValue.str ); 1802 dpd->CurrentValue.str = strdup ( (char*)dpd->FactoryDefaultValue.str );
2148 ptp_debug (params,"event %d: decoded cus tom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str); 1803 ptp_debug (params,"event %d: decoded cus tom function, currentvalue of %x is %s", i, proptype, dpd->CurrentValue.str);
2149 break; 1804 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;
2158 } 1805 }
2159 1806
2160 break; 1807 break;
2161 } 1808 }
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 }
2367 case PTP_EC_CANON_EOS_CameraStatusChanged: 1809 case PTP_EC_CANON_EOS_CameraStatusChanged:
2368 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS; 1810 » » » ptp_debug (params, "event %d: EOS event CameraStatusChan ged (size %d)", i, size);
2369 » » » ce[i].u.status = dtoh32a(curdata+8); 1811 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS;
2370 » » » ptp_debug (params, "event %d: EOS event CameraStatusChan ged (size %d) = %d", i, size, dtoh32a(curdata+8)); 1812 » » » (*ce)[i].u.status = dtoh32a(curdata+8);
2371 params->eos_camerastatus = dtoh32a(curdata+8); 1813 params->eos_camerastatus = dtoh32a(curdata+8);
2372 break; 1814 break;
2373 case 0: /* end marker */ 1815 case 0: /* end marker */
2374 if (size == 8) /* no output */ 1816 if (size == 8) /* no output */
2375 break; 1817 break;
2376 ptp_debug (params, "event %d: EOS event 0, but size %d", i, size); 1818 ptp_debug (params, "event %d: EOS event 0, but size %d", i, size);
2377 break; 1819 break;
2378 case PTP_EC_CANON_EOS_BulbExposureTime: 1820 case PTP_EC_CANON_EOS_BulbExposureTime:
2379 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; 1821 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2380 » » » ce[i].u.info = malloc(strlen("BulbExposureTime 123456789 ")); 1822 » » » (*ce)[i].u.info = malloc(strlen("BulbExposureTime 123456 789"));
2381 » » » sprintf (ce[i].u.info, "BulbExposureTime %d", dtoh32a(c urdata+8)); 1823 » » » sprintf ((*ce)[i].u.info, "BulbExposureTime %d", dtoh32 a(curdata+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);
2386 break; 1824 break;
2387 default: 1825 default:
2388 switch (type) { 1826 switch (type) {
2389 #define XX(x) case PTP_EC_CANON_EOS_##x: \ 1827 #define XX(x) case PTP_EC_CANON_EOS_##x: \
2390 ptp_debug (params, "event %d: unhandled EOS even t "#x" (size %d)", i, size); \ 1828 ptp_debug (params, "event %d: unhandled EOS even t "#x" (size %d)", i, size); \
2391 » » » » ce[i].u.info = malloc(strlen("unhandled EOS even t "#x" (size 123456789)"));» \ 1829 » » » » (*ce)[i].u.info = malloc(strlen("unhandled EOS e vent "#x" (size 123456789)"));» \
2392 » » » » sprintf (ce[i].u.info, "unhandled EOS event "#x" (size %d)", size);» » \ 1830 » » » » sprintf ((*ce)[i].u.info, "unhandled EOS event " #x" (size %d)", size);»» \
2393 break; 1831 break;
2394 XX(RequestGetEvent) 1832 XX(RequestGetEvent)
1833 XX(ObjectRemoved)
2395 XX(RequestGetObjectInfoEx) 1834 XX(RequestGetObjectInfoEx)
2396 XX(StorageStatusChanged) 1835 XX(StorageStatusChanged)
2397 XX(StorageInfoChanged) 1836 XX(StorageInfoChanged)
2398 XX(ObjectInfoChangedEx) 1837 XX(ObjectInfoChangedEx)
2399 XX(ObjectContentChanged) 1838 XX(ObjectContentChanged)
2400 XX(WillSoonShutdown) 1839 XX(WillSoonShutdown)
2401 XX(ShutdownTimerUpdated) 1840 XX(ShutdownTimerUpdated)
2402 XX(RequestCancelTransfer) 1841 XX(RequestCancelTransfer)
2403 XX(RequestObjectTransferDT) 1842 XX(RequestObjectTransferDT)
2404 XX(RequestCancelTransferDT) 1843 XX(RequestCancelTransferDT)
2405 XX(StoreAdded) 1844 XX(StoreAdded)
2406 XX(StoreRemoved) 1845 XX(StoreRemoved)
2407 XX(BulbExposureTime) 1846 XX(BulbExposureTime)
2408 XX(RecordingTime) 1847 XX(RecordingTime)
2409 XX(RequestObjectTransferTS) 1848 XX(RequestObjectTransferTS)
2410 XX(AfResult) 1849 XX(AfResult)
2411 #undef XX 1850 #undef XX
2412 default: 1851 default:
2413 ptp_debug (params, "event %d: unknown EOS event %04x", i, type); 1852 ptp_debug (params, "event %d: unknown EOS event %04x", i, type);
2414 break; 1853 break;
2415 } 1854 }
2416 if (size >= 0x8) { /* event info */ 1855 if (size >= 0x8) { /* event info */
2417 » » » » unsigned int j; 1856 » » » » int j;
2418 for (j=8;j<size;j++) 1857 for (j=8;j<size;j++)
2419 ptp_debug (params, " %d: %02x", j, cu rdata[j]); 1858 ptp_debug (params, " %d: %02x", j, cu rdata[j]);
2420 } 1859 }
2421 » » » ce[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN; 1860 » » » (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
2422 break; 1861 break;
2423 } 1862 }
2424 curdata += size; 1863 curdata += size;
1864 i++;
2425 if ((size == 8) && (type == 0)) 1865 if ((size == 8) && (type == 0))
2426 break; 1866 break;
2427 i++;
2428 } 1867 }
2429 » if (!i) { 1868 » if (!entries) {
2430 » » free (ce); 1869 » » free (*ce);
2431 » » ce = NULL; 1870 » » *ce = NULL;
2432 } 1871 }
2433 » *pce = ce; 1872 » return entries;
2434 » return i;
2435 } 1873 }
2436 1874
2437 /* 1875 /*
2438 PTP USB Event container unpack for Nikon events. 1876 PTP USB Event container unpack for Nikon events.
2439 */ 1877 */
2440 #define PTP_nikon_ec_Length 0 1878 #define PTP_nikon_ec_Length 0
2441 #define PTP_nikon_ec_Code 2 1879 #define PTP_nikon_ec_Code 2
2442 #define PTP_nikon_ec_Param1 4 1880 #define PTP_nikon_ec_Param1 4
2443 #define PTP_nikon_ec_Size 6 1881 #define PTP_nikon_ec_Size 6
2444 static inline void 1882 static inline void
2445 ptp_unpack_Nikon_EC (PTPParams *params, unsigned char* data, unsigned int len, P TPContainer **ec, unsigned int *cnt) 1883 ptp_unpack_Nikon_EC (PTPParams *params, unsigned char* data, unsigned int len, P TPContainer **ec, int *cnt)
2446 { 1884 {
2447 » unsigned int i; 1885 » int i;
2448 1886
2449 *ec = NULL; 1887 *ec = NULL;
2450 if (data == NULL) 1888 if (data == NULL)
2451 return; 1889 return;
2452 if (len < PTP_nikon_ec_Code) 1890 if (len < PTP_nikon_ec_Code)
2453 return; 1891 return;
2454 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]); 1892 *cnt = dtoh16a(&data[PTP_nikon_ec_Length]);
2455 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) /* broken cnt? */ 1893 if (*cnt > (len-PTP_nikon_ec_Code)/PTP_nikon_ec_Size) /* broken cnt? */
2456 return; 1894 return;
2457 if (!*cnt) 1895 if (!*cnt)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 PTPObjectHandles *handles, 1979 PTPObjectHandles *handles,
2542 PTPObjectInfo **oinfos, /* size(handles->n) */ 1980 PTPObjectInfo **oinfos, /* size(handles->n) */
2543 uint32_t **flags /* size(handles->n) */ 1981 uint32_t **flags /* size(handles->n) */
2544 ) { 1982 ) {
2545 unsigned int i, j, nrofobs = 0, curob = 0; 1983 unsigned int i, j, nrofobs = 0, curob = 0;
2546 1984
2547 #define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff) 1985 #define ISOBJECT(ptr) (dtoh32a((ptr)+ptp_canon_dir_storageid) == 0xffffffff)
2548 for (i=0;i<cnt;i++) 1986 for (i=0;i<cnt;i++)
2549 if (ISOBJECT(dir+i*0x4c)) nrofobs++; 1987 if (ISOBJECT(dir+i*0x4c)) nrofobs++;
2550 handles->n = nrofobs; 1988 handles->n = nrofobs;
2551 » handles->Handler = calloc(nrofobs,sizeof(handles->Handler[0])); 1989 » handles->Handler = calloc(sizeof(handles->Handler[0]),nrofobs);
2552 if (!handles->Handler) return PTP_RC_GeneralError; 1990 if (!handles->Handler) return PTP_RC_GeneralError;
2553 » *oinfos = calloc(nrofobs,sizeof((*oinfos)[0])); 1991 » *oinfos = calloc(sizeof((*oinfos)[0]),nrofobs);
2554 if (!*oinfos) return PTP_RC_GeneralError; 1992 if (!*oinfos) return PTP_RC_GeneralError;
2555 » *flags = calloc(nrofobs,sizeof((*flags)[0])); 1993 » *flags = calloc(sizeof((*flags)[0]),nrofobs);
2556 if (!*flags) return PTP_RC_GeneralError; 1994 if (!*flags) return PTP_RC_GeneralError;
2557 1995
2558 /* Migrate data into objects ids, handles into 1996 /* Migrate data into objects ids, handles into
2559 * the object handler array. 1997 * the object handler array.
2560 */ 1998 */
2561 curob = 0; 1999 curob = 0;
2562 for (i=0;i<cnt;i++) { 2000 for (i=0;i<cnt;i++) {
2563 unsigned char *cur = dir+i*0x4c; 2001 unsigned char *cur = dir+i*0x4c;
2564 PTPObjectInfo *oi = (*oinfos)+curob; 2002 PTPObjectInfo *oi = (*oinfos)+curob;
2565 2003
(...skipping 20 matching lines...) Expand all
2586 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchil d); 2024 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_nextchil d);
2587 2025
2588 if (ISOBJECT(cur)) 2026 if (ISOBJECT(cur))
2589 continue; 2027 continue;
2590 for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j]) break; 2028 for (j=0;j<handles->n;j++) if (nextchild == handles->Handler[j]) break;
2591 if (j == handles->n) continue; 2029 if (j == handles->n) continue;
2592 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid); 2030 (*oinfos)[j].StorageID = dtoh32a(cur + ptp_canon_dir_storageid);
2593 } 2031 }
2594 /* Walk over all objects and distribute the storage ids */ 2032 /* Walk over all objects and distribute the storage ids */
2595 while (1) { 2033 while (1) {
2596 » » unsigned int changed = 0; 2034 » » int changed = 0;
2597 for (i=0;i<cnt;i++) { 2035 for (i=0;i<cnt;i++) {
2598 unsigned char *cur = dir+i*0x4c; 2036 unsigned char *cur = dir+i*0x4c;
2599 uint32_t oid = dtoh32a(cur + ptp_canon_dir_object id); 2037 uint32_t oid = dtoh32a(cur + ptp_canon_dir_object id);
2600 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_ne xtid); 2038 uint32_t nextoid = dtoh32a(cur + ptp_canon_dir_ne xtid);
2601 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_ nextchild); 2039 uint32_t nextchild = dtoh32a(cur + ptp_canon_dir_ nextchild);
2602 uint32_t storageid; 2040 uint32_t storageid;
2603 2041
2604 if (!ISOBJECT(cur)) 2042 if (!ISOBJECT(cur))
2605 continue; 2043 continue;
2606 for (j=0;j<handles->n;j++) if (oid == handles->Handler[j ]) break; 2044 for (j=0;j<handles->n;j++) if (oid == handles->Handler[j ]) break;
(...skipping 30 matching lines...) Expand all
2637 * - changed no entry (nothing more to do) 2075 * - changed no entry (nothing more to do)
2638 * - changed all of them at once (usually happens) 2076 * - changed all of them at once (usually happens)
2639 * break if we do. 2077 * break if we do.
2640 */ 2078 */
2641 if (!changed || (changed==nrofobs-1)) 2079 if (!changed || (changed==nrofobs-1))
2642 break; 2080 break;
2643 } 2081 }
2644 #undef ISOBJECT 2082 #undef ISOBJECT
2645 return PTP_RC_OK; 2083 return PTP_RC_OK;
2646 } 2084 }
OLDNEW
« no previous file with comments | « src/ptp.c ('k') | src/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698