blob: 16a97d83c12e3342e7fa059699196df5f27b3176 [file] [log] [blame]
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001/* ptp.c
2 *
Linus Walleijb02a0662006-04-25 08:05:09 +00003 * Copyright (C) 2001-2004 Mariusz Woloszyn <emsi@ipartners.pl>
4 * Copyright (C) 2003-2006 Marcus Meissner <marcus@jet.franken.de>
Linus Walleija823a702006-08-27 21:27:46 +00005 * Copyright (C) 2006 Linus Walleij <triad@df.lth.se>
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00006 *
Linus Walleijb02a0662006-04-25 08:05:09 +00007 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000011 *
Linus Walleijb02a0662006-04-25 08:05:09 +000012 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000016 *
Linus Walleijb02a0662006-04-25 08:05:09 +000017 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000021 */
22
Linus Walleij784ac3f2006-12-29 10:36:51 +000023#define _BSD_SOURCE
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000024#include <config.h>
25#include "ptp.h"
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000026
27#include <stdlib.h>
28#include <stdarg.h>
29#include <stdio.h>
30#include <string.h>
Linus Walleij96c62432006-08-21 10:04:02 +000031#include <unistd.h>
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000032
33#ifdef ENABLE_NLS
34# include <libintl.h>
35# undef _
36# define _(String) dgettext (PACKAGE, String)
37# ifdef gettext_noop
38# define N_(String) gettext_noop (String)
39# else
40# define N_(String) (String)
41# endif
42#else
43# define textdomain(String) (String)
44# define gettext(String) (String)
45# define dgettext(Domain,Message) (Message)
46# define dcgettext(Domain,Message,Type) (Message)
47# define bindtextdomain(Domain,Directory) (Domain)
48# define _(String) (String)
49# define N_(String) (String)
50#endif
51
Linus Walleijb02a0662006-04-25 08:05:09 +000052#define CHECK_PTP_RC(result) {uint16_t r=(result); if (r!=PTP_RC_OK) return r;}
53
54#define PTP_CNT_INIT(cnt) {memset(&cnt,0,sizeof(cnt));}
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000055
Linus Walleij784ac3f2006-12-29 10:36:51 +000056static uint16_t ptp_exit_recv_memory_handler (PTPDataHandler*,unsigned char**,unsigned long*);
57static uint16_t ptp_init_recv_memory_handler(PTPDataHandler*);
58static uint16_t ptp_init_send_memory_handler(PTPDataHandler*,unsigned char*,unsigned long len);
59static uint16_t ptp_exit_send_memory_handler (PTPDataHandler *handler);
60
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000061static void
62ptp_debug (PTPParams *params, const char *format, ...)
63{
64 va_list args;
65
66 va_start (args, format);
67 if (params->debug_func!=NULL)
68 params->debug_func (params->data, format, args);
69 else
70 {
71 vfprintf (stderr, format, args);
72 fprintf (stderr,"\n");
73 fflush (stderr);
74 }
75 va_end (args);
76}
77
78static void
79ptp_error (PTPParams *params, const char *format, ...)
80{
81 va_list args;
82
83 va_start (args, format);
84 if (params->error_func!=NULL)
85 params->error_func (params->data, format, args);
86 else
87 {
88 vfprintf (stderr, format, args);
89 fprintf (stderr,"\n");
90 fflush (stderr);
91 }
92 va_end (args);
93}
94
Linus Walleijb02a0662006-04-25 08:05:09 +000095/* Pack / unpack functions */
96
97#include "ptp-pack.c"
98
Linus Walleijeb8c6fe2006-02-03 09:46:22 +000099/* major PTP functions */
100
Linus Walleijb02a0662006-04-25 08:05:09 +0000101/* Transaction data phase description */
102#define PTP_DP_NODATA 0x0000 /* no data phase */
103#define PTP_DP_SENDDATA 0x0001 /* sending data */
104#define PTP_DP_GETDATA 0x0002 /* receiving data */
105#define PTP_DP_DATA_MASK 0x00ff /* data phase mask */
106
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000107/**
108 * ptp_transaction:
109 * params: PTPParams*
110 * PTPContainer* ptp - general ptp container
111 * uint16_t flags - lower 8 bits - data phase description
112 * unsigned int sendlen - senddata phase data length
113 * char** data - send or receive data buffer pointer
Linus Walleijb02a0662006-04-25 08:05:09 +0000114 * int* recvlen - receive data length
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000115 *
116 * Performs PTP transaction. ptp is a PTPContainer with appropriate fields
117 * filled in (i.e. operation code and parameters). It's up to caller to do
118 * so.
119 * The flags decide thether the transaction has a data phase and what is its
120 * direction (send or receive).
121 * If transaction is sending data the sendlen should contain its length in
122 * bytes, otherwise it's ignored.
123 * The data should contain an address of a pointer to data going to be sent
124 * or is filled with such a pointer address if data are received depending
125 * od dataphase direction (send or received) or is beeing ignored (no
126 * dataphase).
127 * The memory for a pointer should be preserved by the caller, if data are
128 * beeing retreived the appropriate amount of memory is beeing allocated
129 * (the caller should handle that!).
130 *
131 * Return values: Some PTP_RC_* code.
132 * Upon success PTPContainer* ptp contains PTP Response Phase container with
133 * all fields filled in.
134 **/
Linus Walleijb02a0662006-04-25 08:05:09 +0000135static uint16_t
Linus Walleij784ac3f2006-12-29 10:36:51 +0000136ptp_transaction_new (PTPParams* params, PTPContainer* ptp,
137 uint16_t flags, unsigned int sendlen,
138 PTPDataHandler *handler
139) {
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000140 if ((params==NULL) || (ptp==NULL))
141 return PTP_ERROR_BADPARAM;
Linus Walleije7f44be2006-08-25 19:32:29 +0000142
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000143 ptp->Transaction_ID=params->transaction_id++;
144 ptp->SessionID=params->session_id;
145 /* send request */
146 CHECK_PTP_RC(params->sendreq_func (params, ptp));
147 /* is there a dataphase? */
148 switch (flags&PTP_DP_DATA_MASK) {
Linus Walleijb02a0662006-04-25 08:05:09 +0000149 case PTP_DP_SENDDATA:
150 CHECK_PTP_RC(params->senddata_func(params, ptp,
Linus Walleij784ac3f2006-12-29 10:36:51 +0000151 sendlen, handler));
Linus Walleijb02a0662006-04-25 08:05:09 +0000152 break;
153 case PTP_DP_GETDATA:
Linus Walleij784ac3f2006-12-29 10:36:51 +0000154 CHECK_PTP_RC(params->getdata_func(params, ptp, handler));
Linus Walleijb02a0662006-04-25 08:05:09 +0000155 break;
156 case PTP_DP_NODATA:
157 break;
158 default:
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000159 return PTP_ERROR_BADPARAM;
160 }
161 /* get response */
162 CHECK_PTP_RC(params->getresp_func(params, ptp));
Linus Walleij7347d0f2006-10-23 07:23:39 +0000163 if (ptp->Transaction_ID != params->transaction_id-1) {
164 ptp_error (params,
165 "PTP: Sequence number mismatch %d vs expected %d.",
166 ptp->Transaction_ID, params->transaction_id-1
167 );
168 return PTP_ERROR_BADPARAM;
169 }
Linus Walleijb02a0662006-04-25 08:05:09 +0000170 return ptp->Code;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000171}
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000172
Linus Walleij784ac3f2006-12-29 10:36:51 +0000173/* memory data get/put handler */
174typedef struct {
175 unsigned char *data;
176 unsigned long size, curoff;
177} PTPMemHandlerPrivate;
178
179static uint16_t
180memory_getfunc(PTPParams* params, void* private,
181 unsigned long wantlen, unsigned char *data,
182 unsigned long *gotlen
183) {
184 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
185 unsigned long tocopy = wantlen;
186
187 if (priv->curoff + tocopy > priv->size)
188 tocopy = priv->size - priv->curoff;
189 memcpy (data, priv->data + priv->curoff, tocopy);
190 priv->curoff += tocopy;
191 *gotlen = tocopy;
192 return PTP_RC_OK;
193}
194
195static uint16_t
196memory_putfunc(PTPParams* params, void* private,
197 unsigned long sendlen, unsigned char *data,
198 unsigned long *putlen
199) {
200 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
201
202 if (priv->curoff + sendlen > priv->size) {
203 priv->data = realloc (priv->data, priv->curoff+sendlen);
204 priv->size = priv->curoff + sendlen;
205 }
206 memcpy (priv->data + priv->curoff, data, sendlen);
207 priv->curoff += sendlen;
208 *putlen = sendlen;
209 return PTP_RC_OK;
210}
211
212/* init private struct for receiving data. */
213static uint16_t
214ptp_init_recv_memory_handler(PTPDataHandler *handler) {
215 PTPMemHandlerPrivate* priv;
216 priv = malloc (sizeof(PTPMemHandlerPrivate));
217 handler->private = priv;
218 handler->getfunc = memory_getfunc;
219 handler->putfunc = memory_putfunc;
220 priv->data = NULL;
221 priv->size = 0;
222 priv->curoff = 0;
223 return PTP_RC_OK;
224}
225
226/* init private struct and put data in for sending data.
227 * data is still owned by caller.
228 */
229static uint16_t
230ptp_init_send_memory_handler(PTPDataHandler *handler,
231 unsigned char *data, unsigned long len
232) {
233 PTPMemHandlerPrivate* priv;
234 priv = malloc (sizeof(PTPMemHandlerPrivate));
235 if (!priv)
236 return PTP_RC_GeneralError;
237 handler->private = priv;
238 handler->getfunc = memory_getfunc;
239 handler->putfunc = memory_putfunc;
240 priv->data = data;
241 priv->size = len;
242 priv->curoff = 0;
243 return PTP_RC_OK;
244}
245
246/* free private struct + data */
247static uint16_t
248ptp_exit_send_memory_handler (PTPDataHandler *handler) {
249 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->private;
250 /* data is owned by caller */
251 free (priv);
252 return PTP_RC_OK;
253}
254
255/* hand over our internal data to caller */
256static uint16_t
257ptp_exit_recv_memory_handler (PTPDataHandler *handler,
258 unsigned char **data, unsigned long *size
259) {
260 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->private;
261 *data = priv->data;
262 *size = priv->size;
263 free (priv);
264 return PTP_RC_OK;
265}
266
267/* fd data get/put handler */
268typedef struct {
269 int fd;
270} PTPFDHandlerPrivate;
271
272static uint16_t
273fd_getfunc(PTPParams* params, void* private,
274 unsigned long wantlen, unsigned char *data,
275 unsigned long *gotlen
276) {
277 PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)private;
278 int got;
279
280 got = read (priv->fd, data, wantlen);
281 if (got != -1)
282 *gotlen = got;
283 else
284 return PTP_RC_GeneralError;
285 return PTP_RC_OK;
286}
287
288static uint16_t
289fd_putfunc(PTPParams* params, void* private,
290 unsigned long sendlen, unsigned char *data,
291 unsigned long *putlen
292) {
293 int written;
294 PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)private;
295
296 written = write (priv->fd, data, sendlen);
297 if (written != -1)
298 *putlen = written;
299 else
300 return PTP_RC_GeneralError;
301 return PTP_RC_OK;
302}
303
304static uint16_t
305ptp_init_fd_handler(PTPDataHandler *handler, int fd) {
306 PTPFDHandlerPrivate* priv;
307 priv = malloc (sizeof(PTPFDHandlerPrivate));
308 handler->private = priv;
309 handler->getfunc = fd_getfunc;
310 handler->putfunc = fd_putfunc;
311 priv->fd = fd;
312 return PTP_RC_OK;
313}
314
315static uint16_t
316ptp_exit_fd_handler (PTPDataHandler *handler) {
317 PTPFDHandlerPrivate* priv = (PTPFDHandlerPrivate*)handler->private;
318 close (priv->fd);
319 free (priv);
320 return PTP_RC_OK;
321}
322
323/* Old style transaction, based on memory */
324static uint16_t
325ptp_transaction (PTPParams* params, PTPContainer* ptp,
326 uint16_t flags, unsigned int sendlen,
327 unsigned char **data, unsigned int *recvlen
328) {
329 PTPDataHandler handler;
330 uint16_t ret;
331
332 switch (flags & PTP_DP_DATA_MASK) {
333 case PTP_DP_SENDDATA:
334 ptp_init_send_memory_handler (&handler, *data, sendlen);
335 break;
336 case PTP_DP_GETDATA:
337 ptp_init_recv_memory_handler (&handler);
338 break;
339 default:break;
340 }
341 ret = ptp_transaction_new (params, ptp, flags, sendlen, &handler);
342 switch (flags & PTP_DP_DATA_MASK) {
343 case PTP_DP_SENDDATA:
344 ptp_exit_send_memory_handler (&handler);
345 break;
346 case PTP_DP_GETDATA: {
347 unsigned long len;
348 ptp_exit_recv_memory_handler (&handler, data, &len);
349 if (recvlen)
350 *recvlen = len;
351 break;
352 }
353 default:break;
354 }
355 return ret;
356}
357
358
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000359/**
360 * PTP operation functions
361 *
362 * all ptp_ functions should take integer parameters
363 * in host byte order!
364 **/
365
366
367/**
368 * ptp_getdeviceinfo:
369 * params: PTPParams*
370 *
371 * Gets device info dataset and fills deviceinfo structure.
372 *
373 * Return values: Some PTP_RC_* code.
374 **/
375uint16_t
376ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo)
377{
Linus Walleij784ac3f2006-12-29 10:36:51 +0000378 uint16_t ret;
379 unsigned long len;
380 PTPContainer ptp;
381 unsigned char* di=NULL;
382 PTPDataHandler handler;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000383
Linus Walleij784ac3f2006-12-29 10:36:51 +0000384 ptp_init_recv_memory_handler (&handler);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000385 PTP_CNT_INIT(ptp);
386 ptp.Code=PTP_OC_GetDeviceInfo;
387 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +0000388 len=0;
Linus Walleij784ac3f2006-12-29 10:36:51 +0000389 ret=ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, &handler);
390 ptp_exit_recv_memory_handler (&handler, &di, &len);
Linus Walleijb02a0662006-04-25 08:05:09 +0000391 if (ret == PTP_RC_OK) ptp_unpack_DI(params, di, deviceinfo, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000392 free(di);
393 return ret;
394}
395
396
397/**
398 * ptp_opensession:
399 * params: PTPParams*
400 * session - session number
401 *
402 * Establishes a new session.
403 *
404 * Return values: Some PTP_RC_* code.
405 **/
406uint16_t
407ptp_opensession (PTPParams* params, uint32_t session)
408{
409 uint16_t ret;
410 PTPContainer ptp;
411
412 ptp_debug(params,"PTP: Opening session");
413
414 /* SessonID field of the operation dataset should always
415 be set to 0 for OpenSession request! */
416 params->session_id=0x00000000;
417 /* TransactionID should be set to 0 also! */
418 params->transaction_id=0x0000000;
Linus Walleijc3e8a432006-12-01 22:17:40 +0000419 /* zero out response packet buffer */
420 params->response_packet = NULL;
421 params->response_packet_size = 0;
Linus Walleijc70a6df2007-01-01 22:19:08 +0000422 /* no split headers */
423 params->split_header_data = 0;
Linus Walleij0fa47022007-01-03 08:21:23 +0000424
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000425
426 PTP_CNT_INIT(ptp);
427 ptp.Code=PTP_OC_OpenSession;
428 ptp.Param1=session;
429 ptp.Nparam=1;
Linus Walleij784ac3f2006-12-29 10:36:51 +0000430 ret=ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000431 /* now set the global session id to current session number */
432 params->session_id=session;
433 return ret;
434}
435
436/**
437 * ptp_closesession:
438 * params: PTPParams*
439 *
440 * Closes session.
441 *
442 * Return values: Some PTP_RC_* code.
443 **/
444uint16_t
445ptp_closesession (PTPParams* params)
446{
447 PTPContainer ptp;
448
449 ptp_debug(params,"PTP: Closing session");
450
Linus Walleijc3e8a432006-12-01 22:17:40 +0000451 /* free any dangling response packet */
452 if (params->response_packet_size > 0) {
453 free(params->response_packet);
454 params->response_packet = NULL;
455 params->response_packet_size = 0;
Linus Walleij33194242006-11-30 22:53:13 +0000456 }
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000457 PTP_CNT_INIT(ptp);
458 ptp.Code=PTP_OC_CloseSession;
459 ptp.Nparam=0;
Linus Walleij784ac3f2006-12-29 10:36:51 +0000460 return ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000461}
462
463/**
464 * ptp_getststorageids:
465 * params: PTPParams*
466 *
Linus Walleijb02a0662006-04-25 08:05:09 +0000467 * Gets array of StorageIDs and fills the storageids structure.
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000468 *
469 * Return values: Some PTP_RC_* code.
470 **/
471uint16_t
472ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids)
473{
474 uint16_t ret;
475 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000476 unsigned int len;
477 unsigned char* sids=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000478
479 PTP_CNT_INIT(ptp);
480 ptp.Code=PTP_OC_GetStorageIDs;
481 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +0000482 len=0;
483 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids, &len);
484 if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000485 free(sids);
486 return ret;
487}
488
489/**
490 * ptp_getststorageinfo:
491 * params: PTPParams*
492 * storageid - StorageID
493 *
494 * Gets StorageInfo dataset of desired storage and fills storageinfo
495 * structure.
496 *
497 * Return values: Some PTP_RC_* code.
498 **/
499uint16_t
500ptp_getstorageinfo (PTPParams* params, uint32_t storageid,
501 PTPStorageInfo* storageinfo)
502{
503 uint16_t ret;
504 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000505 unsigned char* si=NULL;
506 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000507
508 PTP_CNT_INIT(ptp);
509 ptp.Code=PTP_OC_GetStorageInfo;
510 ptp.Param1=storageid;
511 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000512 len=0;
513 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &si, &len);
514 if (ret == PTP_RC_OK) ptp_unpack_SI(params, si, storageinfo, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000515 free(si);
516 return ret;
517}
518
519/**
Linus Walleij13374a42006-09-13 11:55:30 +0000520 * ptp_formatstore:
521 * params: PTPParams*
522 * storageid - StorageID
523 *
524 * Formats the storage on the device.
525 *
526 * Return values: Some PTP_RC_* code.
527 **/
528uint16_t
529ptp_formatstore (PTPParams* params, uint32_t storageid)
530{
Linus Walleij13374a42006-09-13 11:55:30 +0000531 PTPContainer ptp;
532
533 PTP_CNT_INIT(ptp);
534 ptp.Code=PTP_OC_FormatStore;
535 ptp.Param1=storageid;
536 ptp.Param2=PTP_FST_Undefined;
537 ptp.Nparam=2;
Linus Walleij4f40d112006-09-21 07:44:53 +0000538 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleij13374a42006-09-13 11:55:30 +0000539}
540
541/**
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000542 * ptp_getobjecthandles:
543 * params: PTPParams*
544 * storage - StorageID
545 * objectformatcode - ObjectFormatCode (optional)
546 * associationOH - ObjectHandle of Association for
547 * wich a list of children is desired
548 * (optional)
549 * objecthandles - pointer to structute
550 *
551 * Fills objecthandles with structure returned by device.
552 *
553 * Return values: Some PTP_RC_* code.
554 **/
555uint16_t
556ptp_getobjecthandles (PTPParams* params, uint32_t storage,
557 uint32_t objectformatcode, uint32_t associationOH,
558 PTPObjectHandles* objecthandles)
559{
560 uint16_t ret;
561 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000562 unsigned char* oh=NULL;
563 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000564
565 PTP_CNT_INIT(ptp);
566 ptp.Code=PTP_OC_GetObjectHandles;
567 ptp.Param1=storage;
568 ptp.Param2=objectformatcode;
569 ptp.Param3=associationOH;
570 ptp.Nparam=3;
Linus Walleijb02a0662006-04-25 08:05:09 +0000571 len=0;
572 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oh, &len);
573 if (ret == PTP_RC_OK) ptp_unpack_OH(params, oh, objecthandles, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000574 free(oh);
575 return ret;
576}
577
Linus Walleijb02a0662006-04-25 08:05:09 +0000578/**
579 * ptp_getnumobjects:
580 * params: PTPParams*
581 * storage - StorageID
582 * objectformatcode - ObjectFormatCode (optional)
583 * associationOH - ObjectHandle of Association for
584 * wich a list of children is desired
585 * (optional)
586 * numobs - pointer to uint32_t that takes number of objects
587 *
588 * Fills numobs with number of objects on device.
589 *
590 * Return values: Some PTP_RC_* code.
591 **/
592uint16_t
593ptp_getnumobjects (PTPParams* params, uint32_t storage,
594 uint32_t objectformatcode, uint32_t associationOH,
595 uint32_t* numobs)
596{
597 uint16_t ret;
598 PTPContainer ptp;
599 int len;
600
601 PTP_CNT_INIT(ptp);
602 ptp.Code=PTP_OC_GetObjectHandles;
603 ptp.Param1=storage;
604 ptp.Param2=objectformatcode;
605 ptp.Param3=associationOH;
606 ptp.Nparam=3;
607 len=0;
608 ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
609 if (ret == PTP_RC_OK) {
610 if (ptp.Nparam >= 1)
611 *numobs = ptp.Param1;
612 else
613 ret = PTP_RC_GeneralError;
614 }
615 return ret;
616}
617
618/**
619 * ptp_getobjectinfo:
620 * params: PTPParams*
621 * handle - Object handle
622 * objectinfo - pointer to objectinfo that is returned
623 *
624 * Get objectinfo structure for handle from device.
625 *
626 * Return values: Some PTP_RC_* code.
627 **/
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000628uint16_t
629ptp_getobjectinfo (PTPParams* params, uint32_t handle,
630 PTPObjectInfo* objectinfo)
631{
632 uint16_t ret;
633 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000634 unsigned char* oi=NULL;
635 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000636
637 PTP_CNT_INIT(ptp);
638 ptp.Code=PTP_OC_GetObjectInfo;
639 ptp.Param1=handle;
640 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000641 len=0;
642 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oi, &len);
643 if (ret == PTP_RC_OK) ptp_unpack_OI(params, oi, objectinfo, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000644 free(oi);
645 return ret;
646}
647
Linus Walleijb02a0662006-04-25 08:05:09 +0000648/**
649 * ptp_getobject:
650 * params: PTPParams*
651 * handle - Object handle
652 * object - pointer to data area
653 *
654 * Get object 'handle' from device and store the data in newly
655 * allocated 'object'.
656 *
657 * Return values: Some PTP_RC_* code.
658 **/
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000659uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +0000660ptp_getobject (PTPParams* params, uint32_t handle, unsigned char** object)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000661{
662 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000663 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000664
665 PTP_CNT_INIT(ptp);
666 ptp.Code=PTP_OC_GetObject;
667 ptp.Param1=handle;
668 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000669 len=0;
670 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000671}
672
Linus Walleijb02a0662006-04-25 08:05:09 +0000673/**
Linus Walleij784ac3f2006-12-29 10:36:51 +0000674 * ptp_getobject_to_handler:
675 * params: PTPParams*
676 * handle - Object handle
677 * PTPDataHandler* - pointer datahandler
678 *
679 * Get object 'handle' from device and store the data in newly
680 * allocated 'object'.
681 *
682 * Return values: Some PTP_RC_* code.
683 **/
684uint16_t
685ptp_getobject_to_handler (PTPParams* params, uint32_t handle, PTPDataHandler *handler)
686{
687 PTPContainer ptp;
688
689 PTP_CNT_INIT(ptp);
690 ptp.Code=PTP_OC_GetObject;
691 ptp.Param1=handle;
692 ptp.Nparam=1;
693 return ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, handler);
694}
695
696/**
Linus Walleij96c62432006-08-21 10:04:02 +0000697 * ptp_getobject_tofd:
698 * params: PTPParams*
699 * handle - Object handle
700 * fd - File descriptor to write() to
701 *
702 * Get object 'handle' from device and write the data to the
703 * given file descriptor.
704 *
705 * Return values: Some PTP_RC_* code.
706 **/
707uint16_t
708ptp_getobject_tofd (PTPParams* params, uint32_t handle, int fd)
709{
Linus Walleij784ac3f2006-12-29 10:36:51 +0000710 PTPContainer ptp;
711 PTPDataHandler handler;
712 uint16_t ret;
Linus Walleij96c62432006-08-21 10:04:02 +0000713
Linus Walleij784ac3f2006-12-29 10:36:51 +0000714 ptp_init_fd_handler (&handler, fd);
Linus Walleij96c62432006-08-21 10:04:02 +0000715 PTP_CNT_INIT(ptp);
716 ptp.Code=PTP_OC_GetObject;
717 ptp.Param1=handle;
718 ptp.Nparam=1;
Linus Walleij784ac3f2006-12-29 10:36:51 +0000719 ret = ptp_transaction_new(params, &ptp, PTP_DP_GETDATA, 0, &handler);
720 ptp_exit_fd_handler (&handler);
721 return ret;
Linus Walleij96c62432006-08-21 10:04:02 +0000722}
723
724/**
Linus Walleijb02a0662006-04-25 08:05:09 +0000725 * ptp_getpartialobject:
726 * params: PTPParams*
727 * handle - Object handle
728 * offset - Offset into object
729 * maxbytes - Maximum of bytes to read
730 * object - pointer to data area
731 *
732 * Get object 'handle' from device and store the data in newly
733 * allocated 'object'. Start from offset and read at most maxbytes.
734 *
735 * Return values: Some PTP_RC_* code.
736 **/
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000737uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +0000738ptp_getpartialobject (PTPParams* params, uint32_t handle, uint32_t offset,
739 uint32_t maxbytes, unsigned char** object)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000740{
741 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000742 unsigned int len;
743
744 PTP_CNT_INIT(ptp);
745 ptp.Code=PTP_OC_GetPartialObject;
746 ptp.Param1=handle;
747 ptp.Param2=offset;
748 ptp.Param3=maxbytes;
749 ptp.Nparam=3;
750 len=0;
751 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
752}
753
754/**
755 * ptp_getthumb:
756 * params: PTPParams*
757 * handle - Object handle
758 * object - pointer to data area
759 *
760 * Get thumb for object 'handle' from device and store the data in newly
761 * allocated 'object'.
762 *
763 * Return values: Some PTP_RC_* code.
764 **/
765uint16_t
766ptp_getthumb (PTPParams* params, uint32_t handle, unsigned char** object)
767{
768 PTPContainer ptp;
769 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000770
771 PTP_CNT_INIT(ptp);
772 ptp.Code=PTP_OC_GetThumb;
773 ptp.Param1=handle;
774 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000775 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000776}
777
778/**
779 * ptp_deleteobject:
780 * params: PTPParams*
781 * handle - object handle
782 * ofc - object format code (optional)
783 *
784 * Deletes desired objects.
785 *
786 * Return values: Some PTP_RC_* code.
787 **/
788uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +0000789ptp_deleteobject (PTPParams* params, uint32_t handle, uint32_t ofc)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000790{
791 PTPContainer ptp;
792
793 PTP_CNT_INIT(ptp);
794 ptp.Code=PTP_OC_DeleteObject;
795 ptp.Param1=handle;
796 ptp.Param2=ofc;
797 ptp.Nparam=2;
Linus Walleijb02a0662006-04-25 08:05:09 +0000798 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000799}
800
801/**
802 * ptp_sendobjectinfo:
803 * params: PTPParams*
804 * uint32_t* store - destination StorageID on Responder
805 * uint32_t* parenthandle - Parent ObjectHandle on responder
806 * uint32_t* handle - see Return values
807 * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent
808 *
809 * Sends ObjectInfo of file that is to be sent via SendFileObject.
810 *
811 * Return values: Some PTP_RC_* code.
812 * Upon success : uint32_t* store - Responder StorageID in which
813 * object will be stored
814 * uint32_t* parenthandle- Responder Parent ObjectHandle
815 * in which the object will be stored
816 * uint32_t* handle - Responder's reserved ObjectHandle
817 * for the incoming object
818 **/
819uint16_t
820ptp_sendobjectinfo (PTPParams* params, uint32_t* store,
821 uint32_t* parenthandle, uint32_t* handle,
822 PTPObjectInfo* objectinfo)
823{
824 uint16_t ret;
825 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +0000826 unsigned char* oidata=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000827 uint32_t size;
828
829 PTP_CNT_INIT(ptp);
830 ptp.Code=PTP_OC_SendObjectInfo;
831 ptp.Param1=*store;
832 ptp.Param2=*parenthandle;
833 ptp.Nparam=2;
834
835 size=ptp_pack_OI(params, objectinfo, &oidata);
Linus Walleijb02a0662006-04-25 08:05:09 +0000836 ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000837 free(oidata);
838 *store=ptp.Param1;
839 *parenthandle=ptp.Param2;
840 *handle=ptp.Param3;
841 return ret;
842}
843
844/**
845 * ptp_sendobject:
846 * params: PTPParams*
847 * char* object - contains the object that is to be sent
848 * uint32_t size - object size
849 *
850 * Sends object to Responder.
851 *
852 * Return values: Some PTP_RC_* code.
853 *
854 */
855uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +0000856ptp_sendobject (PTPParams* params, unsigned char* object, uint32_t size)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000857{
858 PTPContainer ptp;
859
860 PTP_CNT_INIT(ptp);
861 ptp.Code=PTP_OC_SendObject;
862 ptp.Nparam=0;
863
Linus Walleijb02a0662006-04-25 08:05:09 +0000864 return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000865}
866
Linus Walleije7f44be2006-08-25 19:32:29 +0000867/**
Linus Walleij784ac3f2006-12-29 10:36:51 +0000868 * ptp_sendobject_from_handler:
869 * params: PTPParams*
870 * PTPDataHandler* - File descriptor to read() object from
871 * uint32_t size - File/object size
872 *
873 * Sends object from file descriptor by consecutive reads from this
874 * descriptor.
875 *
876 * Return values: Some PTP_RC_* code.
877 **/
878uint16_t
879ptp_sendobject_from_handler (PTPParams* params, PTPDataHandler *handler, uint32_t size)
880{
881 PTPContainer ptp;
882
883 PTP_CNT_INIT(ptp);
884 ptp.Code=PTP_OC_SendObject;
885 ptp.Nparam=0;
886 return ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, handler);
887}
888
889
890/**
Linus Walleije7f44be2006-08-25 19:32:29 +0000891 * ptp_sendobject_fromfd:
892 * params: PTPParams*
893 * fd - File descriptor to read() object from
894 * uint32_t size - File/object size
895 *
896 * Sends object from file descriptor by consecutive reads from this
897 * descriptor.
898 *
899 * Return values: Some PTP_RC_* code.
900 **/
901uint16_t
902ptp_sendobject_fromfd (PTPParams* params, int fd, uint32_t size)
903{
Linus Walleij784ac3f2006-12-29 10:36:51 +0000904 PTPContainer ptp;
905 PTPDataHandler handler;
906 uint16_t ret;
Linus Walleije7f44be2006-08-25 19:32:29 +0000907
Linus Walleij784ac3f2006-12-29 10:36:51 +0000908 ptp_init_fd_handler (&handler, fd);
Linus Walleije7f44be2006-08-25 19:32:29 +0000909 PTP_CNT_INIT(ptp);
910 ptp.Code=PTP_OC_SendObject;
911 ptp.Nparam=0;
Linus Walleij784ac3f2006-12-29 10:36:51 +0000912 ret = ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, &handler);
913 ptp_exit_fd_handler (&handler);
914 return ret;
Linus Walleije7f44be2006-08-25 19:32:29 +0000915}
916
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000917
918/**
919 * ptp_initiatecapture:
920 * params: PTPParams*
921 * storageid - destination StorageID on Responder
922 * ofc - object format code
923 *
924 * Causes device to initiate the capture of one or more new data objects
925 * according to its current device properties, storing the data into store
926 * indicated by storageid. If storageid is 0x00000000, the object(s) will
927 * be stored in a store that is determined by the capturing device.
928 * The capturing of new data objects is an asynchronous operation.
929 *
930 * Return values: Some PTP_RC_* code.
931 **/
932
933uint16_t
934ptp_initiatecapture (PTPParams* params, uint32_t storageid,
935 uint32_t ofc)
936{
937 PTPContainer ptp;
938
939 PTP_CNT_INIT(ptp);
940 ptp.Code=PTP_OC_InitiateCapture;
941 ptp.Param1=storageid;
942 ptp.Param2=ofc;
943 ptp.Nparam=2;
Linus Walleijb02a0662006-04-25 08:05:09 +0000944 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000945}
946
947uint16_t
948ptp_getdevicepropdesc (PTPParams* params, uint16_t propcode,
949 PTPDevicePropDesc* devicepropertydesc)
950{
951 PTPContainer ptp;
952 uint16_t ret;
Linus Walleijb02a0662006-04-25 08:05:09 +0000953 unsigned int len;
954 unsigned char* dpd=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000955
956 PTP_CNT_INIT(ptp);
957 ptp.Code=PTP_OC_GetDevicePropDesc;
958 ptp.Param1=propcode;
959 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000960 len=0;
961 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd, &len);
962 if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000963 free(dpd);
964 return ret;
965}
966
Linus Walleijb02a0662006-04-25 08:05:09 +0000967
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000968uint16_t
969ptp_getdevicepropvalue (PTPParams* params, uint16_t propcode,
Linus Walleijb02a0662006-04-25 08:05:09 +0000970 PTPPropertyValue* value, uint16_t datatype)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000971{
972 PTPContainer ptp;
973 uint16_t ret;
Linus Walleijb02a0662006-04-25 08:05:09 +0000974 unsigned int len;
975 int offset;
976 unsigned char* dpv=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000977
978
979 PTP_CNT_INIT(ptp);
980 ptp.Code=PTP_OC_GetDevicePropValue;
981 ptp.Param1=propcode;
982 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +0000983 len=offset=0;
984 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &len);
985 if (ret == PTP_RC_OK) ptp_unpack_DPV(params, dpv, &offset, len, value, datatype);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000986 free(dpv);
987 return ret;
988}
989
990uint16_t
991ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode,
Linus Walleijb02a0662006-04-25 08:05:09 +0000992 PTPPropertyValue *value, uint16_t datatype)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000993{
994 PTPContainer ptp;
995 uint16_t ret;
996 uint32_t size;
Linus Walleijb02a0662006-04-25 08:05:09 +0000997 unsigned char* dpv=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +0000998
999 PTP_CNT_INIT(ptp);
1000 ptp.Code=PTP_OC_SetDevicePropValue;
1001 ptp.Param1=propcode;
1002 ptp.Nparam=1;
1003 size=ptp_pack_DPV(params, value, &dpv, datatype);
Linus Walleijb02a0662006-04-25 08:05:09 +00001004 ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001005 free(dpv);
1006 return ret;
1007}
1008
1009/**
1010 * ptp_ek_sendfileobjectinfo:
1011 * params: PTPParams*
1012 * uint32_t* store - destination StorageID on Responder
1013 * uint32_t* parenthandle - Parent ObjectHandle on responder
1014 * uint32_t* handle - see Return values
1015 * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent
1016 *
1017 * Sends ObjectInfo of file that is to be sent via SendFileObject.
1018 *
1019 * Return values: Some PTP_RC_* code.
1020 * Upon success : uint32_t* store - Responder StorageID in which
1021 * object will be stored
1022 * uint32_t* parenthandle- Responder Parent ObjectHandle
1023 * in which the object will be stored
1024 * uint32_t* handle - Responder's reserved ObjectHandle
1025 * for the incoming object
1026 **/
1027uint16_t
1028ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store,
1029 uint32_t* parenthandle, uint32_t* handle,
1030 PTPObjectInfo* objectinfo)
1031{
1032 uint16_t ret;
1033 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001034 unsigned char* oidata=NULL;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001035 uint32_t size;
1036
1037 PTP_CNT_INIT(ptp);
1038 ptp.Code=PTP_OC_EK_SendFileObjectInfo;
1039 ptp.Param1=*store;
1040 ptp.Param2=*parenthandle;
1041 ptp.Nparam=2;
1042
1043 size=ptp_pack_OI(params, objectinfo, &oidata);
Linus Walleijb02a0662006-04-25 08:05:09 +00001044 ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001045 free(oidata);
1046 *store=ptp.Param1;
1047 *parenthandle=ptp.Param2;
1048 *handle=ptp.Param3;
1049 return ret;
1050}
1051
1052/**
Linus Walleijb02a0662006-04-25 08:05:09 +00001053 * ptp_ek_getserial:
1054 * params: PTPParams*
1055 * char** serial - contains the serial number of the camera
1056 * uint32_t* size - contains the string length
1057 *
1058 * Gets the serial number from the device. (ptp serial)
1059 *
1060 * Return values: Some PTP_RC_* code.
1061 *
1062 */
1063uint16_t
1064ptp_ek_getserial (PTPParams* params, unsigned char **data, unsigned int *size)
1065{
1066 PTPContainer ptp;
1067
1068 PTP_CNT_INIT(ptp);
1069 ptp.Code = PTP_OC_EK_GetSerial;
1070 ptp.Nparam = 0;
1071 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1072}
1073
1074/**
1075 * ptp_ek_setserial:
1076 * params: PTPParams*
1077 * char* serial - contains the new serial number
1078 * uint32_t size - string length
1079 *
1080 * Sets the serial number of the device. (ptp serial)
1081 *
1082 * Return values: Some PTP_RC_* code.
1083 *
1084 */
1085uint16_t
1086ptp_ek_setserial (PTPParams* params, unsigned char *data, unsigned int size)
1087{
1088 PTPContainer ptp;
1089
1090 PTP_CNT_INIT(ptp);
1091 ptp.Code = PTP_OC_EK_SetSerial;
1092 ptp.Nparam = 0;
1093 return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
1094}
1095
1096/* unclear what it does yet */
1097uint16_t
1098ptp_ek_9007 (PTPParams* params, unsigned char **data, unsigned int *size)
1099{
1100 PTPContainer ptp;
1101
1102 PTP_CNT_INIT(ptp);
1103 ptp.Code = 0x9007;
1104 ptp.Nparam = 0;
1105 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1106}
1107
1108/* unclear what it does yet */
1109uint16_t
1110ptp_ek_9009 (PTPParams* params, uint32_t *p1, uint32_t *p2)
1111{
1112 PTPContainer ptp;
1113 uint16_t ret;
1114
1115 PTP_CNT_INIT(ptp);
1116 ptp.Code = 0x9009;
1117 ptp.Nparam = 0;
1118 ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1119 *p1 = ptp.Param1;
1120 *p2 = ptp.Param2;
1121 return ret;
1122}
1123
1124/* unclear yet, but I guess it returns the info from 9008 */
1125uint16_t
1126ptp_ek_900c (PTPParams* params, unsigned char **data, unsigned int *size)
1127{
1128 PTPContainer ptp;
1129
1130 PTP_CNT_INIT(ptp);
1131 ptp.Code = 0x900c;
1132 ptp.Nparam = 0;
1133 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1134 /* returned data is 16bit,16bit,32bit,32bit */
1135}
1136
1137/**
1138 * ptp_ek_settext:
1139 * params: PTPParams*
1140 * PTPEKTextParams* - contains the texts to display.
1141 *
1142 * Displays the specified texts on the TFT of the camera.
1143 *
1144 * Return values: Some PTP_RC_* code.
1145 *
1146 */
1147uint16_t
1148ptp_ek_settext (PTPParams* params, PTPEKTextParams *text)
1149{
1150 PTPContainer ptp;
1151 uint16_t ret;
1152 unsigned int size;
1153 unsigned char *data;
1154
1155 PTP_CNT_INIT(ptp);
1156 ptp.Code = PTP_OC_EK_SetText;
1157 ptp.Nparam = 0;
1158 if (0 == (size = ptp_pack_EK_text(params, text, &data)))
1159 return PTP_ERROR_BADPARAM;
1160 ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
1161 free(data);
1162 return ret;
1163}
1164
1165/**
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001166 * ptp_ek_sendfileobject:
1167 * params: PTPParams*
1168 * char* object - contains the object that is to be sent
1169 * uint32_t size - object size
1170 *
1171 * Sends object to Responder.
1172 *
1173 * Return values: Some PTP_RC_* code.
1174 *
1175 */
1176uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +00001177ptp_ek_sendfileobject (PTPParams* params, unsigned char* object, uint32_t size)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001178{
1179 PTPContainer ptp;
1180
1181 PTP_CNT_INIT(ptp);
1182 ptp.Code=PTP_OC_EK_SendFileObject;
1183 ptp.Nparam=0;
1184
Linus Walleijb02a0662006-04-25 08:05:09 +00001185 return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001186}
1187
Linus Walleij784ac3f2006-12-29 10:36:51 +00001188/**
1189 * ptp_ek_sendfileobject_from_handler:
1190 * params: PTPParams*
1191 * PTPDataHandler* handler - contains the handler of the object that is to be sent
1192 * uint32_t size - object size
1193 *
1194 * Sends object to Responder.
1195 *
1196 * Return values: Some PTP_RC_* code.
1197 *
1198 */
1199uint16_t
1200ptp_ek_sendfileobject_from_handler (PTPParams* params, PTPDataHandler*handler, uint32_t size)
1201{
1202 PTPContainer ptp;
1203
1204 PTP_CNT_INIT(ptp);
1205 ptp.Code=PTP_OC_EK_SendFileObject;
1206 ptp.Nparam=0;
1207 return ptp_transaction_new(params, &ptp, PTP_DP_SENDDATA, size, handler);
1208}
1209
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001210/*************************************************************************
1211 *
1212 * Canon PTP extensions support
1213 *
1214 * (C) Nikolai Kopanygin 2003
1215 *
1216 *************************************************************************/
1217
1218
1219/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001220 * ptp_canon_getpartialobjectinfo:
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001221 * params: PTPParams*
1222 * uint32_t handle - ObjectHandle
Linus Walleij7347d0f2006-10-23 07:23:39 +00001223 * uint32_t p2 - Not fully understood parameter
1224 * 0 - returns full size
1225 * 1 - returns thumbnail size (or EXIF?)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001226 *
1227 * Gets form the responder the size of the specified object.
1228 *
1229 * Return values: Some PTP_RC_* code.
1230 * Upon success : uint32_t* size - The object size
Linus Walleij7347d0f2006-10-23 07:23:39 +00001231 * uint32_t* rp2 - Still unknown return parameter
1232 * (perhaps upper 32bit of size)
1233 *
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001234 *
1235 **/
1236uint16_t
Linus Walleij7347d0f2006-10-23 07:23:39 +00001237ptp_canon_getpartialobjectinfo (PTPParams* params, uint32_t handle, uint32_t p2,
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001238 uint32_t* size, uint32_t* rp2)
1239{
1240 uint16_t ret;
1241 PTPContainer ptp;
1242
1243 PTP_CNT_INIT(ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001244 ptp.Code=PTP_OC_CANON_GetPartialObjectInfo;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001245 ptp.Param1=handle;
1246 ptp.Param2=p2;
1247 ptp.Nparam=2;
Linus Walleijb02a0662006-04-25 08:05:09 +00001248 ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001249 *size=ptp.Param1;
1250 *rp2=ptp.Param2;
1251 return ret;
1252}
1253
1254/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001255 * ptp_canon_get_mac_address:
1256 * params: PTPParams*
1257 * value 0 works.
1258 * Gets the MAC address of the wireless transmitter.
1259 *
1260 * Return values: Some PTP_RC_* code.
1261 * Upon success : unsigned char* mac - The MAC address
1262 *
1263 **/
1264uint16_t
1265ptp_canon_get_mac_address (PTPParams* params, unsigned char **mac)
1266{
1267 PTPContainer ptp;
1268 unsigned int size = 0;
1269
1270 PTP_CNT_INIT(ptp);
1271 ptp.Code=PTP_OC_CANON_GetMACAddress;
1272 ptp.Nparam=0;
1273 *mac = NULL;
1274 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, mac, &size);
1275}
1276
1277/**
1278 * ptp_canon_get_directory:
1279 * params: PTPParams*
1280
1281 * Gets the full directory of the camera.
1282 *
1283 * Return values: Some PTP_RC_* code.
1284 * Upon success : PTPObjectHandles *handles - filled out with handles
1285 * PTPObjectInfo **oinfos - allocated array of PTP Object Infos
1286 * uint32_t **flags - allocated array of CANON Flags
1287 *
1288 **/
1289uint16_t
1290ptp_canon_get_directory (PTPParams* params,
1291 PTPObjectHandles *handles,
1292 PTPObjectInfo **oinfos, /* size(handles->n) */
1293 uint32_t **flags /* size(handles->n) */
1294) {
1295 PTPContainer ptp;
1296 unsigned char *dir = NULL;
1297 unsigned int size = 0;
1298 uint16_t ret;
1299
1300 PTP_CNT_INIT(ptp);
1301 ptp.Code=PTP_OC_CANON_GetDirectory;
1302 ptp.Nparam=0;
1303 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dir, &size);
1304 if (ret != PTP_RC_OK)
1305 return ret;
1306 ret = ptp_unpack_canon_directory(params, dir, ptp.Param1, handles, oinfos, flags);
1307 free (dir);
1308 return ret;
1309}
1310
1311/**
1312 * ptp_canon_setobjectarchive:
1313 *
1314 * params: PTPParams*
1315 * uint32_t objectid
1316 * uint32_t flags
1317 *
1318 * Return values: Some PTP_RC_* code.
1319 *
1320 **/
1321uint16_t
1322ptp_canon_setobjectarchive (PTPParams* params, uint32_t oid, uint32_t flags)
1323{
1324 PTPContainer ptp;
1325
1326 PTP_CNT_INIT(ptp);
1327 ptp.Code=PTP_OC_CANON_SetObjectArchive;
1328 ptp.Nparam=2;
1329 ptp.Param1=oid;
1330 ptp.Param2=flags;
1331 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1332}
1333
1334
1335/**
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001336 * ptp_canon_startshootingmode:
1337 * params: PTPParams*
1338 *
1339 * Starts shooting session. It emits a StorageInfoChanged
1340 * event via the interrupt pipe and pushes the StorageInfoChanged
1341 * and CANON_CameraModeChange events onto the event stack
1342 * (see operation PTP_OC_CANON_CheckEvent).
1343 *
1344 * Return values: Some PTP_RC_* code.
1345 *
1346 **/
1347uint16_t
1348ptp_canon_startshootingmode (PTPParams* params)
1349{
1350 PTPContainer ptp;
1351
1352 PTP_CNT_INIT(ptp);
1353 ptp.Code=PTP_OC_CANON_StartShootingMode;
1354 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001355 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001356}
1357
1358/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001359 * ptp_canon_initiate_direct_transfer:
1360 * params: PTPParams*
1361 * uint32_t *out
1362 *
1363 * Switches the camera display to on and lets the user
1364 * select what to transfer. Sends a 0xc011 event when started
1365 * and 0xc013 if direct transfer aborted.
1366 *
1367 * Return values: Some PTP_RC_* code.
1368 *
1369 **/
1370uint16_t
1371ptp_canon_initiate_direct_transfer (PTPParams* params, uint32_t *out)
1372{
1373 PTPContainer ptp;
1374 uint16_t ret;
1375
1376 PTP_CNT_INIT(ptp);
1377 ptp.Code = PTP_OC_CANON_InitiateDirectTransferEx2;
1378 ptp.Nparam = 1;
1379 ptp.Param1 = 0xf;
1380 ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1381 if ((ret == PTP_RC_OK) && (ptp.Nparam>0))
1382 *out = ptp.Param1;
1383 return ret;
1384}
1385
1386/**
1387 * ptp_canon_get_target_handles:
1388 * params: PTPParams*
1389 * PTPCanon_directtransfer_entry **out
1390 * unsigned int *outsize
1391 *
1392 * Retrieves direct transfer entries specifying the images to transfer
1393 * from the camera (to be retrieved after 0xc011 event).
1394 *
1395 * Return values: Some PTP_RC_* code.
1396 *
1397 **/
1398uint16_t
1399ptp_canon_get_target_handles (PTPParams* params,
1400 PTPCanon_directtransfer_entry **entries, unsigned int *cnt)
1401{
1402 PTPContainer ptp;
1403 uint16_t ret;
1404 unsigned char *out = NULL, *cur;
1405 int i;
1406 unsigned int size;
1407
1408 PTP_CNT_INIT(ptp);
1409 ptp.Code = PTP_OC_CANON_GetTargetHandles;
1410 ptp.Nparam = 0;
1411 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &out, &size);
1412 if (ret != PTP_RC_OK)
1413 return ret;
1414 *cnt = dtoh32a(out);
1415 *entries = malloc(sizeof(PTPCanon_directtransfer_entry)*(*cnt));
1416 cur = out+4;
1417 for (i=0;i<*cnt;i++) {
1418 unsigned char len;
1419 (*entries)[i].oid = dtoh32a(cur);
1420 (*entries)[i].str = ptp_unpack_string(params, cur, 4, &len);
1421 cur += 4+(cur[4]*2+1);
1422 }
1423 free (out);
1424 return PTP_RC_OK;
1425}
1426/**
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001427 * ptp_canon_endshootingmode:
1428 * params: PTPParams*
1429 *
1430 * This operation is observed after pressing the Disconnect
1431 * button on the Remote Capture app. It emits a StorageInfoChanged
1432 * event via the interrupt pipe and pushes the StorageInfoChanged
1433 * and CANON_CameraModeChange events onto the event stack
1434 * (see operation PTP_OC_CANON_CheckEvent).
1435 *
1436 * Return values: Some PTP_RC_* code.
1437 *
1438 **/
1439uint16_t
1440ptp_canon_endshootingmode (PTPParams* params)
1441{
1442 PTPContainer ptp;
1443
1444 PTP_CNT_INIT(ptp);
1445 ptp.Code=PTP_OC_CANON_EndShootingMode;
1446 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001447 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001448}
1449
1450/**
1451 * ptp_canon_viewfinderon:
1452 * params: PTPParams*
1453 *
1454 * Prior to start reading viewfinder images, one must call this operation.
1455 * Supposedly, this operation affects the value of the CANON_ViewfinderMode
1456 * property.
1457 *
1458 * Return values: Some PTP_RC_* code.
1459 *
1460 **/
1461uint16_t
1462ptp_canon_viewfinderon (PTPParams* params)
1463{
1464 PTPContainer ptp;
1465
1466 PTP_CNT_INIT(ptp);
1467 ptp.Code=PTP_OC_CANON_ViewfinderOn;
1468 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001469 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001470}
1471
1472/**
1473 * ptp_canon_viewfinderoff:
1474 * params: PTPParams*
1475 *
1476 * Before changing the shooting mode, or when one doesn't need to read
1477 * viewfinder images any more, one must call this operation.
1478 * Supposedly, this operation affects the value of the CANON_ViewfinderMode
1479 * property.
1480 *
1481 * Return values: Some PTP_RC_* code.
1482 *
1483 **/
1484uint16_t
1485ptp_canon_viewfinderoff (PTPParams* params)
1486{
1487 PTPContainer ptp;
1488
1489 PTP_CNT_INIT(ptp);
1490 ptp.Code=PTP_OC_CANON_ViewfinderOff;
1491 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001492 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001493}
1494
1495/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001496 * ptp_canon_aeafawb:
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001497 * params: PTPParams*
1498 * uint32_t p1 - Yet unknown parameter,
1499 * value 7 works
1500 *
Linus Walleij7347d0f2006-10-23 07:23:39 +00001501 * Called AeAfAwb (auto exposure, focus, white balance)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001502 *
1503 * Return values: Some PTP_RC_* code.
1504 *
1505 **/
1506uint16_t
Linus Walleij7347d0f2006-10-23 07:23:39 +00001507ptp_canon_aeafawb (PTPParams* params, uint32_t p1)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001508{
1509 PTPContainer ptp;
1510
1511 PTP_CNT_INIT(ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001512 ptp.Code=PTP_OC_CANON_DoAeAfAwb;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001513 ptp.Param1=p1;
1514 ptp.Nparam=1;
Linus Walleijb02a0662006-04-25 08:05:09 +00001515 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001516}
1517
1518
1519/**
1520 * ptp_canon_checkevent:
1521 * params: PTPParams*
1522 *
1523 * The camera has a FIFO stack, in which it accumulates events.
1524 * Partially these events are communicated also via the USB interrupt pipe
1525 * according to the PTP USB specification, partially not.
1526 * This operation returns from the device a block of data, empty,
1527 * if the event stack is empty, or filled with an event's data otherwise.
1528 * The event is removed from the stack in the latter case.
1529 * The Remote Capture app sends this command to the camera all the time
1530 * of connection, filling with it the gaps between other operations.
1531 *
1532 * Return values: Some PTP_RC_* code.
1533 * Upon success : PTPUSBEventContainer* event - is filled with the event data
1534 * if any
1535 * int *isevent - returns 1 in case of event
1536 * or 0 otherwise
1537 **/
1538uint16_t
1539ptp_canon_checkevent (PTPParams* params, PTPUSBEventContainer* event, int* isevent)
1540{
1541 uint16_t ret;
1542 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001543 unsigned char *evdata = NULL;
1544 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001545
1546 *isevent=0;
1547 PTP_CNT_INIT(ptp);
1548 ptp.Code=PTP_OC_CANON_CheckEvent;
1549 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001550 len=0;
1551 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001552 if (evdata!=NULL) {
1553 if (ret == PTP_RC_OK) {
Linus Walleijb02a0662006-04-25 08:05:09 +00001554 ptp_unpack_EC(params, evdata, event, len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001555 *isevent=1;
1556 }
1557 free(evdata);
1558 }
1559 return ret;
1560}
1561
1562
1563/**
1564 * ptp_canon_focuslock:
1565 *
1566 * This operation locks the focus. It is followed by the CANON_GetChanges(?)
1567 * operation in the log.
1568 * It affects the CANON_MacroMode property.
1569 *
1570 * params: PTPParams*
1571 *
1572 * Return values: Some PTP_RC_* code.
1573 *
1574 **/
1575uint16_t
1576ptp_canon_focuslock (PTPParams* params)
1577{
1578 PTPContainer ptp;
1579
1580 PTP_CNT_INIT(ptp);
1581 ptp.Code=PTP_OC_CANON_FocusLock;
1582 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001583 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001584}
1585
1586/**
1587 * ptp_canon_focusunlock:
1588 *
1589 * This operation unlocks the focus. It is followed by the CANON_GetChanges(?)
1590 * operation in the log.
1591 * It sets the CANON_MacroMode property value to 1 (where it occurs in the log).
1592 *
1593 * params: PTPParams*
1594 *
1595 * Return values: Some PTP_RC_* code.
1596 *
1597 **/
1598uint16_t
1599ptp_canon_focusunlock (PTPParams* params)
1600{
1601 PTPContainer ptp;
1602
1603 PTP_CNT_INIT(ptp);
1604 ptp.Code=PTP_OC_CANON_FocusUnlock;
1605 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001606 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001607}
1608
1609/**
1610 * ptp_canon_initiatecaptureinmemory:
1611 *
1612 * This operation starts the image capture according to the current camera
1613 * settings. When the capture has happened, the camera emits a CaptureComplete
1614 * event via the interrupt pipe and pushes the CANON_RequestObjectTransfer,
1615 * CANON_DeviceInfoChanged and CaptureComplete events onto the event stack
1616 * (see operation CANON_CheckEvent). From the CANON_RequestObjectTransfer
1617 * event's parameter one can learn the just captured image's ObjectHandle.
1618 * The image is stored in the camera's own RAM.
1619 * On the next capture the image will be overwritten!
1620 *
1621 * params: PTPParams*
1622 *
1623 * Return values: Some PTP_RC_* code.
1624 *
1625 **/
1626uint16_t
1627ptp_canon_initiatecaptureinmemory (PTPParams* params)
1628{
1629 PTPContainer ptp;
1630
1631 PTP_CNT_INIT(ptp);
1632 ptp.Code=PTP_OC_CANON_InitiateCaptureInMemory;
1633 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001634 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1635}
1636
1637uint16_t
1638ptp_canon_9012 (PTPParams* params)
1639{
1640 PTPContainer ptp;
1641
1642 PTP_CNT_INIT(ptp);
1643 ptp.Code=0x9012;
1644 ptp.Nparam=0;
1645 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001646}
1647
1648/**
1649 * ptp_canon_getpartialobject:
1650 *
1651 * This operation is used to read from the device a data
1652 * block of an object from a specified offset.
1653 *
1654 * params: PTPParams*
1655 * uint32_t handle - the handle of the requested object
1656 * uint32_t offset - the offset in bytes from the beginning of the object
1657 * uint32_t size - the requested size of data block to read
1658 * uint32_t pos - 1 for the first block, 2 - for a block in the middle,
1659 * 3 - for the last block
1660 *
1661 * Return values: Some PTP_RC_* code.
1662 * char **block - the pointer to the block of data read
1663 * uint32_t* readnum - the number of bytes read
1664 *
1665 **/
1666uint16_t
1667ptp_canon_getpartialobject (PTPParams* params, uint32_t handle,
1668 uint32_t offset, uint32_t size,
Linus Walleijb02a0662006-04-25 08:05:09 +00001669 uint32_t pos, unsigned char** block,
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001670 uint32_t* readnum)
1671{
1672 uint16_t ret;
1673 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001674 unsigned char *data=NULL;
1675 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001676
1677 PTP_CNT_INIT(ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001678 ptp.Code=PTP_OC_CANON_GetPartialObjectEx;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001679 ptp.Param1=handle;
1680 ptp.Param2=offset;
1681 ptp.Param3=size;
1682 ptp.Param4=pos;
1683 ptp.Nparam=4;
Linus Walleijb02a0662006-04-25 08:05:09 +00001684 len=0;
1685 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001686 if (ret==PTP_RC_OK) {
1687 *block=data;
1688 *readnum=ptp.Param1;
1689 }
1690 return ret;
1691}
1692
1693/**
1694 * ptp_canon_getviewfinderimage:
1695 *
1696 * This operation can be used to read the image which is currently
1697 * in the camera's viewfinder. The image size is 320x240, format is JPEG.
1698 * Of course, prior to calling this operation, one must turn the viewfinder
1699 * on with the CANON_ViewfinderOn command.
1700 * Invoking this operation many times, one can get live video from the camera!
1701 *
1702 * params: PTPParams*
1703 *
1704 * Return values: Some PTP_RC_* code.
1705 * char **image - the pointer to the read image
1706 * unit32_t *size - the size of the image in bytes
1707 *
1708 **/
1709uint16_t
Linus Walleijb02a0662006-04-25 08:05:09 +00001710ptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image, uint32_t* size)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001711{
1712 uint16_t ret;
1713 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001714 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001715
1716 PTP_CNT_INIT(ptp);
1717 ptp.Code=PTP_OC_CANON_GetViewfinderImage;
1718 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001719 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, image, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001720 if (ret==PTP_RC_OK) *size=ptp.Param1;
1721 return ret;
1722}
1723
1724/**
1725 * ptp_canon_getchanges:
1726 *
1727 * This is an interesting operation, about the effect of which I am not sure.
1728 * This command is called every time when a device property has been changed
1729 * with the SetDevicePropValue operation, and after some other operations.
1730 * This operation reads the array of Device Properties which have been changed
1731 * by the previous operation.
1732 * Probably, this operation is even required to make those changes work.
1733 *
1734 * params: PTPParams*
1735 *
1736 * Return values: Some PTP_RC_* code.
1737 * uint16_t** props - the pointer to the array of changed properties
1738 * uint32_t* propnum - the number of elements in the *props array
1739 *
1740 **/
1741uint16_t
1742ptp_canon_getchanges (PTPParams* params, uint16_t** props, uint32_t* propnum)
1743{
1744 uint16_t ret;
1745 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001746 unsigned char* data=NULL;
1747 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001748
1749 PTP_CNT_INIT(ptp);
1750 ptp.Code=PTP_OC_CANON_GetChanges;
1751 ptp.Nparam=0;
Linus Walleijb02a0662006-04-25 08:05:09 +00001752 len=0;
1753 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001754 if (ret == PTP_RC_OK)
1755 *propnum=ptp_unpack_uint16_t_array(params,data,0,props);
1756 free(data);
1757 return ret;
1758}
1759
1760/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001761 * ptp_canon_getobjectinfo:
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001762 *
1763 * This command reads a specified object's record in a device's filesystem,
1764 * or the records of all objects belonging to a specified folder (association).
1765 *
1766 * params: PTPParams*
1767 * uint32_t store - StorageID,
1768 * uint32_t p2 - Yet unknown (0 value works OK)
1769 * uint32_t parent - Parent Object Handle
1770 * # If Parent Object Handle is 0xffffffff,
1771 * # the Parent Object is the top level folder.
1772 * uint32_t handle - Object Handle
1773 * # If Object Handle is 0, the records of all objects
1774 * # belonging to the Parent Object are read.
1775 * # If Object Handle is not 0, only the record of this
1776 * # Object is read.
1777 *
1778 * Return values: Some PTP_RC_* code.
1779 * PTPCANONFolderEntry** entries - the pointer to the folder entry array
1780 * uint32_t* entnum - the number of elements of the array
1781 *
1782 **/
1783uint16_t
Linus Walleij7347d0f2006-10-23 07:23:39 +00001784ptp_canon_getobjectinfo (PTPParams* params, uint32_t store, uint32_t p2,
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001785 uint32_t parent, uint32_t handle,
1786 PTPCANONFolderEntry** entries, uint32_t* entnum)
1787{
1788 uint16_t ret;
1789 PTPContainer ptp;
Linus Walleijb02a0662006-04-25 08:05:09 +00001790 unsigned char *data = NULL;
1791 unsigned int len;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001792
1793 PTP_CNT_INIT(ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001794 ptp.Code=PTP_OC_CANON_GetObjectInfoEx;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001795 ptp.Param1=store;
1796 ptp.Param2=p2;
1797 ptp.Param3=parent;
1798 ptp.Param4=handle;
1799 ptp.Nparam=4;
Linus Walleijb02a0662006-04-25 08:05:09 +00001800 len=0;
1801 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00001802 if (ret == PTP_RC_OK) {
1803 int i;
1804 *entnum=ptp.Param1;
1805 *entries=calloc(*entnum, sizeof(PTPCANONFolderEntry));
1806 if (*entries!=NULL) {
1807 for(i=0; i<(*entnum); i++)
1808 ptp_unpack_Canon_FE(params,
1809 data+i*PTP_CANON_FolderEntryLen,
1810 &((*entries)[i]) );
1811 } else {
1812 ret=PTP_ERROR_IO; /* Cannot allocate memory */
1813 }
1814 }
1815 free(data);
1816 return ret;
1817}
1818
Linus Walleijb02a0662006-04-25 08:05:09 +00001819/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001820 * ptp_canon_get_objecthandle_by_name:
Linus Walleij0468fe72006-09-13 11:49:52 +00001821 *
1822 * This command looks up the specified object on the camera.
1823 *
1824 * Format is "A:\\PATH".
1825 *
1826 * The 'A' is the VolumeLabel from GetStorageInfo,
1827 * my IXUS has "A" for the card and "V" for internal memory.
1828 *
1829 * params: PTPParams*
1830 * char* name - path name
1831 *
1832 * Return values: Some PTP_RC_* code.
1833 * uint32_t *oid - PTP object id.
1834 *
1835 **/
1836uint16_t
Linus Walleij7347d0f2006-10-23 07:23:39 +00001837ptp_canon_get_objecthandle_by_name (PTPParams* params, char* name, uint32_t* objectid)
Linus Walleij0468fe72006-09-13 11:49:52 +00001838{
1839 uint16_t ret;
1840 PTPContainer ptp;
1841 unsigned char *data = NULL;
1842 uint8_t len;
1843
1844 PTP_CNT_INIT (ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001845 ptp.Code=PTP_OC_CANON_GetObjectHandleByName;
Linus Walleij0468fe72006-09-13 11:49:52 +00001846 ptp.Nparam=0;
1847 len=0;
1848 data = malloc (2*(strlen(name)+1)+2);
1849 memset (data, 0, 2*(strlen(name)+1)+2);
1850 ptp_pack_string (params, name, data, 0, &len);
1851 ret=ptp_transaction (params, &ptp, PTP_DP_SENDDATA, (len+1)*2+1, &data, NULL);
1852 free (data);
1853 *objectid = ptp.Param1;
1854 return ret;
1855}
1856
1857/**
Linus Walleij7347d0f2006-10-23 07:23:39 +00001858 * ptp_canon_get_customize_data:
Linus Walleijb02a0662006-04-25 08:05:09 +00001859 *
1860 * This command downloads the specified theme slot, including jpegs
1861 * and wav files.
1862 *
1863 * params: PTPParams*
1864 * uint32_t themenr - nr of theme
1865 *
1866 * Return values: Some PTP_RC_* code.
1867 * unsigned char **data - pointer to data pointer
1868 * unsigned int *size - size of data returned
1869 *
1870 **/
1871uint16_t
Linus Walleij7347d0f2006-10-23 07:23:39 +00001872ptp_canon_get_customize_data (PTPParams* params, uint32_t themenr,
Linus Walleijb02a0662006-04-25 08:05:09 +00001873 unsigned char **data, unsigned int *size)
1874{
1875 PTPContainer ptp;
1876
1877 *data = NULL;
1878 *size = 0;
1879 PTP_CNT_INIT(ptp);
Linus Walleij7347d0f2006-10-23 07:23:39 +00001880 ptp.Code = PTP_OC_CANON_GetCustomizeData;
Linus Walleijb02a0662006-04-25 08:05:09 +00001881 ptp.Param1 = themenr;
1882 ptp.Nparam = 1;
1883 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1884}
1885
1886
Linus Walleijb02a0662006-04-25 08:05:09 +00001887uint16_t
1888ptp_nikon_curve_download (PTPParams* params, unsigned char **data, unsigned int *size) {
1889 PTPContainer ptp;
1890 *data = NULL;
1891 *size = 0;
1892 PTP_CNT_INIT(ptp);
1893 ptp.Code = PTP_OC_NIKON_CurveDownload;
1894 ptp.Nparam = 0;
1895 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1896}
1897
1898uint16_t
1899ptp_nikon_getfileinfoinblock ( PTPParams* params,
1900 uint32_t p1, uint32_t p2, uint32_t p3,
1901 unsigned char **data, unsigned int *size
1902) {
1903 PTPContainer ptp;
1904 *data = NULL;
1905 *size = 0;
1906 PTP_CNT_INIT(ptp);
1907 ptp.Code = PTP_OC_NIKON_GetFileInfoInBlock;
1908 ptp.Nparam = 3;
1909 ptp.Param1 = p1;
1910 ptp.Param2 = p2;
1911 ptp.Param3 = p3;
1912 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
1913}
1914
1915/**
1916 * ptp_nikon_setcontrolmode:
1917 *
1918 * This command can switch the camera to full PC control mode.
1919 *
1920 * params: PTPParams*
1921 * uint32_t mode - mode
1922 *
1923 * Return values: Some PTP_RC_* code.
1924 *
1925 **/
1926uint16_t
1927ptp_nikon_setcontrolmode (PTPParams* params, uint32_t mode)
1928{
1929 PTPContainer ptp;
1930
1931 PTP_CNT_INIT(ptp);
1932 ptp.Code=PTP_OC_NIKON_SetControlMode;
1933 ptp.Param1=mode;
1934 ptp.Nparam=1;
1935 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1936}
1937
1938/**
1939 * ptp_nikon_capture:
1940 *
1941 * This command captures a picture on the Nikon.
1942 *
1943 * params: PTPParams*
1944 * uint32_t x - unknown parameter. seen to be -1.
1945 *
1946 * Return values: Some PTP_RC_* code.
1947 *
1948 **/
1949uint16_t
1950ptp_nikon_capture (PTPParams* params, uint32_t x)
1951{
1952 PTPContainer ptp;
1953
1954 PTP_CNT_INIT(ptp);
1955 ptp.Code=PTP_OC_NIKON_Capture;
1956 ptp.Param1=x;
1957 ptp.Nparam=1;
1958 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
1959}
1960
1961/**
1962 * ptp_nikon_check_event:
1963 *
1964 * This command checks the event queue on the Nikon.
1965 *
1966 * params: PTPParams*
1967 * PTPUSBEventContainer **event - list of usb events.
1968 * int *evtcnt - number of usb events in event structure.
1969 *
1970 * Return values: Some PTP_RC_* code.
1971 *
1972 **/
1973uint16_t
1974ptp_nikon_check_event (PTPParams* params, PTPUSBEventContainer** event, int* evtcnt)
1975{
1976 PTPContainer ptp;
1977 uint16_t ret;
1978 unsigned char *data = NULL;
1979 unsigned int size = 0;
1980
1981 PTP_CNT_INIT(ptp);
1982 ptp.Code=PTP_OC_NIKON_CheckEvent;
1983 ptp.Nparam=0;
1984 *evtcnt = 0;
1985 ret = ptp_transaction (params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
1986 if (ret == PTP_RC_OK) {
1987 ptp_unpack_Nikon_EC (params, data, size, event, evtcnt);
1988 free (data);
1989 }
1990 return ret;
1991}
1992
1993/**
1994 * ptp_nikon_device_ready:
1995 *
1996 * This command checks if the device is ready. Used after
1997 * a capture.
1998 *
1999 * params: PTPParams*
2000 *
2001 * Return values: Some PTP_RC_* code.
2002 *
2003 **/
2004uint16_t
2005ptp_nikon_device_ready (PTPParams* params)
2006{
2007 PTPContainer ptp;
2008
2009 PTP_CNT_INIT(ptp);
2010 ptp.Code=PTP_OC_NIKON_DeviceReady;
2011 ptp.Nparam=0;
2012 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
2013}
2014
2015/**
2016 * ptp_nikon_getptpipinfo:
2017 *
2018 * This command gets the ptpip info data.
2019 *
2020 * params: PTPParams*
2021 * unsigned char *data - data
2022 * unsigned int size - size of returned data
2023 *
2024 * Return values: Some PTP_RC_* code.
2025 *
2026 **/
2027uint16_t
2028ptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size)
2029{
2030 PTPContainer ptp;
2031
2032 PTP_CNT_INIT(ptp);
2033 ptp.Code=PTP_OC_NIKON_GetDevicePTPIPInfo;
2034 ptp.Nparam=0;
2035 return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size);
2036}
2037
2038/**
Linus Walleijaa4b0752006-07-26 22:21:04 +00002039 * ptp_nikon_getwifiprofilelist:
Linus Walleijb02a0662006-04-25 08:05:09 +00002040 *
Linus Walleijaa4b0752006-07-26 22:21:04 +00002041 * This command gets the wifi profile list.
Linus Walleijb02a0662006-04-25 08:05:09 +00002042 *
2043 * params: PTPParams*
Linus Walleijb02a0662006-04-25 08:05:09 +00002044 *
2045 * Return values: Some PTP_RC_* code.
2046 *
2047 **/
2048uint16_t
Linus Walleijaa4b0752006-07-26 22:21:04 +00002049ptp_nikon_getwifiprofilelist (PTPParams* params)
Linus Walleijb02a0662006-04-25 08:05:09 +00002050{
2051 PTPContainer ptp;
Linus Walleijaa4b0752006-07-26 22:21:04 +00002052 unsigned char* data;
2053 unsigned int size;
2054 unsigned int pos;
2055 unsigned int profn;
2056 unsigned int n;
2057 char* buffer;
2058 uint8_t len;
2059
Linus Walleijb02a0662006-04-25 08:05:09 +00002060 PTP_CNT_INIT(ptp);
2061 ptp.Code=PTP_OC_NIKON_GetProfileAllData;
2062 ptp.Nparam=0;
Linus Walleijaa4b0752006-07-26 22:21:04 +00002063 size = 0;
2064 data = NULL;
2065 CHECK_PTP_RC(ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size));
2066
2067 if (size < 2) return PTP_RC_Undefined; /* FIXME: Add more precise error code */
2068
2069 params->wifi_profiles_version = data[0];
2070 params->wifi_profiles_number = data[1];
2071 if (params->wifi_profiles)
2072 free(params->wifi_profiles);
2073
2074 params->wifi_profiles = malloc(params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));
2075 memset(params->wifi_profiles, 0, params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile));
2076
2077 pos = 2;
2078 profn = 0;
2079 while (profn < params->wifi_profiles_number && pos < size) {
2080 if (pos+6 >= size) return PTP_RC_Undefined;
2081 params->wifi_profiles[profn].id = data[pos++];
2082 params->wifi_profiles[profn].valid = data[pos++];
2083
2084 n = dtoh32a(&data[pos]);
2085 pos += 4;
2086 if (pos+n+4 >= size) return PTP_RC_Undefined;
2087 strncpy(params->wifi_profiles[profn].profile_name, (char*)&data[pos], n);
2088 params->wifi_profiles[profn].profile_name[16] = '\0';
2089 pos += n;
2090
2091 params->wifi_profiles[profn].display_order = data[pos++];
2092 params->wifi_profiles[profn].device_type = data[pos++];
2093 params->wifi_profiles[profn].icon_type = data[pos++];
2094
2095 buffer = ptp_unpack_string(params, data, pos, &len);
2096 strncpy(params->wifi_profiles[profn].creation_date, buffer, sizeof(params->wifi_profiles[profn].creation_date));
2097 pos += (len*2+1);
2098 if (pos+1 >= size) return PTP_RC_Undefined;
2099 /* FIXME: check if it is really last usage date */
2100 buffer = ptp_unpack_string(params, data, pos, &len);
2101 strncpy(params->wifi_profiles[profn].lastusage_date, buffer, sizeof(params->wifi_profiles[profn].lastusage_date));
2102 pos += (len*2+1);
2103 if (pos+5 >= size) return PTP_RC_Undefined;
2104
2105 n = dtoh32a(&data[pos]);
2106 pos += 4;
2107 if (pos+n >= size) return PTP_RC_Undefined;
2108 strncpy(params->wifi_profiles[profn].essid, (char*)&data[pos], n);
2109 params->wifi_profiles[profn].essid[32] = '\0';
2110 pos += n;
2111 pos += 1;
2112 profn++;
2113 }
2114
2115#if 0
2116 PTPNIKONWifiProfile test;
2117 memset(&test, 0, sizeof(PTPNIKONWifiProfile));
2118 strcpy(test.profile_name, "MyTest");
2119 test.icon_type = 1;
2120 strcpy(test.essid, "nikon");
2121 test.ip_address = 10 + 11 << 16 + 11 << 24;
2122 test.subnet_mask = 24;
2123 test.access_mode = 1;
2124 test.wifi_channel = 1;
2125 test.key_nr = 1;
2126
2127 ptp_nikon_writewifiprofile(params, &test);
2128#endif
2129
2130 return PTP_RC_OK;
Linus Walleijb02a0662006-04-25 08:05:09 +00002131}
2132
2133/**
Linus Walleijaa4b0752006-07-26 22:21:04 +00002134 * ptp_nikon_deletewifiprofile:
2135 *
2136 * This command deletes a wifi profile.
2137 *
2138 * params: PTPParams*
2139 * unsigned int profilenr - profile number
2140 *
2141 * Return values: Some PTP_RC_* code.
2142 *
2143 **/
2144uint16_t
2145ptp_nikon_deletewifiprofile (PTPParams* params, uint32_t profilenr)
2146{
2147 PTPContainer ptp;
2148
2149 PTP_CNT_INIT(ptp);
2150 ptp.Code=PTP_OC_NIKON_DeleteProfile;
2151 ptp.Nparam=1;
2152 ptp.Param1=profilenr;
2153 return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
2154}
2155
2156/**
2157 * ptp_nikon_writewifiprofile:
Linus Walleijb02a0662006-04-25 08:05:09 +00002158 *
2159 * This command gets the ptpip info data.
2160 *
2161 * params: PTPParams*
Linus Walleijaa4b0752006-07-26 22:21:04 +00002162 * unsigned int profilenr - profile number
Linus Walleijb02a0662006-04-25 08:05:09 +00002163 * unsigned char *data - data
2164 * unsigned int size - size of returned data
2165 *
2166 * Return values: Some PTP_RC_* code.
2167 *
2168 **/
2169uint16_t
Linus Walleijaa4b0752006-07-26 22:21:04 +00002170ptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* profile)
Linus Walleijb02a0662006-04-25 08:05:09 +00002171{
Linus Walleijaa4b0752006-07-26 22:21:04 +00002172 unsigned char guid[16];
2173
2174 PTPContainer ptp;
2175 unsigned char buffer[1024];
2176 unsigned char* data = buffer;
2177 int size = 0;
2178 int i;
2179 uint8_t len;
2180 int profilenr = -1;
2181
2182 ptp_nikon_getptpipguid(guid);
2183
2184 if (!params->wifi_profiles)
2185 CHECK_PTP_RC(ptp_nikon_getwifiprofilelist(params));
2186
2187 for (i = 0; i < params->wifi_profiles_number; i++) {
2188 if (!params->wifi_profiles[i].valid) {
2189 profilenr = params->wifi_profiles[i].id;
2190 break;
2191 }
2192 }
2193
2194 if (profilenr == -1) {
2195 /* No free profile! */
2196 return PTP_RC_StoreFull;
2197 }
2198
2199 memset(buffer, 0, 1024);
2200
2201 buffer[0x00] = 0x64; /* Version */
2202
2203 /* Profile name */
2204 htod32a(&buffer[0x01], 17);
2205 /* 16 as third parameter, so there will always be a null-byte in the end */
2206 strncpy((char*)&buffer[0x05], profile->profile_name, 16);
2207
2208 buffer[0x16] = 0x00; /* Display order */
2209 buffer[0x17] = profile->device_type;
2210 buffer[0x18] = profile->icon_type;
2211
2212 /* FIXME: Creation date: put a real date here */
2213 ptp_pack_string(params, "19990909T090909", data, 0x19, &len);
2214
2215 /* IP parameters */
2216 *((unsigned int*)&buffer[0x3A]) = profile->ip_address; /* Do not reverse bytes */
2217 buffer[0x3E] = profile->subnet_mask;
2218 *((unsigned int*)&buffer[0x3F]) = profile->gateway_address; /* Do not reverse bytes */
2219 buffer[0x43] = profile->address_mode;
2220
2221 /* Wifi parameters */
2222 buffer[0x44] = profile->access_mode;
2223 buffer[0x45] = profile->wifi_channel;
2224
2225 htod32a(&buffer[0x46], 33); /* essid */
2226 /* 32 as third parameter, so there will always be a null-byte in the end */
2227 strncpy((char*)&buffer[0x4A], profile->essid, 32);
2228
2229 buffer[0x6B] = profile->authentification;
2230 buffer[0x6C] = profile->encryption;
2231 htod32a(&buffer[0x6D], 64);
2232 for (i = 0; i < 64; i++) {
2233 buffer[0x71+i] = profile->key[i];
2234 }
2235 buffer[0xB1] = profile->key_nr;
2236 memcpy(&buffer[0xB2], guid, 16);
2237
2238 switch(profile->encryption) {
2239 case 1: /* WEP 64bit */
2240 htod16a(&buffer[0xC2], 5); /* (64-24)/8 = 5 */
2241 break;
2242 case 2: /* WEP 128bit */
2243 htod16a(&buffer[0xC2], 13); /* (128-24)/8 = 13 */
2244 break;
2245 default:
2246 htod16a(&buffer[0xC2], 0);
2247 }
2248 size = 0xC4;
2249
2250 PTP_CNT_INIT(ptp);
2251 ptp.Code=PTP_OC_NIKON_SendProfileData;
2252 ptp.Nparam=1;
2253 ptp.Param1=profilenr;
2254 return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
Linus Walleijb02a0662006-04-25 08:05:09 +00002255}
2256
2257/**
2258 * ptp_mtp_getobjectpropssupported:
2259 *
2260 * This command gets the object properties possible from the device.
2261 *
2262 * params: PTPParams*
2263 * uint ofc - object format code
2264 * unsigned int *propnum - number of elements in returned array
2265 * uint16_t *props - array of supported properties
2266 *
2267 * Return values: Some PTP_RC_* code.
2268 *
2269 **/
2270uint16_t
2271ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc,
2272 uint32_t *propnum, uint16_t **props
2273) {
2274 PTPContainer ptp;
2275 uint16_t ret;
2276 unsigned char *data = NULL;
2277 unsigned int size = 0;
2278
2279 PTP_CNT_INIT(ptp);
2280 ptp.Code=PTP_OC_MTP_GetObjectPropsSupported;
2281 ptp.Nparam = 1;
2282 ptp.Param1 = ofc;
2283 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
2284 if (ret == PTP_RC_OK)
2285 *propnum=ptp_unpack_uint16_t_array(params,data,0,props);
2286 free(data);
2287 return ret;
2288}
2289
2290/**
2291 * ptp_mtp_getobjectpropdesc:
2292 *
2293 * This command gets the object property description.
2294 *
2295 * params: PTPParams*
2296 * uint16_t opc - object property code
2297 * uint16_t ofc - object format code
2298 *
2299 * Return values: Some PTP_RC_* code.
2300 *
2301 **/
2302uint16_t
2303ptp_mtp_getobjectpropdesc (
2304 PTPParams* params, uint16_t opc, uint16_t ofc, PTPObjectPropDesc *opd
2305) {
2306 PTPContainer ptp;
2307 uint16_t ret;
2308 unsigned char *data = NULL;
2309 unsigned int size = 0;
2310
2311 PTP_CNT_INIT(ptp);
2312 ptp.Code=PTP_OC_MTP_GetObjectPropDesc;
2313 ptp.Nparam = 2;
2314 ptp.Param1 = opc;
2315 ptp.Param2 = ofc;
2316 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
2317 if (ret == PTP_RC_OK)
2318 ptp_unpack_OPD (params, data, opd, size);
2319 free(data);
2320 return ret;
2321}
2322
2323/**
2324 * ptp_mtp_getobjectpropvalue:
2325 *
2326 * This command gets the object properties of an object handle.
2327 *
2328 * params: PTPParams*
2329 * uint32_t objectid - object format code
2330 * uint16_t opc - object prop code
2331 *
2332 * Return values: Some PTP_RC_* code.
2333 *
2334 **/
2335uint16_t
2336ptp_mtp_getobjectpropvalue (
2337 PTPParams* params, uint32_t oid, uint16_t opc,
2338 PTPPropertyValue *value, uint16_t datatype
2339) {
2340 PTPContainer ptp;
2341 uint16_t ret;
2342 unsigned char *data = NULL;
2343 unsigned int size = 0;
2344 int offset = 0;
2345
2346 PTP_CNT_INIT(ptp);
2347 ptp.Code=PTP_OC_MTP_GetObjectPropValue;
2348 ptp.Nparam = 2;
2349 ptp.Param1 = oid;
2350 ptp.Param2 = opc;
2351 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size);
2352 if (ret == PTP_RC_OK)
2353 ptp_unpack_DPV(params, data, &offset, size, value, datatype);
2354 free(data);
2355 return ret;
2356}
2357
2358/**
2359 * ptp_mtp_setobjectpropvalue:
2360 *
2361 * This command gets the object properties of an object handle.
2362 *
2363 * params: PTPParams*
2364 * uint32_t objectid - object format code
2365 * uint16_t opc - object prop code
2366 *
2367 * Return values: Some PTP_RC_* code.
2368 *
2369 **/
2370uint16_t
2371ptp_mtp_setobjectpropvalue (
2372 PTPParams* params, uint32_t oid, uint16_t opc,
2373 PTPPropertyValue *value, uint16_t datatype
2374) {
2375 PTPContainer ptp;
2376 uint16_t ret;
2377 unsigned char *data = NULL;
2378 unsigned int size ;
2379
2380 PTP_CNT_INIT(ptp);
2381 ptp.Code=PTP_OC_MTP_SetObjectPropValue;
2382 ptp.Nparam = 2;
2383 ptp.Param1 = oid;
2384 ptp.Param2 = opc;
2385 size = ptp_pack_DPV(params, value, &data, datatype);
Linus Walleijf67bca92006-05-29 09:33:39 +00002386 ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL);
Linus Walleijb02a0662006-04-25 08:05:09 +00002387 free(data);
2388 return ret;
2389}
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002390
Linus Walleijf67bca92006-05-29 09:33:39 +00002391uint16_t
2392ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohArray, uint32_t* arraylen)
2393{
2394 PTPContainer ptp;
2395 uint16_t ret;
2396 unsigned char* dpv=NULL;
2397
2398 PTP_CNT_INIT(ptp);
2399 ptp.Code=PTP_OC_MTP_GetObjectReferences;
2400 ptp.Param1=handle;
2401 ptp.Nparam=1;
2402 ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, NULL);
2403 if (ret == PTP_RC_OK) *arraylen = ptp_unpack_uint32_t_array(params, dpv, 0, ohArray);
2404 free(dpv);
2405 return ret;
2406}
2407
2408uint16_t
2409ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArray, uint32_t arraylen)
2410{
2411 PTPContainer ptp;
2412 uint16_t ret;
2413 uint32_t size;
2414 unsigned char* dpv=NULL;
2415
2416 PTP_CNT_INIT(ptp);
2417 ptp.Code = PTP_OC_MTP_SetObjectReferences;
2418 ptp.Param1 = handle;
2419 ptp.Nparam = 1;
2420 size = ptp_pack_uint32_t_array(params, ohArray, arraylen, &dpv);
2421 ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, (unsigned char **)&dpv, NULL);
2422 free(dpv);
2423 return ret;
2424}
2425
Linus Walleij99310d42006-11-01 08:29:39 +00002426uint16_t
Linus Walleij3fcfea52006-11-13 07:07:36 +00002427ptp_mtp_getobjectproplist (PTPParams* params, uint32_t handle, MTPPropList **proplist)
2428{
2429 uint16_t ret;
2430 PTPContainer ptp;
Linus Walleij3fcfea52006-11-13 07:07:36 +00002431 unsigned char* opldata = NULL;
2432 unsigned int oplsize;
2433
2434 PTP_CNT_INIT(ptp);
2435 ptp.Code = PTP_OC_MTP_GetObjPropList;
2436 ptp.Param1 = handle;
Linus Walleij277cd532006-11-20 14:57:46 +00002437 ptp.Param2 = 0x00000000U; /* 0x00000000U should be "all formats" */
2438 ptp.Param3 = 0xFFFFFFFFU; /* 0xFFFFFFFFU should be "all properties" */
Linus Walleij3fcfea52006-11-13 07:07:36 +00002439 ptp.Param4 = 0x00000000U;
2440 ptp.Param5 = 0x00000000U;
2441 ptp.Nparam = 5;
Richard Low8d82d2f2006-11-16 20:37:43 +00002442 ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &opldata, &oplsize);
2443 if (ret == PTP_RC_OK) ptp_unpack_OPL(params, opldata, proplist, oplsize);
Linus Walleij277cd532006-11-20 14:57:46 +00002444 if (opldata != NULL)
2445 free(opldata);
Linus Walleij3fcfea52006-11-13 07:07:36 +00002446 return ret;
Linus Walleij3fcfea52006-11-13 07:07:36 +00002447}
2448
2449uint16_t
Linus Walleij99310d42006-11-01 08:29:39 +00002450ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle,
2451 uint16_t objecttype, uint64_t objectsize, MTPPropList *proplist)
2452{
2453 uint16_t ret;
2454 PTPContainer ptp;
Linus Walleij99310d42006-11-01 08:29:39 +00002455 unsigned char* opldata=NULL;
2456 uint32_t oplsize;
2457
2458 PTP_CNT_INIT(ptp);
2459 ptp.Code = PTP_OC_MTP_SendObjectPropList;
2460 ptp.Param1 = *store;
2461 ptp.Param2 = *parenthandle;
2462 ptp.Param3 = (uint32_t) objecttype;
2463 ptp.Param4 = (uint32_t) (objectsize >> 32);
2464 ptp.Param5 = (uint32_t) (objectsize & 0xffffffffU);
2465 ptp.Nparam = 5;
Linus Walleij0fa47022007-01-03 08:21:23 +00002466
Linus Walleij99310d42006-11-01 08:29:39 +00002467 /* Set object handle to 0 for a new object */
Richard Low6c0a6ce2006-11-26 10:42:08 +00002468 oplsize = ptp_pack_OPL(params,proplist,&opldata);
Linus Walleij99310d42006-11-01 08:29:39 +00002469 ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL);
2470 free(opldata);
2471 *store = ptp.Param1;
2472 *parenthandle = ptp.Param2;
2473 *handle = ptp.Param3;
Linus Walleij0fa47022007-01-03 08:21:23 +00002474
Linus Walleij99310d42006-11-01 08:29:39 +00002475 return ret;
2476}
2477
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002478/* Non PTP protocol functions */
2479/* devinfo testing functions */
2480
2481int
2482ptp_operation_issupported(PTPParams* params, uint16_t operation)
2483{
2484 int i=0;
2485
2486 for (;i<params->deviceinfo.OperationsSupported_len;i++) {
2487 if (params->deviceinfo.OperationsSupported[i]==operation)
2488 return 1;
2489 }
2490 return 0;
2491}
2492
2493
2494int
Linus Walleijb02a0662006-04-25 08:05:09 +00002495ptp_event_issupported(PTPParams* params, uint16_t event)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002496{
2497 int i=0;
2498
Linus Walleijb02a0662006-04-25 08:05:09 +00002499 for (;i<params->deviceinfo.EventsSupported_len;i++) {
2500 if (params->deviceinfo.EventsSupported[i]==event)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002501 return 1;
2502 }
2503 return 0;
2504}
2505
Linus Walleijb02a0662006-04-25 08:05:09 +00002506
2507int
2508ptp_property_issupported(PTPParams* params, uint16_t property)
2509{
2510 int i=0;
2511
2512 for (;i<params->deviceinfo.DevicePropertiesSupported_len;i++)
2513 if (params->deviceinfo.DevicePropertiesSupported[i]==property)
2514 return 1;
2515 return 0;
2516}
2517
2518/* ptp structures freeing functions */
2519void
2520ptp_free_devicepropvalue(uint16_t dt, PTPPropertyValue* dpd) {
2521 switch (dt) {
2522 case PTP_DTC_INT8: case PTP_DTC_UINT8:
2523 case PTP_DTC_UINT16: case PTP_DTC_INT16:
2524 case PTP_DTC_UINT32: case PTP_DTC_INT32:
2525 case PTP_DTC_UINT64: case PTP_DTC_INT64:
2526 case PTP_DTC_UINT128: case PTP_DTC_INT128:
2527 /* Nothing to free */
2528 break;
2529 case PTP_DTC_AINT8: case PTP_DTC_AUINT8:
2530 case PTP_DTC_AUINT16: case PTP_DTC_AINT16:
2531 case PTP_DTC_AUINT32: case PTP_DTC_AINT32:
2532 case PTP_DTC_AUINT64: case PTP_DTC_AINT64:
2533 case PTP_DTC_AUINT128: case PTP_DTC_AINT128:
2534 if (dpd->a.v)
2535 free(dpd->a.v);
2536 break;
2537 case PTP_DTC_STR:
2538 if (dpd->str)
2539 free(dpd->str);
2540 break;
2541 }
2542}
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002543
2544void
2545ptp_free_devicepropdesc(PTPDevicePropDesc* dpd)
2546{
2547 uint16_t i;
2548
Linus Walleijb02a0662006-04-25 08:05:09 +00002549 ptp_free_devicepropvalue (dpd->DataType, &dpd->FactoryDefaultValue);
2550 ptp_free_devicepropvalue (dpd->DataType, &dpd->CurrentValue);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002551 switch (dpd->FormFlag) {
Linus Walleijb02a0662006-04-25 08:05:09 +00002552 case PTP_DPFF_Range:
2553 ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MinimumValue);
2554 ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MaximumValue);
2555 ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.StepSize);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002556 break;
Linus Walleijb02a0662006-04-25 08:05:09 +00002557 case PTP_DPFF_Enumeration:
2558 if (dpd->FORM.Enum.SupportedValue) {
2559 for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++)
2560 ptp_free_devicepropvalue (dpd->DataType, dpd->FORM.Enum.SupportedValue+i);
2561 free (dpd->FORM.Enum.SupportedValue);
2562 }
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002563 }
2564}
2565
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002566void
Linus Walleijb02a0662006-04-25 08:05:09 +00002567ptp_free_objectpropdesc(PTPObjectPropDesc* opd)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002568{
Linus Walleijb02a0662006-04-25 08:05:09 +00002569 uint16_t i;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002570
Linus Walleijb02a0662006-04-25 08:05:09 +00002571 ptp_free_devicepropvalue (opd->DataType, &opd->FactoryDefaultValue);
2572 switch (opd->FormFlag) {
2573 case PTP_OPFF_None:
2574 break;
2575 case PTP_OPFF_Range:
2576 ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MinimumValue);
2577 ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MaximumValue);
2578 ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.StepSize);
2579 break;
2580 case PTP_OPFF_Enumeration:
2581 if (opd->FORM.Enum.SupportedValue) {
2582 for (i=0;i<opd->FORM.Enum.NumberOfValues;i++)
2583 ptp_free_devicepropvalue (opd->DataType, opd->FORM.Enum.SupportedValue+i);
2584 free (opd->FORM.Enum.SupportedValue);
2585 }
2586 default:
2587 fprintf (stderr, "Unknown OPFF type %d\n", opd->FormFlag);
2588 break;
2589 }
2590}
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002591
2592void
2593ptp_perror(PTPParams* params, uint16_t error) {
2594
2595 int i;
2596 /* PTP error descriptions */
2597 static struct {
Linus Walleijb02a0662006-04-25 08:05:09 +00002598 short n;
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002599 const char *txt;
2600 } ptp_errors[] = {
2601 {PTP_RC_Undefined, N_("PTP: Undefined Error")},
2602 {PTP_RC_OK, N_("PTP: OK!")},
2603 {PTP_RC_GeneralError, N_("PTP: General Error")},
2604 {PTP_RC_SessionNotOpen, N_("PTP: Session Not Open")},
2605 {PTP_RC_InvalidTransactionID, N_("PTP: Invalid Transaction ID")},
2606 {PTP_RC_OperationNotSupported, N_("PTP: Operation Not Supported")},
2607 {PTP_RC_ParameterNotSupported, N_("PTP: Parameter Not Supported")},
2608 {PTP_RC_IncompleteTransfer, N_("PTP: Incomplete Transfer")},
2609 {PTP_RC_InvalidStorageId, N_("PTP: Invalid Storage ID")},
2610 {PTP_RC_InvalidObjectHandle, N_("PTP: Invalid Object Handle")},
2611 {PTP_RC_DevicePropNotSupported, N_("PTP: Device Prop Not Supported")},
2612 {PTP_RC_InvalidObjectFormatCode, N_("PTP: Invalid Object Format Code")},
2613 {PTP_RC_StoreFull, N_("PTP: Store Full")},
2614 {PTP_RC_ObjectWriteProtected, N_("PTP: Object Write Protected")},
2615 {PTP_RC_StoreReadOnly, N_("PTP: Store Read Only")},
2616 {PTP_RC_AccessDenied, N_("PTP: Access Denied")},
2617 {PTP_RC_NoThumbnailPresent, N_("PTP: No Thumbnail Present")},
2618 {PTP_RC_SelfTestFailed, N_("PTP: Self Test Failed")},
2619 {PTP_RC_PartialDeletion, N_("PTP: Partial Deletion")},
2620 {PTP_RC_StoreNotAvailable, N_("PTP: Store Not Available")},
2621 {PTP_RC_SpecificationByFormatUnsupported,
2622 N_("PTP: Specification By Format Unsupported")},
2623 {PTP_RC_NoValidObjectInfo, N_("PTP: No Valid Object Info")},
2624 {PTP_RC_InvalidCodeFormat, N_("PTP: Invalid Code Format")},
2625 {PTP_RC_UnknownVendorCode, N_("PTP: Unknown Vendor Code")},
2626 {PTP_RC_CaptureAlreadyTerminated,
2627 N_("PTP: Capture Already Terminated")},
Linus Walleijb02a0662006-04-25 08:05:09 +00002628 {PTP_RC_DeviceBusy, N_("PTP: Device Busy")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002629 {PTP_RC_InvalidParentObject, N_("PTP: Invalid Parent Object")},
2630 {PTP_RC_InvalidDevicePropFormat, N_("PTP: Invalid Device Prop Format")},
2631 {PTP_RC_InvalidDevicePropValue, N_("PTP: Invalid Device Prop Value")},
2632 {PTP_RC_InvalidParameter, N_("PTP: Invalid Parameter")},
2633 {PTP_RC_SessionAlreadyOpened, N_("PTP: Session Already Opened")},
2634 {PTP_RC_TransactionCanceled, N_("PTP: Transaction Canceled")},
2635 {PTP_RC_SpecificationOfDestinationUnsupported,
2636 N_("PTP: Specification Of Destination Unsupported")},
Linus Walleijb02a0662006-04-25 08:05:09 +00002637 {PTP_RC_EK_FilenameRequired, N_("PTP: EK Filename Required")},
2638 {PTP_RC_EK_FilenameConflicts, N_("PTP: EK Filename Conflicts")},
2639 {PTP_RC_EK_FilenameInvalid, N_("PTP: EK Filename Invalid")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002640
2641 {PTP_ERROR_IO, N_("PTP: I/O error")},
2642 {PTP_ERROR_BADPARAM, N_("PTP: Error: bad parameter")},
2643 {PTP_ERROR_DATA_EXPECTED, N_("PTP: Protocol error, data expected")},
2644 {PTP_ERROR_RESP_EXPECTED, N_("PTP: Protocol error, response expected")},
2645 {0, NULL}
Linus Walleijb02a0662006-04-25 08:05:09 +00002646};
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002647
2648 for (i=0; ptp_errors[i].txt!=NULL; i++)
Linus Walleijb02a0662006-04-25 08:05:09 +00002649 if (ptp_errors[i].n == error)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002650 ptp_error(params, ptp_errors[i].txt);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002651}
2652
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002653const char*
Linus Walleijb02a0662006-04-25 08:05:09 +00002654ptp_get_property_description(PTPParams* params, uint16_t dpc)
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002655{
2656 int i;
Linus Walleija823a702006-08-27 21:27:46 +00002657 /* Device Property descriptions */
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002658 struct {
2659 uint16_t dpc;
2660 const char *txt;
2661 } ptp_device_properties[] = {
Linus Walleijb02a0662006-04-25 08:05:09 +00002662 {PTP_DPC_Undefined, N_("Undefined PTP Property")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002663 {PTP_DPC_BatteryLevel, N_("Battery Level")},
2664 {PTP_DPC_FunctionalMode, N_("Functional Mode")},
2665 {PTP_DPC_ImageSize, N_("Image Size")},
2666 {PTP_DPC_CompressionSetting, N_("Compression Setting")},
2667 {PTP_DPC_WhiteBalance, N_("White Balance")},
2668 {PTP_DPC_RGBGain, N_("RGB Gain")},
2669 {PTP_DPC_FNumber, N_("F-Number")},
2670 {PTP_DPC_FocalLength, N_("Focal Length")},
2671 {PTP_DPC_FocusDistance, N_("Focus Distance")},
2672 {PTP_DPC_FocusMode, N_("Focus Mode")},
2673 {PTP_DPC_ExposureMeteringMode, N_("Exposure Metering Mode")},
2674 {PTP_DPC_FlashMode, N_("Flash Mode")},
2675 {PTP_DPC_ExposureTime, N_("Exposure Time")},
2676 {PTP_DPC_ExposureProgramMode, N_("Exposure Program Mode")},
2677 {PTP_DPC_ExposureIndex,
2678 N_("Exposure Index (film speed ISO)")},
2679 {PTP_DPC_ExposureBiasCompensation,
2680 N_("Exposure Bias Compensation")},
2681 {PTP_DPC_DateTime, N_("Date Time")},
2682 {PTP_DPC_CaptureDelay, N_("Pre-Capture Delay")},
2683 {PTP_DPC_StillCaptureMode, N_("Still Capture Mode")},
2684 {PTP_DPC_Contrast, N_("Contrast")},
2685 {PTP_DPC_Sharpness, N_("Sharpness")},
2686 {PTP_DPC_DigitalZoom, N_("Digital Zoom")},
2687 {PTP_DPC_EffectMode, N_("Effect Mode")},
2688 {PTP_DPC_BurstNumber, N_("Burst Number")},
2689 {PTP_DPC_BurstInterval, N_("Burst Interval")},
2690 {PTP_DPC_TimelapseNumber, N_("Timelapse Number")},
2691 {PTP_DPC_TimelapseInterval, N_("Timelapse Interval")},
2692 {PTP_DPC_FocusMeteringMode, N_("Focus Metering Mode")},
2693 {PTP_DPC_UploadURL, N_("Upload URL")},
2694 {PTP_DPC_Artist, N_("Artist")},
2695 {PTP_DPC_CopyrightInfo, N_("Copyright Info")},
2696 {0,NULL}
2697 };
2698 struct {
2699 uint16_t dpc;
2700 const char *txt;
2701 } ptp_device_properties_EK[] = {
Linus Walleijb02a0662006-04-25 08:05:09 +00002702 {PTP_DPC_EK_ColorTemperature, N_("Color Temperature")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002703 {PTP_DPC_EK_DateTimeStampFormat,
Linus Walleijb02a0662006-04-25 08:05:09 +00002704 N_("Date Time Stamp Format")},
2705 {PTP_DPC_EK_BeepMode, N_("Beep Mode")},
2706 {PTP_DPC_EK_VideoOut, N_("Video Out")},
2707 {PTP_DPC_EK_PowerSaving, N_("Power Saving")},
2708 {PTP_DPC_EK_UI_Language, N_("UI Language")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002709 {0,NULL}
2710 };
2711
2712 struct {
2713 uint16_t dpc;
2714 const char *txt;
Linus Walleijb02a0662006-04-25 08:05:09 +00002715 } ptp_device_properties_Canon[] = {
2716 {PTP_DPC_CANON_BeepMode, N_("Beep Mode")},
2717 {PTP_DPC_CANON_ViewfinderMode, N_("Viewfinder Mode")},
2718 {PTP_DPC_CANON_ImageQuality, N_("Image Quality")},
2719 {PTP_DPC_CANON_ImageSize, N_("Image Size")},
2720 {PTP_DPC_CANON_FlashMode, N_("Flash Mode")},
2721 {PTP_DPC_CANON_ShootingMode, N_("Shooting Mode")},
2722 {PTP_DPC_CANON_MeteringMode, N_("Metering Mode")},
2723 {PTP_DPC_CANON_AFDistance, N_("AF Distance")},
2724 {PTP_DPC_CANON_FocusingPoint, N_("Focusing Point")},
2725 {PTP_DPC_CANON_WhiteBalance, N_("White Balance")},
2726 {PTP_DPC_CANON_ISOSpeed, N_("ISO Speed")},
2727 {PTP_DPC_CANON_Aperture, N_("Aperture")},
2728 {PTP_DPC_CANON_ShutterSpeed, N_("ShutterSpeed")},
2729 {PTP_DPC_CANON_ExpCompensation, N_("Exposure Compensation")},
2730 {PTP_DPC_CANON_Zoom, N_("Zoom")},
2731 {PTP_DPC_CANON_SizeQualityMode, N_("Size Quality Mode")},
2732 {PTP_DPC_CANON_FirmwareVersion, N_("Firmware Version")},
2733 {PTP_DPC_CANON_CameraModel, N_("Camera Model")},
2734 {PTP_DPC_CANON_CameraOwner, N_("Camera Owner")},
2735 {PTP_DPC_CANON_UnixTime, N_("UNIX Time")},
2736 {PTP_DPC_CANON_DZoomMagnification, N_("Digital Zoom Magnification")},
2737 {PTP_DPC_CANON_PhotoEffect, N_("Photo Effect")},
2738 {PTP_DPC_CANON_AssistLight, N_("Assist Light")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002739 {0,NULL}
2740 };
Linus Walleijb02a0662006-04-25 08:05:09 +00002741
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002742 struct {
2743 uint16_t dpc;
2744 const char *txt;
Linus Walleijb02a0662006-04-25 08:05:09 +00002745 } ptp_device_properties_Nikon[] = {
2746 {PTP_DPC_NIKON_WhiteBalanceAutoBias, /* 0xD017 */
2747 N_("Auto White Balance Bias")},
2748 {PTP_DPC_NIKON_WhiteBalanceTungstenBias, /* 0xD018 */
2749 N_("Tungsten White Balance Bias")},
Linus Walleij4f40d112006-09-21 07:44:53 +00002750 {PTP_DPC_NIKON_WhiteBalanceFluorescentBias, /* 0xD019 */
2751 N_("Fluorescent White Balance Bias")},
Linus Walleijb02a0662006-04-25 08:05:09 +00002752 {PTP_DPC_NIKON_WhiteBalanceDaylightBias, /* 0xD01a */
2753 N_("Daylight White Balance Bias")},
2754 {PTP_DPC_NIKON_WhiteBalanceFlashBias, /* 0xD01b */
2755 N_("Flash White Balance Bias")},
2756 {PTP_DPC_NIKON_WhiteBalanceCloudyBias, /* 0xD01c */
2757 N_("Cloudy White Balance Bias")},
2758 {PTP_DPC_NIKON_WhiteBalanceShadeBias, /* 0xD01d */
2759 N_("Shady White Balance Bias")},
2760 {PTP_DPC_NIKON_WhiteBalanceColorTemperature, /* 0xD01e */
2761 N_("White Balance Colour Temperature")},
2762 {PTP_DPC_NIKON_ImageSharpening, /* 0xD02a */
2763 N_("Sharpening")},
2764 {PTP_DPC_NIKON_ToneCompensation, /* 0xD02b */
2765 N_("Tone Compensation")},
2766 {PTP_DPC_NIKON_ColorModel, /* 0xD02c */
2767 N_("Color Model")},
2768 {PTP_DPC_NIKON_HueAdjustment, /* 0xD02d */
2769 N_("Hue Adjustment")},
2770 {PTP_DPC_NIKON_NonCPULensDataFocalLength, /* 0xD02e */
2771 N_("Lens Focal Length (Non CPU)")},
2772 {PTP_DPC_NIKON_NonCPULensDataMaximumAperture, /* 0xD02f */
2773 N_("Lens Max. Aperture (Non CPU)")},
2774 {PTP_DPC_NIKON_CSMMenuBankSelect, /* 0xD040 */
2775 "PTP_DPC_NIKON_CSMMenuBankSelect"},
2776 {PTP_DPC_NIKON_MenuBankNameA, /* 0xD041 */
2777 "PTP_DPC_NIKON_MenuBankNameA"},
2778 {PTP_DPC_NIKON_MenuBankNameB, /* 0xD042 */
2779 "PTP_DPC_NIKON_MenuBankNameB"},
2780 {PTP_DPC_NIKON_MenuBankNameC, /* 0xD043 */
2781 "PTP_DPC_NIKON_MenuBankNameC"},
2782 {PTP_DPC_NIKON_MenuBankNameD, /* 0xD044 */
2783 "PTP_DPC_NIKON_MenuBankNameD"},
2784 {PTP_DPC_NIKON_A1AFCModePriority, /* 0xD048 */
2785 "PTP_DPC_NIKON_A1AFCModePriority"},
2786 {PTP_DPC_NIKON_A2AFSModePriority, /* 0xD049 */
2787 "PTP_DPC_NIKON_A2AFSModePriority"},
2788 {PTP_DPC_NIKON_A3GroupDynamicAF, /* 0xD04a */
2789 "PTP_DPC_NIKON_A3GroupDynamicAF"},
2790 {PTP_DPC_NIKON_A4AFActivation, /* 0xD04b */
2791 "PTP_DPC_NIKON_A4AFActivation"},
2792 {PTP_DPC_NIKON_A5FocusAreaIllumManualFocus, /* 0xD04c */
2793 "PTP_DPC_NIKON_A5FocusAreaIllumManualFocus"},
2794 {PTP_DPC_NIKON_FocusAreaIllumContinuous, /* 0xD04d */
2795 "PTP_DPC_NIKON_FocusAreaIllumContinuous"},
2796 {PTP_DPC_NIKON_FocusAreaIllumWhenSelected, /* 0xD04e */
2797 "PTP_DPC_NIKON_FocusAreaIllumWhenSelected"},
2798 {PTP_DPC_NIKON_FocusAreaWrap, /* 0xD04f */
2799 N_("Focus Area Wrap")},
2800 {PTP_DPC_NIKON_A7VerticalAFON, /* 0xD050 */
2801 N_("Vertical AF On")},
2802 {PTP_DPC_NIKON_ISOAuto, /* 0xD054 */
2803 N_("Auto ISO")},
2804 {PTP_DPC_NIKON_B2ISOStep, /* 0xD055 */
2805 N_("ISO Step")},
2806 {PTP_DPC_NIKON_EVStep, /* 0xD056 */
2807 N_("Exposure Step")},
2808 {PTP_DPC_NIKON_B4ExposureCompEv, /* 0xD057 */
2809 N_("Exposure Compensation (EV)")},
2810 {PTP_DPC_NIKON_ExposureCompensation, /* 0xD058 */
2811 N_("Exposure Compensation")},
2812 {PTP_DPC_NIKON_CenterWeightArea, /* 0xD059 */
2813 N_("Centre Weight Area")},
2814 {PTP_DPC_NIKON_AELockMode, /* 0xD05e */
2815 N_("Exposure Lock")},
2816 {PTP_DPC_NIKON_AELAFLMode, /* 0xD05f */
2817 N_("Focus Lock")},
2818 {PTP_DPC_NIKON_MeterOff, /* 0xD062 */
2819 N_("Auto Meter Off Time")},
2820 {PTP_DPC_NIKON_SelfTimer, /* 0xD063 */
2821 N_("Self Timer Delay")},
2822 {PTP_DPC_NIKON_MonitorOff, /* 0xD064 */
2823 N_("LCD Off Time")},
2824 {PTP_DPC_NIKON_D1ShootingSpeed, /* 0xD068 */
2825 N_("Shooting Speed")},
2826 {PTP_DPC_NIKON_D2MaximumShots, /* 0xD069 */
2827 N_("Max. Shots")},
2828 {PTP_DPC_NIKON_D3ExpDelayMode, /* 0xD06a */
Linus Walleijd208f9c2006-04-27 14:16:06 +00002829 "PTP_DPC_NIKON_D3ExpDelayMode"},
Linus Walleijb02a0662006-04-25 08:05:09 +00002830 {PTP_DPC_NIKON_LongExposureNoiseReduction, /* 0xD06b */
2831 N_("Long Exposure Noise Reduction")},
2832 {PTP_DPC_NIKON_FileNumberSequence, /* 0xD06c */
2833 N_("File Number Sequencing")},
2834 {PTP_DPC_NIKON_D6ControlPanelFinderRearControl, /* 0xD06d */
Linus Walleijd208f9c2006-04-27 14:16:06 +00002835 "PTP_DPC_NIKON_D6ControlPanelFinderRearControl"},
Linus Walleijb02a0662006-04-25 08:05:09 +00002836 {PTP_DPC_NIKON_ControlPanelFinderViewfinder, /* 0xD06e */
Linus Walleijd208f9c2006-04-27 14:16:06 +00002837 "PTP_DPC_NIKON_ControlPanelFinderViewfinder"},
Linus Walleijb02a0662006-04-25 08:05:09 +00002838 {PTP_DPC_NIKON_D7Illumination, /* 0xD06f */
Linus Walleijd208f9c2006-04-27 14:16:06 +00002839 "PTP_DPC_NIKON_D7Illumination"},
Linus Walleijb02a0662006-04-25 08:05:09 +00002840 {PTP_DPC_NIKON_E1FlashSyncSpeed, /* 0xD074 */
2841 N_("Flash Sync. Speed")},
2842 {PTP_DPC_NIKON_FlashShutterSpeed, /* 0xD075 */
2843 N_("Flash Shutter Speed")},
2844 {PTP_DPC_NIKON_E3AAFlashMode, /* 0xD076 */
2845 N_("Flash Mode")},
2846 {PTP_DPC_NIKON_E4ModelingFlash, /* 0xD077 */
2847 N_("Modeling Flash")},
2848 {PTP_DPC_NIKON_BracketSet, /* 0xD078 */
2849 N_("Bracket Set")},
2850 {PTP_DPC_NIKON_E6ManualModeBracketing, /* 0xD079 */
2851 N_("Manual Mode Bracketing")},
2852 {PTP_DPC_NIKON_BracketOrder, /* 0xD07a */
2853 N_("Bracket Order")},
2854 {PTP_DPC_NIKON_E8AutoBracketSelection, /* 0xD07b */
2855 N_("Auto Bracket Selection")},
2856 {PTP_DPC_NIKON_F1CenterButtonShootingMode, /* 0xD080 */
2857 N_("Center Button Shooting Mode")},
2858 {PTP_DPC_NIKON_CenterButtonPlaybackMode, /* 0xD081 */
2859 N_("Center Button Playback Mode")},
2860 {PTP_DPC_NIKON_F2Multiselector, /* 0xD082 */
2861 N_("Multiselector")},
2862 {PTP_DPC_NIKON_F3PhotoInfoPlayback, /* 0xD083 */
2863 N_("Photo Info. Playback")},
2864 {PTP_DPC_NIKON_F4AssignFuncButton, /* 0xD084 */
2865 N_("Assign Func. Button")},
2866 {PTP_DPC_NIKON_F5CustomizeCommDials, /* 0xD085 */
2867 N_("Customise Command Dials")},
2868 {PTP_DPC_NIKON_ReverseCommandDial, /* 0xD086 */
2869 N_("Reverse Command Dial")},
2870 {PTP_DPC_NIKON_ApertureSetting, /* 0xD087 */
2871 N_("Aperture Setting")},
2872 {PTP_DPC_NIKON_MenusAndPlayback, /* 0xD088 */
2873 N_("Menus and Playback")},
2874 {PTP_DPC_NIKON_F6ButtonsAndDials, /* 0xD089 */
2875 N_("Buttons and Dials")},
2876 {PTP_DPC_NIKON_NoCFCard, /* 0xD08a */
2877 N_("No CF Card Release")},
2878 {PTP_DPC_NIKON_ImageRotation, /* 0xD092 */
2879 N_("Image Rotation")},
2880 {PTP_DPC_NIKON_Bracketing, /* 0xD0c0 */
2881 N_("Exposure Bracketing")},
2882 {PTP_DPC_NIKON_ExposureBracketingIntervalDist, /* 0xD0c1 */
2883 N_("Exposure Bracketing Distance")},
2884 {PTP_DPC_NIKON_BracketingProgram, /* 0xD0c2 */
2885 N_("Exposure Bracketing Number")},
2886 {PTP_DPC_NIKON_AutofocusLCDTopMode2, /* 0xD107 */
2887 N_("AF LCD Top Mode 2")},
2888 {PTP_DPC_NIKON_AutofocusArea, /* 0xD108 */
2889 N_("Active AF Sensor")},
2890 {PTP_DPC_NIKON_LightMeter, /* 0xD10a */
2891 N_("Exposure Meter")},
2892 {PTP_DPC_NIKON_ExposureApertureLock, /* 0xD111 */
2893 N_("Exposure Aperture Lock")},
2894 {PTP_DPC_NIKON_MaximumShots, /* 0xD103 */
2895 N_("Maximum Shots")},
2896 {PTP_DPC_NIKON_OptimizeImage, /* 0xD140 */
2897 N_("Optimize Image")},
2898 {PTP_DPC_NIKON_Saturation, /* 0xD142 */
2899 N_("Saturation")},
2900 {PTP_DPC_NIKON_CSMMenu, /* 0xD180 */
2901 N_("CSM Menu")},
2902 {PTP_DPC_NIKON_BeepOff,
2903 N_("AF Beep Mode")},
2904 {PTP_DPC_NIKON_AutofocusMode,
2905 N_("Autofocus Mode")},
2906 {PTP_DPC_NIKON_AFAssist,
2907 N_("AF Assist Lamp")},
2908 {PTP_DPC_NIKON_PADVPMode,
2909 N_("Auto ISO P/A/DVP Setting")},
2910 {PTP_DPC_NIKON_ImageReview,
2911 N_("Image Review")},
2912 {PTP_DPC_NIKON_GridDisplay,
2913 N_("Viewfinder Grid Display")},
2914 {PTP_DPC_NIKON_AFAreaIllumination,
2915 N_("AF Area Illumination")},
2916 {PTP_DPC_NIKON_FlashMode,
2917 N_("Flash Mode")},
2918 {PTP_DPC_NIKON_FlashModeManualPower,
2919 N_("Flash Mode Manual Power")},
2920 {PTP_DPC_NIKON_FlashSign,
2921 N_("Flash Sign")},
2922 {PTP_DPC_NIKON_FlashExposureCompensation,
2923 N_("Flash Exposure Compensation")},
2924 {PTP_DPC_NIKON_RemoteTimeout,
2925 N_("Remote Timeout")},
2926 {PTP_DPC_NIKON_ImageCommentString,
2927 N_("Image Comment String")},
2928 {PTP_DPC_NIKON_FlashOpen,
2929 N_("Flash Open")},
2930 {PTP_DPC_NIKON_FlashCharged,
2931 N_("Flash Charged")},
2932 {PTP_DPC_NIKON_LensID,
2933 N_("Lens ID")},
2934 {PTP_DPC_NIKON_FocalLengthMin,
2935 N_("Min. Focal Length")},
2936 {PTP_DPC_NIKON_FocalLengthMax,
2937 N_("Max. Focal Length")},
2938 {PTP_DPC_NIKON_MaxApAtMinFocalLength,
2939 N_("Max. Aperture at Min. Focal Length")},
2940 {PTP_DPC_NIKON_MaxApAtMaxFocalLength,
2941 N_("Max. Aperture at Max. Focal Length")},
2942 {PTP_DPC_NIKON_LowLight,
2943 N_("Low Light")},
Linus Walleij037a1252006-12-16 20:36:52 +00002944 {PTP_DPC_NIKON_ACPower, N_("AC Power")},
2945 {PTP_DPC_NIKON_BracketingSet, N_("NIKON Auto Bracketing Set")},
2946 {PTP_DPC_NIKON_WhiteBalanceBracketStep, N_("NIKON White Balance Bracket Step")},
2947 {PTP_DPC_NIKON_AFLLock, N_("NIKON AF-L Locked")},
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002948 {0,NULL}
2949 };
Linus Walleij545c7792006-06-13 15:22:30 +00002950 struct {
2951 uint16_t dpc;
2952 const char *txt;
2953 } ptp_device_properties_MTP[] = {
2954 {PTP_DPC_MTP_SecureTime, N_("Secure Time")},
2955 {PTP_DPC_MTP_DeviceCertificate, N_("Device Certificate")},
2956 {PTP_DPC_MTP_SynchronizationPartner,
2957 N_("Synchronization Partner")},
2958 {PTP_DPC_MTP_DeviceFriendlyName,
2959 N_("Device Friendly Name")},
2960 {PTP_DPC_MTP_VolumeLevel, N_("Volume Level")},
2961 {PTP_DPC_MTP_DeviceIcon, N_("Device Icon")},
2962 {PTP_DPC_MTP_PlaybackRate, N_("Playback Rate")},
2963 {PTP_DPC_MTP_PlaybackObject, N_("Playback Object")},
2964 {PTP_DPC_MTP_PlaybackContainerIndex,
2965 N_("Playback Container Index")},
2966 {PTP_DPC_MTP_PlaybackPosition, N_("Playback Position")},
Linus Walleij5fb47132006-12-30 15:35:48 +00002967 {PTP_DPC_MTP_RevocationInfo, N_("RevocationInfo")},
2968 {PTP_DPC_MTP_PlaysForSureID, N_("PlaysForSureID")},
Linus Walleij545c7792006-06-13 15:22:30 +00002969 {0,NULL}
2970 };
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002971
2972 for (i=0; ptp_device_properties[i].txt!=NULL; i++)
2973 if (ptp_device_properties[i].dpc==dpc)
2974 return (ptp_device_properties[i].txt);
2975
Linus Walleij545c7792006-06-13 15:22:30 +00002976 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT)
2977 for (i=0; ptp_device_properties_MTP[i].txt!=NULL; i++)
2978 if (ptp_device_properties_MTP[i].dpc==dpc)
2979 return (ptp_device_properties_MTP[i].txt);
2980
Linus Walleijb02a0662006-04-25 08:05:09 +00002981 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_EASTMAN_KODAK)
2982 for (i=0; ptp_device_properties_EK[i].txt!=NULL; i++)
2983 if (ptp_device_properties_EK[i].dpc==dpc)
2984 return (ptp_device_properties_EK[i].txt);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002985
Linus Walleijb02a0662006-04-25 08:05:09 +00002986 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_CANON)
2987 for (i=0; ptp_device_properties_Canon[i].txt!=NULL; i++)
2988 if (ptp_device_properties_Canon[i].dpc==dpc)
2989 return (ptp_device_properties_Canon[i].txt);
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002990
Linus Walleijb02a0662006-04-25 08:05:09 +00002991 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON)
2992 for (i=0; ptp_device_properties_Nikon[i].txt!=NULL; i++)
2993 if (ptp_device_properties_Nikon[i].dpc==dpc)
2994 return (ptp_device_properties_Nikon[i].txt);
2995
Linus Walleijeb8c6fe2006-02-03 09:46:22 +00002996 return NULL;
2997}
2998
Linus Walleijb02a0662006-04-25 08:05:09 +00002999static int64_t
3000_value_to_num(PTPPropertyValue *data, uint16_t dt) {
3001 if (dt == PTP_DTC_STR) {
3002 if (!data->str)
3003 return 0;
3004 return atol(data->str);
3005 }
3006 if (dt & PTP_DTC_ARRAY_MASK) {
3007 return 0;
3008 } else {
3009 switch (dt) {
3010 case PTP_DTC_UNDEF:
3011 return 0;
3012 case PTP_DTC_INT8:
3013 return data->i8;
3014 case PTP_DTC_UINT8:
3015 return data->u8;
3016 case PTP_DTC_INT16:
3017 return data->i16;
3018 case PTP_DTC_UINT16:
3019 return data->u16;
3020 case PTP_DTC_INT32:
3021 return data->i32;
3022 case PTP_DTC_UINT32:
3023 return data->u32;
3024 /*
3025 PTP_DTC_INT64
3026 PTP_DTC_UINT64
3027 PTP_DTC_INT128
3028 PTP_DTC_UINT128
3029 */
3030 default:
3031 return 0;
3032 }
3033 }
3034
3035 return 0;
3036}
3037
3038#define PTP_VAL_BOOL(dpc) {dpc, 0, N_("Off")}, {dpc, 1, N_("On")}
3039#define PTP_VAL_RBOOL(dpc) {dpc, 0, N_("On")}, {dpc, 1, N_("Off")}
3040#define PTP_VAL_YN(dpc) {dpc, 0, N_("No")}, {dpc, 1, N_("Yes")}
3041
3042int
3043ptp_render_property_value(PTPParams* params, uint16_t dpc,
3044 PTPDevicePropDesc *dpd, int length, char *out)
3045{
3046 int i;
3047
3048 struct {
3049 uint16_t dpc;
3050 double coef;
3051 double bias;
3052 const char *format;
3053 } ptp_value_trans[] = {
3054 {PTP_DPC_ExposureIndex, 1.0, 0.0, "ISO %.0f"},
3055 {0, 0.0, 0.0, NULL}
3056 };
3057
3058 struct {
3059 uint16_t dpc;
3060 double coef;
3061 double bias;
3062 const char *format;
3063 } ptp_value_trans_Nikon[] = {
3064 {PTP_DPC_BatteryLevel, 1.0, 0.0, "%.0f%%"},
3065 {PTP_DPC_FNumber, 0.01, 0.0, "f/%.2g"},
3066 {PTP_DPC_FocalLength, 0.01, 0.0, "%.0f mm"},
3067 {PTP_DPC_ExposureTime, 0.00001, 0.0, "%.2g sec"},
3068 {PTP_DPC_ExposureBiasCompensation, 0.001, 0.0, N_("%.1f stops")},
3069 {PTP_DPC_NIKON_LightMeter, 0.08333, 0.0, N_("%.1f stops")},
3070 {PTP_DPC_NIKON_FlashExposureCompensation, 0.16666, 0.0, N_("%.1f stops")},
3071 {PTP_DPC_NIKON_CenterWeightArea, 2.0, 6.0, N_("%.0f mm")},
3072 {PTP_DPC_NIKON_FocalLengthMin, 0.01, 0.0, "%.0f mm"},
3073 {PTP_DPC_NIKON_FocalLengthMax, 0.01, 0.0, "%.0f mm"},
3074 {PTP_DPC_NIKON_MaxApAtMinFocalLength, 0.01, 0.0, "f/%.2g"},
3075 {PTP_DPC_NIKON_MaxApAtMaxFocalLength, 0.01, 0.0, "f/%.2g"},
3076 {0, 0.0, 0.0, NULL}
3077 };
3078
3079 struct {
3080 uint16_t dpc;
3081 int64_t key;
3082 char *value;
3083 } ptp_value_list_Nikon[] = {
3084 {PTP_DPC_CompressionSetting, 0, N_("JPEG Basic")},
3085 {PTP_DPC_CompressionSetting, 1, N_("JPEG Norm")},
3086 {PTP_DPC_CompressionSetting, 2, N_("JPEG Fine")},
3087 {PTP_DPC_CompressionSetting, 4, N_("RAW")},
3088 {PTP_DPC_CompressionSetting, 5, N_("RAW + JPEG Basic")},
3089 {PTP_DPC_WhiteBalance, 2, N_("Auto")},
3090 {PTP_DPC_WhiteBalance, 6, N_("Incandescent")},
3091 {PTP_DPC_WhiteBalance, 5, N_("Fluorescent")},
3092 {PTP_DPC_WhiteBalance, 4, N_("Daylight")},
3093 {PTP_DPC_WhiteBalance, 7, N_("Flash")},
3094 {PTP_DPC_WhiteBalance, 32784, N_("Cloudy")},
3095 {PTP_DPC_WhiteBalance, 32785, N_("Shade")},
Linus Walleij037a1252006-12-16 20:36:52 +00003096 {PTP_DPC_WhiteBalance, 32786, N_("Color Temperature")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003097 {PTP_DPC_WhiteBalance, 32787, N_("Preset")},
3098 {PTP_DPC_FlashMode, 32784, N_("Default")},
3099 {PTP_DPC_FlashMode, 4, N_("Red-eye Reduction")},
3100 {PTP_DPC_FlashMode, 32787, N_("Red-eye Reduction + Slow Sync")},
3101 {PTP_DPC_FlashMode, 32785, N_("Slow Sync")},
3102 {PTP_DPC_FlashMode, 32785, N_("Rear Curtain Sync + Slow Sync")},
3103 {PTP_DPC_FocusMeteringMode, 2, N_("Dynamic Area")},
3104 {PTP_DPC_FocusMeteringMode, 32784, N_("Single Area")},
3105 {PTP_DPC_FocusMeteringMode, 32785, N_("Closest Subject")},
Linus Walleij037a1252006-12-16 20:36:52 +00003106 {PTP_DPC_FocusMeteringMode, 32786, N_("Group Dynamic")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003107 {PTP_DPC_FocusMode, 1, N_("Manual Focus")},
3108 {PTP_DPC_FocusMode, 32784, "AF-S"},
3109 {PTP_DPC_FocusMode, 32785, "AF-C"},
3110 PTP_VAL_BOOL(PTP_DPC_NIKON_ISOAuto),
3111 PTP_VAL_BOOL(PTP_DPC_NIKON_ExposureCompensation),
3112 PTP_VAL_BOOL(PTP_DPC_NIKON_AELockMode),
3113 {PTP_DPC_NIKON_AELAFLMode, 0, N_("AE/AF Lock")},
3114 {PTP_DPC_NIKON_AELAFLMode, 1, N_("AF Lock only")},
3115 {PTP_DPC_NIKON_AELAFLMode, 2, N_("AE Lock only")},
3116 {PTP_DPC_NIKON_AELAFLMode, 3, N_("AF Lock Hold")},
3117 {PTP_DPC_NIKON_AELAFLMode, 4, N_("AF On")},
3118 {PTP_DPC_NIKON_AELAFLMode, 5, N_("Flash Lock")},
3119 {PTP_DPC_ExposureMeteringMode, 2, N_("Center Weighted")},
3120 {PTP_DPC_ExposureMeteringMode, 3, N_("Matrix")},
3121 {PTP_DPC_ExposureMeteringMode, 4, N_("Spot")},
3122 {PTP_DPC_ExposureProgramMode, 1, "M"},
3123 {PTP_DPC_ExposureProgramMode, 3, "A"},
3124 {PTP_DPC_ExposureProgramMode, 4, "S"},
3125 {PTP_DPC_ExposureProgramMode, 2, "P"},
3126 {PTP_DPC_ExposureProgramMode, 32784, N_("Auto")},
3127 {PTP_DPC_ExposureProgramMode, 32785, N_("Portrait")},
3128 {PTP_DPC_ExposureProgramMode, 32786, N_("Landscape")},
3129 {PTP_DPC_ExposureProgramMode, 32787, N_("Macro")},
3130 {PTP_DPC_ExposureProgramMode, 32788, N_("Sports")},
3131 {PTP_DPC_ExposureProgramMode, 32790, N_("Night Landscape")},
3132 {PTP_DPC_ExposureProgramMode, 32789, N_("Night Portrait")},
3133 {PTP_DPC_StillCaptureMode, 1, N_("Single Shot")},
3134 {PTP_DPC_StillCaptureMode, 2, N_("Power Wind")},
Linus Walleij037a1252006-12-16 20:36:52 +00003135 {PTP_DPC_StillCaptureMode, 32784, N_("Continuous Low Speed")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003136 {PTP_DPC_StillCaptureMode, 32785, N_("Timer")},
3137 {PTP_DPC_StillCaptureMode, 32787, N_("Remote")},
Linus Walleij037a1252006-12-16 20:36:52 +00003138 {PTP_DPC_StillCaptureMode, 32787, N_("Mirror Up")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003139 {PTP_DPC_StillCaptureMode, 32788, N_("Timer + Remote")},
3140 PTP_VAL_BOOL(PTP_DPC_NIKON_AutofocusMode),
3141 PTP_VAL_RBOOL(PTP_DPC_NIKON_AFAssist),
3142 PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageReview),
3143 PTP_VAL_BOOL(PTP_DPC_NIKON_GridDisplay),
3144 {PTP_DPC_NIKON_AFAreaIllumination, 0, N_("Auto")},
3145 {PTP_DPC_NIKON_AFAreaIllumination, 1, N_("Off")},
3146 {PTP_DPC_NIKON_AFAreaIllumination, 2, N_("On")},
3147 {PTP_DPC_NIKON_ColorModel, 0, "sRGB"},
3148 {PTP_DPC_NIKON_ColorModel, 1, "AdobeRGB"},
3149 {PTP_DPC_NIKON_ColorModel, 2, "sRGB"},
3150 {PTP_DPC_NIKON_FlashMode, 0, "iTTL"},
3151 {PTP_DPC_NIKON_FlashMode, 1, N_("Manual")},
3152 {PTP_DPC_NIKON_FlashMode, 2, N_("Commander")},
3153 {PTP_DPC_NIKON_FlashModeManualPower, 0, N_("Full")},
3154 {PTP_DPC_NIKON_FlashModeManualPower, 1, "1/2"},
3155 {PTP_DPC_NIKON_FlashModeManualPower, 2, "1/4"},
3156 {PTP_DPC_NIKON_FlashModeManualPower, 3, "1/8"},
3157 {PTP_DPC_NIKON_FlashModeManualPower, 4, "1/16"},
3158 PTP_VAL_RBOOL(PTP_DPC_NIKON_FlashSign),
3159 {PTP_DPC_NIKON_RemoteTimeout, 0, N_("1 min")},
3160 {PTP_DPC_NIKON_RemoteTimeout, 1, N_("5 mins")},
3161 {PTP_DPC_NIKON_RemoteTimeout, 2, N_("10 mins")},
3162 {PTP_DPC_NIKON_RemoteTimeout, 3, N_("15 mins")},
3163 PTP_VAL_YN(PTP_DPC_NIKON_FlashOpen),
3164 PTP_VAL_YN(PTP_DPC_NIKON_FlashCharged),
3165 PTP_VAL_BOOL(PTP_DPC_NIKON_LongExposureNoiseReduction),
3166 PTP_VAL_BOOL(PTP_DPC_NIKON_FileNumberSequence),
3167 PTP_VAL_BOOL(PTP_DPC_NIKON_ReverseCommandDial),
3168 PTP_VAL_RBOOL(PTP_DPC_NIKON_NoCFCard),
3169 PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageRotation),
3170 PTP_VAL_BOOL(PTP_DPC_NIKON_Bracketing),
3171 {PTP_DPC_NIKON_AutofocusArea, 0, N_("Centre")},
3172 {PTP_DPC_NIKON_AutofocusArea, 1, N_("Top")},
3173 {PTP_DPC_NIKON_AutofocusArea, 2, N_("Bottom")},
3174 {PTP_DPC_NIKON_AutofocusArea, 3, N_("Left")},
3175 {PTP_DPC_NIKON_AutofocusArea, 4, N_("Right")},
3176 {PTP_DPC_NIKON_OptimizeImage, 0, N_("Normal")},
3177 {PTP_DPC_NIKON_OptimizeImage, 1, N_("Vivid")},
3178 {PTP_DPC_NIKON_OptimizeImage, 2, N_("Sharper")},
3179 {PTP_DPC_NIKON_OptimizeImage, 3, N_("Softer")},
3180 {PTP_DPC_NIKON_OptimizeImage, 4, N_("Direct Print")},
3181 {PTP_DPC_NIKON_OptimizeImage, 5, N_("Portrait")},
3182 {PTP_DPC_NIKON_OptimizeImage, 6, N_("Landscape")},
3183 {PTP_DPC_NIKON_OptimizeImage, 7, N_("Custom")},
3184
3185 {PTP_DPC_NIKON_ImageSharpening, 0, N_("Auto")},
3186 {PTP_DPC_NIKON_ImageSharpening, 1, N_("Normal")},
3187 {PTP_DPC_NIKON_ImageSharpening, 2, N_("Low")},
3188 {PTP_DPC_NIKON_ImageSharpening, 3, N_("Medium Low")},
3189 {PTP_DPC_NIKON_ImageSharpening, 4, N_("Medium high")},
3190 {PTP_DPC_NIKON_ImageSharpening, 5, N_("High")},
3191 {PTP_DPC_NIKON_ImageSharpening, 6, N_("None")},
3192
3193 {PTP_DPC_NIKON_ToneCompensation, 0, N_("Auto")},
3194 {PTP_DPC_NIKON_ToneCompensation, 1, N_("Normal")},
3195 {PTP_DPC_NIKON_ToneCompensation, 2, N_("Low contrast")},
3196 {PTP_DPC_NIKON_ToneCompensation, 3, N_("Medium low")},
3197 {PTP_DPC_NIKON_ToneCompensation, 4, N_("Medium high")},
3198 {PTP_DPC_NIKON_ToneCompensation, 5, N_("High control")},
3199 {PTP_DPC_NIKON_ToneCompensation, 6, N_("Custom")},
3200
3201 {PTP_DPC_NIKON_Saturation, 0, N_("Normal")},
3202 {PTP_DPC_NIKON_Saturation, 1, N_("Moderate")},
3203 {PTP_DPC_NIKON_Saturation, 2, N_("Enhanced")},
3204
3205 {PTP_DPC_NIKON_LensID, 0, N_("Unknown")},
3206 {PTP_DPC_NIKON_LensID, 38, "Sigma 70-300mm 1:4-5.6 D APO Macro"},
3207 {PTP_DPC_NIKON_LensID, 83, "AF Nikkor 80-200mm 1:2.8 D ED"},
3208 {PTP_DPC_NIKON_LensID, 118, "AF Nikkor 50mm 1:1.8 D"},
3209 {PTP_DPC_NIKON_LensID, 127, "AF-S Nikkor 18-70mm 1:3.5-4.5G ED DX"},
3210 PTP_VAL_YN(PTP_DPC_NIKON_LowLight),
3211 PTP_VAL_YN(PTP_DPC_NIKON_CSMMenu),
3212 PTP_VAL_RBOOL(PTP_DPC_NIKON_BeepOff),
3213 {0, 0, NULL}
3214 };
Linus Walleijb02a0662006-04-25 08:05:09 +00003215 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON) {
3216 int64_t kval;
3217
3218 for (i=0; ptp_value_trans[i].dpc!=0; i++)
3219 if (ptp_value_trans[i].dpc==dpc) {
3220 double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType);
3221
3222 return snprintf(out, length,
3223 _(ptp_value_trans[i].format),
3224 value * ptp_value_trans[i].coef +
3225 ptp_value_trans[i].bias);
3226 }
3227
3228 for (i=0; ptp_value_trans_Nikon[i].dpc!=0; i++)
3229 if (ptp_value_trans_Nikon[i].dpc==dpc) {
3230 double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType);
3231
3232 return snprintf(out, length,
3233 _(ptp_value_trans_Nikon[i].format),
3234 value * ptp_value_trans_Nikon[i].coef +
3235 ptp_value_trans_Nikon[i].bias);
3236 }
3237
3238 kval = _value_to_num(&(dpd->CurrentValue), dpd->DataType);
3239
3240 for (i=0; ptp_value_list_Nikon[i].dpc!=0; i++)
3241 if (ptp_value_list_Nikon[i].dpc==dpc &&
3242 ptp_value_list_Nikon[i].key==kval)
3243 return snprintf(out, length, "%s",
3244 _(ptp_value_list_Nikon[i].value));
3245 }
3246 if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT) {
3247 switch (dpc) {
Linus Walleij545c7792006-06-13 15:22:30 +00003248 case PTP_DPC_MTP_SynchronizationPartner:
3249 case PTP_DPC_MTP_DeviceFriendlyName:
Linus Walleijb02a0662006-04-25 08:05:09 +00003250 return snprintf(out, length, "%s", dpd->CurrentValue.str);
Linus Walleij545c7792006-06-13 15:22:30 +00003251 case PTP_DPC_MTP_SecureTime:
3252 case PTP_DPC_MTP_DeviceCertificate: {
Linus Walleija823a702006-08-27 21:27:46 +00003253 /* FIXME: Convert to use unicode demux functions */
Linus Walleijb02a0662006-04-25 08:05:09 +00003254 for (i=0;(i<dpd->CurrentValue.a.count) && (i<length);i++)
3255 out[i] = dpd->CurrentValue.a.v[i].u16;
3256 if ( dpd->CurrentValue.a.count &&
3257 (dpd->CurrentValue.a.count < length)) {
3258 out[dpd->CurrentValue.a.count-1] = 0;
3259 return dpd->CurrentValue.a.count-1;
3260 } else {
3261 out[length-1] = 0;
3262 return length;
3263 }
3264 break;
3265 }
3266 default:
3267 break;
3268 }
3269 }
3270
3271 return 0;
3272}
3273
3274struct {
3275 uint16_t ofc;
3276 const char *format;
3277} ptp_ofc_trans[] = {
3278 {PTP_OFC_Undefined,"Undefined Type"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003279 {PTP_OFC_Defined,"Defined Type"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003280 {PTP_OFC_Association,"Association/Directory"},
3281 {PTP_OFC_Script,"Script"},
3282 {PTP_OFC_Executable,"Executable"},
3283 {PTP_OFC_Text,"Text"},
3284 {PTP_OFC_HTML,"HTML"},
3285 {PTP_OFC_DPOF,"DPOF"},
3286 {PTP_OFC_AIFF,"AIFF"},
3287 {PTP_OFC_WAV,"MS Wave"},
3288 {PTP_OFC_MP3,"MP3"},
3289 {PTP_OFC_AVI,"MS AVI"},
3290 {PTP_OFC_MPEG,"MPEG"},
3291 {PTP_OFC_ASF,"ASF"},
3292 {PTP_OFC_QT,"Apple Quicktime"},
3293 {PTP_OFC_EXIF_JPEG,"JPEG"},
3294 {PTP_OFC_TIFF_EP,"TIFF EP"},
3295 {PTP_OFC_FlashPix,"FlashPix"},
3296 {PTP_OFC_BMP,"BMP"},
3297 {PTP_OFC_CIFF,"CIFF"},
3298 {PTP_OFC_GIF,"GIF"},
3299 {PTP_OFC_JFIF,"JFIF"},
3300 {PTP_OFC_PCD,"PCD"},
3301 {PTP_OFC_PICT,"PICT"},
3302 {PTP_OFC_PNG,"PNG"},
3303 {PTP_OFC_TIFF,"TIFF"},
3304 {PTP_OFC_TIFF_IT,"TIFF_IT"},
3305 {PTP_OFC_JP2,"JP2"},
3306 {PTP_OFC_JPX,"JPX"},
3307};
3308
3309struct {
3310 uint16_t ofc;
3311 const char *format;
3312} ptp_ofc_mtp_trans[] = {
Linus Walleij5fb47132006-12-30 15:35:48 +00003313 {PTP_OFC_MTP_MediaCard,N_("MediaCard")},
3314 {PTP_OFC_MTP_MediaCardGroup,N_("MediaCardGroup")},
3315 {PTP_OFC_MTP_Encounter,N_("Encounter")},
3316 {PTP_OFC_MTP_EncounterBox,N_("EncounterBox")},
3317 {PTP_OFC_MTP_M4A,N_("M4A")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003318 {PTP_OFC_MTP_Firmware,N_("Firmware")},
3319 {PTP_OFC_MTP_WindowsImageFormat,N_("WindowsImageFormat")},
3320 {PTP_OFC_MTP_UndefinedAudio,N_("Undefined Audio")},
3321 {PTP_OFC_MTP_WMA,"WMA"},
3322 {PTP_OFC_MTP_OGG,"OGG"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003323 {PTP_OFC_MTP_AAC,"AAC"},
Linus Walleijaa4b0752006-07-26 22:21:04 +00003324 {PTP_OFC_MTP_AudibleCodec,N_("Audible.com Codec")},
Linus Walleij5fb47132006-12-30 15:35:48 +00003325 {PTP_OFC_MTP_FLAC,"FLAC"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003326 {PTP_OFC_MTP_UndefinedVideo,N_("Undefined Video")},
3327 {PTP_OFC_MTP_WMV,"WMV"},
3328 {PTP_OFC_MTP_MP4,"MP4"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003329 {PTP_OFC_MTP_MP2,"MP2"},
3330 {PTP_OFC_MTP_3GP,"3GP"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003331 {PTP_OFC_MTP_UndefinedCollection,N_("Undefined Collection")},
3332 {PTP_OFC_MTP_AbstractMultimediaAlbum,N_("Abstract Multimedia Album")},
3333 {PTP_OFC_MTP_AbstractImageAlbum,N_("Abstract Image Album")},
3334 {PTP_OFC_MTP_AbstractAudioAlbum,N_("Abstract Audio Album")},
3335 {PTP_OFC_MTP_AbstractVideoAlbum,N_("Abstract Video Album")},
3336 {PTP_OFC_MTP_AbstractAudioVideoPlaylist,N_("Abstract Audio Video Playlist")},
3337 {PTP_OFC_MTP_AbstractContactGroup,N_("Abstract Contact Group")},
3338 {PTP_OFC_MTP_AbstractMessageFolder,N_("Abstract Message Folder")},
3339 {PTP_OFC_MTP_AbstractChapteredProduction,N_("Abstract Chaptered Production")},
Linus Walleij5fb47132006-12-30 15:35:48 +00003340 {PTP_OFC_MTP_AbstractAudioPlaylist,N_("Abstract Audio Playlist")},
3341 {PTP_OFC_MTP_AbstractVideoPlaylist,N_("Abstract Video Playlist")},
3342 {PTP_OFC_MTP_AbstractMediacast,N_("Abstract Mediacast")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003343 {PTP_OFC_MTP_WPLPlaylist,N_("WPL Playlist")},
3344 {PTP_OFC_MTP_M3UPlaylist,N_("M3U Playlist")},
3345 {PTP_OFC_MTP_MPLPlaylist,N_("MPL Playlist")},
3346 {PTP_OFC_MTP_ASXPlaylist,N_("ASX Playlist")},
3347 {PTP_OFC_MTP_PLSPlaylist,N_("PLS Playlist")},
3348 {PTP_OFC_MTP_UndefinedDocument,N_("UndefinedDocument")},
3349 {PTP_OFC_MTP_AbstractDocument,N_("AbstractDocument")},
Linus Walleij5fb47132006-12-30 15:35:48 +00003350 {PTP_OFC_MTP_XMLDocument,N_("XMLDocument")},
3351 {PTP_OFC_MTP_MSWordDocument,N_("Microsoft Word Document")},
3352 {PTP_OFC_MTP_MHTCompiledHTMLDocument,N_("MHT Compiled HTML Document")},
3353 {PTP_OFC_MTP_MSExcelSpreadsheetXLS,N_("Microsoft Excel Spreadsheet (.xls)")},
3354 {PTP_OFC_MTP_MSPowerpointPresentationPPT,N_("Microsoft Powerpoint (.ppt)")},
Linus Walleijb02a0662006-04-25 08:05:09 +00003355 {PTP_OFC_MTP_UndefinedMessage,N_("UndefinedMessage")},
3356 {PTP_OFC_MTP_AbstractMessage,N_("AbstractMessage")},
3357 {PTP_OFC_MTP_UndefinedContact,N_("UndefinedContact")},
3358 {PTP_OFC_MTP_AbstractContact,N_("AbstractContact")},
3359 {PTP_OFC_MTP_vCard2,N_("vCard2")},
3360 {PTP_OFC_MTP_vCard3,N_("vCard3")},
3361 {PTP_OFC_MTP_UndefinedCalendarItem,N_("UndefinedCalendarItem")},
3362 {PTP_OFC_MTP_AbstractCalendarItem,N_("AbstractCalendarItem")},
3363 {PTP_OFC_MTP_vCalendar1,N_("vCalendar1")},
3364 {PTP_OFC_MTP_vCalendar2,N_("vCalendar2")},
3365 {PTP_OFC_MTP_UndefinedWindowsExecutable,N_("Undefined Windows Executable")},
3366};
3367
3368int
3369ptp_render_ofc(PTPParams* params, uint16_t ofc, int spaceleft, char *txt)
3370{
3371 int i;
3372
3373 if (!(ofc & 0x8000)) {
3374 for (i=0;i<sizeof(ptp_ofc_trans)/sizeof(ptp_ofc_trans[0]);i++)
3375 if (ofc == ptp_ofc_trans[i].ofc)
3376 return snprintf(txt, spaceleft,_(ptp_ofc_trans[i].format));
3377 } else {
3378 switch (params->deviceinfo.VendorExtensionID) {
3379 case PTP_VENDOR_EASTMAN_KODAK:
3380 switch (ofc) {
3381 case PTP_OFC_EK_M3U:
3382 return snprintf (txt, spaceleft,_("M3U"));
3383 default:
3384 break;
3385 }
3386 break;
3387 case PTP_VENDOR_MICROSOFT:
3388 for (i=0;i<sizeof(ptp_ofc_mtp_trans)/sizeof(ptp_ofc_mtp_trans[0]);i++)
3389 if (ofc == ptp_ofc_mtp_trans[i].ofc)
3390 return snprintf(txt, spaceleft,_(ptp_ofc_mtp_trans[i].format));
3391 break;
3392 default:break;
3393 }
3394 }
3395 return snprintf (txt, spaceleft,_("Unknown(%04x)"), ofc);
3396}
3397
3398struct {
Linus Walleij7347d0f2006-10-23 07:23:39 +00003399 uint16_t opcode;
3400 const char *name;
3401} ptp_opcode_trans[] = {
3402 {PTP_OC_Undefined,N_("Undefined")},
3403 {PTP_OC_GetDeviceInfo,N_("get device info")},
3404 {PTP_OC_OpenSession,N_("Open session")},
3405 {PTP_OC_CloseSession,N_("Close session")},
3406 {PTP_OC_GetStorageIDs,N_("Get storage IDs")},
3407 {PTP_OC_GetStorageInfo,N_("Get storage info")},
3408 {PTP_OC_GetNumObjects,N_("Get number of objects")},
3409 {PTP_OC_GetObjectHandles,N_("Get object handles")},
3410 {PTP_OC_GetObjectInfo,N_("Get object info")},
3411 {PTP_OC_GetObject,N_("Get object")},
3412 {PTP_OC_GetThumb,N_("Get thumbnail")},
3413 {PTP_OC_DeleteObject,N_("Delete object")},
3414 {PTP_OC_SendObjectInfo,N_("Send object info")},
3415 {PTP_OC_SendObject,N_("Send object")},
3416 {PTP_OC_InitiateCapture,N_("Initiate capture")},
3417 {PTP_OC_FormatStore,N_("Format storage")},
3418 {PTP_OC_ResetDevice,N_("Reset device")},
3419 {PTP_OC_SelfTest,N_("Self test device")},
3420 {PTP_OC_SetObjectProtection,N_("Set object protection")},
3421 {PTP_OC_PowerDown,N_("Power down device")},
3422 {PTP_OC_GetDevicePropDesc,N_("Get device property description")},
3423 {PTP_OC_GetDevicePropValue,N_("Get device property value")},
3424 {PTP_OC_SetDevicePropValue,N_("Set device property value")},
3425 {PTP_OC_ResetDevicePropValue,N_("Reset device property value")},
3426 {PTP_OC_TerminateOpenCapture,N_("Terminate open capture")},
3427 {PTP_OC_MoveObject,N_("Move object")},
3428 {PTP_OC_CopyObject,N_("Copy object")},
3429 {PTP_OC_GetPartialObject,N_("Get partial object")},
3430 {PTP_OC_InitiateOpenCapture,N_("Initiate open capture")}
3431};
3432
3433struct {
3434 uint16_t opcode;
3435 const char *name;
3436} ptp_opcode_mtp_trans[] = {
3437 {PTP_OC_MTP_GetObjectPropsSupported,N_("Get object properties supported")},
3438 {PTP_OC_MTP_GetObjectPropDesc,N_("Get object property description")},
3439 {PTP_OC_MTP_GetObjectPropValue,N_("Get object property value")},
3440 {PTP_OC_MTP_SetObjectPropValue,N_("Set object property value")},
3441 {PTP_OC_MTP_GetObjPropList,N_("Get object property list")},
3442 {PTP_OC_MTP_SetObjPropList,N_("Set object property list")},
3443 {PTP_OC_MTP_GetInterdependendPropdesc,N_("Get interdependent property description")},
3444 {PTP_OC_MTP_SendObjectPropList,N_("Send object property list")},
3445 {PTP_OC_MTP_GetObjectReferences,N_("Get object references")},
3446 {PTP_OC_MTP_SetObjectReferences,N_("Set object references")},
3447 {PTP_OC_MTP_UpdateDeviceFirmware,N_("Update device firmware")},
Linus Walleij5fb47132006-12-30 15:35:48 +00003448 {PTP_OC_MTP_Skip,N_("Skip to next position in playlist")},
3449
3450 /* WMDRMPD Extensions */
3451 {PTP_OC_MTP_WMDRMPD_GetSecureTimeChallenge,N_("Get secure time challenge")},
3452 {PTP_OC_MTP_WMDRMPD_GetSecureTimeResponse,N_("Get secure time response")},
3453 {PTP_OC_MTP_WMDRMPD_SetLicenseResponse,N_("Set license response")},
3454 {PTP_OC_MTP_WMDRMPD_GetSyncList,N_("Get sync list")},
3455 {PTP_OC_MTP_WMDRMPD_SendMeterChallengeQuery,N_("Send meter challenge query")},
3456 {PTP_OC_MTP_WMDRMPD_GetMeterChallenge,N_("Get meter challenge")},
3457 {PTP_OC_MTP_WMDRMPD_SetMeterResponse,N_("Get meter response")},
3458 {PTP_OC_MTP_WMDRMPD_CleanDataStore,N_("Clean data store")},
3459 {PTP_OC_MTP_WMDRMPD_GetLicenseState,N_("Get license state")},
3460 {PTP_OC_MTP_WMDRMPD_SendWMDRMPDCommand,N_("Send WMDRM-PD Command")},
3461 {PTP_OC_MTP_WMDRMPD_SendWMDRMPDRequest,N_("Send WMDRM-PD Request")},
3462
3463 /* WMPPD Extensions */
3464 {PTP_OC_MTP_WMPPD_ReportAddedDeletedItems,N_("Report Added/Deleted Items")},
3465 {PTP_OC_MTP_WMPPD_ReportAcquiredItems,N_("Report Acquired Items")},
3466 {PTP_OC_MTP_WMPPD_PlaylistObjectPref,N_("Get type of playlists that are allowed to be transfered")},
3467
3468 /* WMDRMPD Extensions... these have no identifiers associated with them */
3469 {PTP_OC_MTP_WMDRMPD_SendWMDRMPDAppRequest,N_("Send WMDRM-PD Application Request")},
3470 {PTP_OC_MTP_WMDRMPD_GetWMDRMPDAppResponse,N_("Get WMDRM-PD Application Response")},
3471 {PTP_OC_MTP_WMDRMPD_EnableTrustedFilesOperations,N_("Enable trusted file operations")},
3472 {PTP_OC_MTP_WMDRMPD_DisableTrustedFilesOperations,N_("Disable trusted file operations")},
3473 {PTP_OC_MTP_WMDRMPD_EndTrustedAppSession,N_("End trusted application session")},
3474
Linus Walleijfa2d1d12007-01-01 17:08:13 +00003475 /* AAVT Extensions */
3476 {PTP_OC_MTP_AAVT_OpenMediaSession,N_("Open Media Session")},
3477 {PTP_OC_MTP_AAVT_CloseMediaSession,N_("Close Media Session")},
3478 {PTP_OC_MTP_AAVT_GetNextDataBlock,N_("Get Next Data Block")},
3479 {PTP_OC_MTP_AAVT_SetCurrentTimePosition,N_("Set Current Time Position")},
3480
Linus Walleij5fb47132006-12-30 15:35:48 +00003481 /* WMDRMND Extensions */
Linus Walleij5fb47132006-12-30 15:35:48 +00003482 {PTP_OC_MTP_WMDRMND_SendRegistrationRequest,N_("Send Registration Request")},
3483 {PTP_OC_MTP_WMDRMND_GetRegistrationResponse,N_("Get Registration Response")},
3484 {PTP_OC_MTP_WMDRMND_GetProximityChallenge,N_("Get Proximity Challenge")},
3485 {PTP_OC_MTP_WMDRMND_SendProximityResponse,N_("Send Proximity Response")},
3486 {PTP_OC_MTP_WMDRMND_SendWMDRMNDLicenseRequest,N_("Send WMDRM-ND License Request")},
3487 {PTP_OC_MTP_WMDRMND_GetWMDRMNDLicenseResponse,N_("Get WMDRM-ND License Response")},
3488
3489 /* WiFi Provisioning MTP Extension Codes (microsoft.com/WPDWCN: 1.0) */
3490 {PTP_OC_MTP_WPDWCN_ProcessWFCObject,N_("Process WFC Object")}
Linus Walleij7347d0f2006-10-23 07:23:39 +00003491};
3492
3493int
3494ptp_render_opcode(PTPParams* params, uint16_t opcode, int spaceleft, char *txt)
3495{
3496 int i;
3497
3498 if (!(opcode & 0x8000)) {
3499 for (i=0;i<sizeof(ptp_opcode_trans)/sizeof(ptp_opcode_trans[0]);i++)
3500 if (opcode == ptp_opcode_trans[i].opcode)
3501 return snprintf(txt, spaceleft,_(ptp_opcode_trans[i].name));
3502 } else {
3503 switch (params->deviceinfo.VendorExtensionID) {
3504 case PTP_VENDOR_MICROSOFT:
3505 for (i=0;i<sizeof(ptp_opcode_mtp_trans)/sizeof(ptp_opcode_mtp_trans[0]);i++)
3506 if (opcode == ptp_opcode_mtp_trans[i].opcode)
3507 return snprintf(txt, spaceleft,_(ptp_opcode_mtp_trans[i].name));
3508 break;
3509 default:break;
3510 }
3511 }
3512 return snprintf (txt, spaceleft,_("Unknown(%04x)"), opcode);
3513}
3514
3515
3516struct {
Linus Walleijb02a0662006-04-25 08:05:09 +00003517 uint16_t id;
3518 const char *name;
3519} ptp_opc_trans[] = {
3520 {PTP_OPC_StorageID,"StorageID"},
3521 {PTP_OPC_ObjectFormat,"ObjectFormat"},
3522 {PTP_OPC_ProtectionStatus,"ProtectionStatus"},
3523 {PTP_OPC_ObjectSize,"ObjectSize"},
3524 {PTP_OPC_AssociationType,"AssociationType"},
3525 {PTP_OPC_AssociationDesc,"AssociationDesc"},
3526 {PTP_OPC_ObjectFileName,"ObjectFileName"},
3527 {PTP_OPC_DateCreated,"DateCreated"},
3528 {PTP_OPC_DateModified,"DateModified"},
3529 {PTP_OPC_Keywords,"Keywords"},
3530 {PTP_OPC_ParentObject,"ParentObject"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003531 {PTP_OPC_AllowedFolderContents,"AllowedFolderContents"},
3532 {PTP_OPC_Hidden,"Hidden"},
3533 {PTP_OPC_SystemObject,"SystemObject"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003534 {PTP_OPC_PersistantUniqueObjectIdentifier,"PersistantUniqueObjectIdentifier"},
3535 {PTP_OPC_SyncID,"SyncID"},
3536 {PTP_OPC_PropertyBag,"PropertyBag"},
3537 {PTP_OPC_Name,"Name"},
3538 {PTP_OPC_CreatedBy,"CreatedBy"},
3539 {PTP_OPC_Artist,"Artist"},
3540 {PTP_OPC_DateAuthored,"DateAuthored"},
3541 {PTP_OPC_Description,"Description"},
3542 {PTP_OPC_URLReference,"URLReference"},
3543 {PTP_OPC_LanguageLocale,"LanguageLocale"},
3544 {PTP_OPC_CopyrightInformation,"CopyrightInformation"},
3545 {PTP_OPC_Source,"Source"},
3546 {PTP_OPC_OriginLocation,"OriginLocation"},
3547 {PTP_OPC_DateAdded,"DateAdded"},
3548 {PTP_OPC_NonConsumable,"NonConsumable"},
3549 {PTP_OPC_CorruptOrUnplayable,"CorruptOrUnplayable"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003550 {PTP_OPC_ProducerSerialNumber,"ProducerSerialNumber"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003551 {PTP_OPC_RepresentativeSampleFormat,"RepresentativeSampleFormat"},
3552 {PTP_OPC_RepresentativeSampleSize,"RepresentativeSampleSize"},
3553 {PTP_OPC_RepresentativeSampleHeight,"RepresentativeSampleHeight"},
3554 {PTP_OPC_RepresentativeSampleWidth,"RepresentativeSampleWidth"},
3555 {PTP_OPC_RepresentativeSampleDuration,"RepresentativeSampleDuration"},
3556 {PTP_OPC_RepresentativeSampleData,"RepresentativeSampleData"},
3557 {PTP_OPC_Width,"Width"},
3558 {PTP_OPC_Height,"Height"},
3559 {PTP_OPC_Duration,"Duration"},
3560 {PTP_OPC_Rating,"Rating"},
3561 {PTP_OPC_Track,"Track"},
3562 {PTP_OPC_Genre,"Genre"},
3563 {PTP_OPC_Credits,"Credits"},
3564 {PTP_OPC_Lyrics,"Lyrics"},
3565 {PTP_OPC_SubscriptionContentID,"SubscriptionContentID"},
3566 {PTP_OPC_ProducedBy,"ProducedBy"},
3567 {PTP_OPC_UseCount,"UseCount"},
3568 {PTP_OPC_SkipCount,"SkipCount"},
3569 {PTP_OPC_LastAccessed,"LastAccessed"},
3570 {PTP_OPC_ParentalRating,"ParentalRating"},
3571 {PTP_OPC_MetaGenre,"MetaGenre"},
3572 {PTP_OPC_Composer,"Composer"},
3573 {PTP_OPC_EffectiveRating,"EffectiveRating"},
3574 {PTP_OPC_Subtitle,"Subtitle"},
3575 {PTP_OPC_OriginalReleaseDate,"OriginalReleaseDate"},
3576 {PTP_OPC_AlbumName,"AlbumName"},
3577 {PTP_OPC_AlbumArtist,"AlbumArtist"},
3578 {PTP_OPC_Mood,"Mood"},
3579 {PTP_OPC_DRMStatus,"DRMStatus"},
3580 {PTP_OPC_SubDescription,"SubDescription"},
3581 {PTP_OPC_IsCropped,"IsCropped"},
3582 {PTP_OPC_IsColorCorrected,"IsColorCorrected"},
Linus Walleij5fb47132006-12-30 15:35:48 +00003583 {PTP_OPC_ImageBitDepth,"ImageBitDepth"},
3584 {PTP_OPC_Fnumber,"Fnumber"},
3585 {PTP_OPC_ExposureTime,"ExposureTime"},
3586 {PTP_OPC_ExposureIndex,"ExposureIndex"},
3587 {PTP_OPC_DisplayName,"DisplayName"},
3588 {PTP_OPC_BodyText,"BodyText"},
3589 {PTP_OPC_Subject,"Subject"},
3590 {PTP_OPC_Prority,"Prority"},
3591 {PTP_OPC_GivenName,"GivenName"},
3592 {PTP_OPC_MiddleNames,"MiddleNames"},
3593 {PTP_OPC_FamilyName,"FamilyName"},
3594
3595 {PTP_OPC_Prefix,"Prefix"},
3596 {PTP_OPC_Suffix,"Suffix"},
3597 {PTP_OPC_PhoneticGivenName,"PhoneticGivenName"},
3598 {PTP_OPC_PhoneticFamilyName,"PhoneticFamilyName"},
3599 {PTP_OPC_EmailPrimary,"EmailPrimary"},
3600 {PTP_OPC_EmailPersonal1,"EmailPersonal1"},
3601 {PTP_OPC_EmailPersonal2,"EmailPersonal2"},
3602 {PTP_OPC_EmailBusiness1,"EmailBusiness1"},
3603 {PTP_OPC_EmailBusiness2,"EmailBusiness2"},
3604 {PTP_OPC_EmailOthers,"EmailOthers"},
3605 {PTP_OPC_PhoneNumberPrimary,"PhoneNumberPrimary"},
3606 {PTP_OPC_PhoneNumberPersonal,"PhoneNumberPersonal"},
3607 {PTP_OPC_PhoneNumberPersonal2,"PhoneNumberPersonal2"},
3608 {PTP_OPC_PhoneNumberBusiness,"PhoneNumberBusiness"},
3609 {PTP_OPC_PhoneNumberBusiness2,"PhoneNumberBusiness2"},
3610 {PTP_OPC_PhoneNumberMobile,"PhoneNumberMobile"},
3611 {PTP_OPC_PhoneNumberMobile2,"PhoneNumberMobile2"},
3612 {PTP_OPC_FaxNumberPrimary,"FaxNumberPrimary"},
3613 {PTP_OPC_FaxNumberPersonal,"FaxNumberPersonal"},
3614 {PTP_OPC_FaxNumberBusiness,"FaxNumberBusiness"},
3615 {PTP_OPC_PagerNumber,"PagerNumber"},
3616 {PTP_OPC_PhoneNumberOthers,"PhoneNumberOthers"},
3617 {PTP_OPC_PrimaryWebAddress,"PrimaryWebAddress"},
3618 {PTP_OPC_PersonalWebAddress,"PersonalWebAddress"},
3619 {PTP_OPC_BusinessWebAddress,"BusinessWebAddress"},
3620 {PTP_OPC_InstantMessengerAddress,"InstantMessengerAddress"},
3621 {PTP_OPC_InstantMessengerAddress2,"InstantMessengerAddress2"},
3622 {PTP_OPC_InstantMessengerAddress3,"InstantMessengerAddress3"},
3623 {PTP_OPC_PostalAddressPersonalFull,"PostalAddressPersonalFull"},
3624 {PTP_OPC_PostalAddressPersonalFullLine1,"PostalAddressPersonalFullLine1"},
3625 {PTP_OPC_PostalAddressPersonalFullLine2,"PostalAddressPersonalFullLine2"},
3626 {PTP_OPC_PostalAddressPersonalFullCity,"PostalAddressPersonalFullCity"},
3627 {PTP_OPC_PostalAddressPersonalFullRegion,"PostalAddressPersonalFullRegion"},
3628 {PTP_OPC_PostalAddressPersonalFullPostalCode,"PostalAddressPersonalFullPostalCode"},
3629 {PTP_OPC_PostalAddressPersonalFullCountry,"PostalAddressPersonalFullCountry"},
3630 {PTP_OPC_PostalAddressBusinessFull,"PostalAddressBusinessFull"},
3631 {PTP_OPC_PostalAddressBusinessLine1,"PostalAddressBusinessLine1"},
3632 {PTP_OPC_PostalAddressBusinessLine2,"PostalAddressBusinessLine2"},
3633 {PTP_OPC_PostalAddressBusinessCity,"PostalAddressBusinessCity"},
3634 {PTP_OPC_PostalAddressBusinessRegion,"PostalAddressBusinessRegion"},
3635 {PTP_OPC_PostalAddressBusinessPostalCode,"PostalAddressBusinessPostalCode"},
3636 {PTP_OPC_PostalAddressBusinessCountry,"PostalAddressBusinessCountry"},
3637 {PTP_OPC_PostalAddressOtherFull,"PostalAddressOtherFull"},
3638 {PTP_OPC_PostalAddressOtherLine1,"PostalAddressOtherLine1"},
3639 {PTP_OPC_PostalAddressOtherLine2,"PostalAddressOtherLine2"},
3640 {PTP_OPC_PostalAddressOtherCity,"PostalAddressOtherCity"},
3641 {PTP_OPC_PostalAddressOtherRegion,"PostalAddressOtherRegion"},
3642 {PTP_OPC_PostalAddressOtherPostalCode,"PostalAddressOtherPostalCode"},
3643 {PTP_OPC_PostalAddressOtherCountry,"PostalAddressOtherCountry"},
3644 {PTP_OPC_OrganizationName,"OrganizationName"},
3645 {PTP_OPC_PhoneticOrganizationName,"PhoneticOrganizationName"},
3646 {PTP_OPC_Role,"Role"},
3647 {PTP_OPC_Birthdate,"Birthdate"},
3648 {PTP_OPC_MessageTo,"MessageTo"},
3649 {PTP_OPC_MessageCC,"MessageCC"},
3650 {PTP_OPC_MessageBCC,"MessageBCC"},
3651 {PTP_OPC_MessageRead,"MessageRead"},
3652 {PTP_OPC_MessageReceivedTime,"MessageReceivedTime"},
3653 {PTP_OPC_MessageSender,"MessageSender"},
3654 {PTP_OPC_ActivityBeginTime,"ActivityBeginTime"},
3655 {PTP_OPC_ActivityEndTime,"ActivityEndTime"},
3656 {PTP_OPC_ActivityLocation,"ActivityLocation"},
3657 {PTP_OPC_ActivityRequiredAttendees,"ActivityRequiredAttendees"},
3658 {PTP_OPC_ActivityOptionalAttendees,"ActivityOptionalAttendees"},
3659 {PTP_OPC_ActivityResources,"ActivityResources"},
3660 {PTP_OPC_ActivityAccepted,"ActivityAccepted"},
3661 {PTP_OPC_Owner,"Owner"},
3662 {PTP_OPC_Editor,"Editor"},
3663 {PTP_OPC_Webmaster,"Webmaster"},
3664 {PTP_OPC_URLSource,"URLSource"},
3665 {PTP_OPC_URLDestination,"URLDestination"},
3666 {PTP_OPC_TimeBookmark,"TimeBookmark"},
3667 {PTP_OPC_ObjectBookmark,"ObjectBookmark"},
3668 {PTP_OPC_ByteBookmark,"ByteBookmark"},
3669 {PTP_OPC_LastBuildDate,"LastBuildDate"},
3670 {PTP_OPC_TimetoLive,"TimetoLive"},
3671 {PTP_OPC_MediaGUID,"MediaGUID"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003672 {PTP_OPC_TotalBitRate,"TotalBitRate"},
3673 {PTP_OPC_BitRateType,"BitRateType"},
3674 {PTP_OPC_SampleRate,"SampleRate"},
3675 {PTP_OPC_NumberOfChannels,"NumberOfChannels"},
3676 {PTP_OPC_AudioBitDepth,"AudioBitDepth"},
3677 {PTP_OPC_ScanDepth,"ScanDepth"},
3678 {PTP_OPC_AudioWAVECodec,"AudioWAVECodec"},
3679 {PTP_OPC_AudioBitRate,"AudioBitRate"},
3680 {PTP_OPC_VideoFourCCCodec,"VideoFourCCCodec"},
3681 {PTP_OPC_VideoBitRate,"VideoBitRate"},
3682 {PTP_OPC_FramesPerThousandSeconds,"FramesPerThousandSeconds"},
3683 {PTP_OPC_KeyFrameDistance,"KeyFrameDistance"},
3684 {PTP_OPC_BufferSize,"BufferSize"},
3685 {PTP_OPC_EncodingQuality,"EncodingQuality"},
Linus Walleij15af8532007-01-07 12:45:20 +00003686 {PTP_OPC_EncodingProfile,"EncodingProfile"},
rreardon32b33052006-12-13 10:57:48 +00003687 {PTP_OPC_BuyFlag,"BuyFlag"},
Linus Walleijb02a0662006-04-25 08:05:09 +00003688};
3689
3690int
3691ptp_render_mtp_propname(uint16_t propid, int spaceleft, char *txt) {
3692 int i;
3693 for (i=0;i<sizeof(ptp_opc_trans)/sizeof(ptp_opc_trans[0]);i++)
3694 if (propid == ptp_opc_trans[i].id)
3695 return snprintf(txt, spaceleft,ptp_opc_trans[i].name);
3696 return snprintf (txt, spaceleft,"unknown(%04x)", propid);
3697}