Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1 | /* ptp.c |
| 2 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3 | * Copyright (C) 2001-2004 Mariusz Woloszyn <emsi@ipartners.pl> |
| 4 | * Copyright (C) 2003-2006 Marcus Meissner <marcus@jet.franken.de> |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 5 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 10 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 15 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <config.h> |
| 23 | #include "ptp.h" |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <stdarg.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #ifdef ENABLE_NLS |
| 31 | # include <libintl.h> |
| 32 | # undef _ |
| 33 | # define _(String) dgettext (PACKAGE, String) |
| 34 | # ifdef gettext_noop |
| 35 | # define N_(String) gettext_noop (String) |
| 36 | # else |
| 37 | # define N_(String) (String) |
| 38 | # endif |
| 39 | #else |
| 40 | # define textdomain(String) (String) |
| 41 | # define gettext(String) (String) |
| 42 | # define dgettext(Domain,Message) (Message) |
| 43 | # define dcgettext(Domain,Message,Type) (Message) |
| 44 | # define bindtextdomain(Domain,Directory) (Domain) |
| 45 | # define _(String) (String) |
| 46 | # define N_(String) (String) |
| 47 | #endif |
| 48 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 49 | #define CHECK_PTP_RC(result) {uint16_t r=(result); if (r!=PTP_RC_OK) return r;} |
| 50 | |
| 51 | #define PTP_CNT_INIT(cnt) {memset(&cnt,0,sizeof(cnt));} |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 52 | |
| 53 | static void |
| 54 | ptp_debug (PTPParams *params, const char *format, ...) |
| 55 | { |
| 56 | va_list args; |
| 57 | |
| 58 | va_start (args, format); |
| 59 | if (params->debug_func!=NULL) |
| 60 | params->debug_func (params->data, format, args); |
| 61 | else |
| 62 | { |
| 63 | vfprintf (stderr, format, args); |
| 64 | fprintf (stderr,"\n"); |
| 65 | fflush (stderr); |
| 66 | } |
| 67 | va_end (args); |
| 68 | } |
| 69 | |
| 70 | static void |
| 71 | ptp_error (PTPParams *params, const char *format, ...) |
| 72 | { |
| 73 | va_list args; |
| 74 | |
| 75 | va_start (args, format); |
| 76 | if (params->error_func!=NULL) |
| 77 | params->error_func (params->data, format, args); |
| 78 | else |
| 79 | { |
| 80 | vfprintf (stderr, format, args); |
| 81 | fprintf (stderr,"\n"); |
| 82 | fflush (stderr); |
| 83 | } |
| 84 | va_end (args); |
| 85 | } |
| 86 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 87 | /* Pack / unpack functions */ |
| 88 | |
| 89 | #include "ptp-pack.c" |
| 90 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 91 | /* send / receive functions */ |
| 92 | |
| 93 | uint16_t |
| 94 | ptp_usb_sendreq (PTPParams* params, PTPContainer* req) |
| 95 | { |
| 96 | uint16_t ret; |
| 97 | PTPUSBBulkContainer usbreq; |
| 98 | |
| 99 | /* build appropriate USB container */ |
| 100 | usbreq.length=htod32(PTP_USB_BULK_REQ_LEN- |
| 101 | (sizeof(uint32_t)*(5-req->Nparam))); |
| 102 | usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND); |
| 103 | usbreq.code=htod16(req->Code); |
| 104 | usbreq.trans_id=htod32(req->Transaction_ID); |
| 105 | usbreq.payload.params.param1=htod32(req->Param1); |
| 106 | usbreq.payload.params.param2=htod32(req->Param2); |
| 107 | usbreq.payload.params.param3=htod32(req->Param3); |
| 108 | usbreq.payload.params.param4=htod32(req->Param4); |
| 109 | usbreq.payload.params.param5=htod32(req->Param5); |
| 110 | /* send it to responder */ |
| 111 | ret=params->write_func((unsigned char *)&usbreq, |
| 112 | PTP_USB_BULK_REQ_LEN-(sizeof(uint32_t)*(5-req->Nparam)), |
| 113 | params->data); |
| 114 | if (ret!=PTP_RC_OK) { |
| 115 | ret = PTP_ERROR_IO; |
| 116 | /* ptp_error (params, |
| 117 | "PTP: request code 0x%04x sending req error 0x%04x", |
| 118 | req->Code,ret); */ |
| 119 | } |
| 120 | return ret; |
| 121 | } |
| 122 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 123 | uint16_t |
| 124 | ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, |
| 125 | unsigned char *data, unsigned int size) |
| 126 | { |
| 127 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 128 | int wlen, datawlen; |
| 129 | PTPUSBBulkContainer usbdata; |
| 130 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 131 | /* build appropriate USB container */ |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 132 | usbdata.length = htod32(PTP_USB_BULK_HDR_LEN+size); |
| 133 | usbdata.type = htod16(PTP_USB_CONTAINER_DATA); |
| 134 | usbdata.code = htod16(ptp->Code); |
| 135 | usbdata.trans_id= htod32(ptp->Transaction_ID); |
| 136 | |
| 137 | if (params->split_header_data) { |
| 138 | datawlen = 0; |
| 139 | wlen = PTP_USB_BULK_HDR_LEN; |
| 140 | } else { |
| 141 | /* For all camera devices. */ |
| 142 | datawlen = (size<PTP_USB_BULK_PAYLOAD_LEN)?size:PTP_USB_BULK_PAYLOAD_LEN; |
| 143 | wlen = PTP_USB_BULK_HDR_LEN + datawlen; |
| 144 | memcpy(usbdata.payload.data, data, datawlen); |
| 145 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 146 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 147 | /* send first part of data */ |
| 148 | ret = params->write_func((unsigned char *)&usbdata, wlen, params->data); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 149 | if (ret!=PTP_RC_OK) { |
| 150 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 151 | /* ptp_error (params, |
| 152 | "PTP: request code 0x%04x sending data error 0x%04x", |
| 153 | ptp->Code,ret);*/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 154 | return ret; |
| 155 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 156 | if (size <= datawlen) return ret; |
| 157 | /* if everything OK send the rest */ |
| 158 | ret=params->write_func (data + datawlen, size - datawlen, params->data); |
| 159 | if (ret!=PTP_RC_OK) { |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 160 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 161 | /* ptp_error (params, |
| 162 | "PTP: request code 0x%04x sending data error 0x%04x", |
| 163 | ptp->Code,ret); */ |
| 164 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 168 | uint16_t |
| 169 | ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 170 | unsigned char **data, unsigned int *readlen) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 171 | { |
| 172 | uint16_t ret; |
| 173 | PTPUSBBulkContainer usbdata; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 174 | |
| 175 | PTP_CNT_INIT(usbdata); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 176 | if (*data!=NULL) return PTP_ERROR_BADPARAM; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 177 | do { |
| 178 | unsigned int len, rlen; |
| 179 | /* read the header and potentially the first data */ |
| 180 | ret=params->read_func((unsigned char *)&usbdata, |
| 181 | sizeof(usbdata), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 182 | if (ret!=PTP_RC_OK) { |
| 183 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 184 | break; |
| 185 | } else |
| 186 | if (dtoh16(usbdata.type)!=PTP_USB_CONTAINER_DATA) { |
| 187 | ret = PTP_ERROR_DATA_EXPECTED; |
| 188 | break; |
| 189 | } else |
| 190 | if (dtoh16(usbdata.code)!=ptp->Code) { |
| 191 | ret = dtoh16(usbdata.code); |
| 192 | break; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 193 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 194 | |
| 195 | /* For most PTP devices rlen is 512 == sizeof(usbdata) |
| 196 | * here. For MTP devices splitting header and data it might |
| 197 | * be 12. |
| 198 | */ |
| 199 | /* Evaluate full data length. */ |
| 200 | len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN; |
| 201 | |
| 202 | /* autodetect split header/data MTP devices */ |
| 203 | if (dtoh32(usbdata.length) > 12 && (rlen==12)) |
| 204 | params->split_header_data = 1; |
| 205 | |
| 206 | /* Allocate memory for data. */ |
| 207 | *data=calloc(len,1); |
| 208 | if (readlen) |
| 209 | *readlen = len; |
| 210 | |
| 211 | /* Copy first part of data to 'data' */ |
| 212 | memcpy(*data,usbdata.payload.data,rlen - PTP_USB_BULK_HDR_LEN); |
| 213 | |
| 214 | /* Is that all of data? */ |
| 215 | if (len+PTP_USB_BULK_HDR_LEN<=rlen) break; |
| 216 | |
| 217 | /* If not read the rest of it. */ |
| 218 | ret=params->read_func(((unsigned char *)(*data))+ |
| 219 | rlen - PTP_USB_BULK_HDR_LEN, |
| 220 | len-(rlen - PTP_USB_BULK_HDR_LEN), |
| 221 | params->data, &rlen); |
| 222 | if (ret!=PTP_RC_OK) { |
| 223 | ret = PTP_ERROR_IO; |
| 224 | break; |
| 225 | } |
| 226 | } while (0); |
| 227 | /* |
| 228 | if (ret!=PTP_RC_OK) { |
| 229 | ptp_error (params, |
| 230 | "PTP: request code 0x%04x getting data error 0x%04x", |
| 231 | ptp->Code, ret); |
| 232 | }*/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | uint16_t |
| 237 | ptp_usb_getresp (PTPParams* params, PTPContainer* resp) |
| 238 | { |
| 239 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 240 | unsigned int rlen; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 241 | PTPUSBBulkContainer usbresp; |
| 242 | |
| 243 | PTP_CNT_INIT(usbresp); |
| 244 | /* read response, it should never be longer than sizeof(usbresp) */ |
| 245 | ret=params->read_func((unsigned char *)&usbresp, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 246 | sizeof(usbresp), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 247 | |
| 248 | if (ret!=PTP_RC_OK) { |
| 249 | ret = PTP_ERROR_IO; |
| 250 | } else |
| 251 | if (dtoh16(usbresp.type)!=PTP_USB_CONTAINER_RESPONSE) { |
| 252 | ret = PTP_ERROR_RESP_EXPECTED; |
| 253 | } else |
| 254 | if (dtoh16(usbresp.code)!=resp->Code) { |
| 255 | ret = dtoh16(usbresp.code); |
| 256 | } |
| 257 | if (ret!=PTP_RC_OK) { |
| 258 | /* ptp_error (params, |
| 259 | "PTP: request code 0x%04x getting resp error 0x%04x", |
| 260 | resp->Code, ret);*/ |
| 261 | return ret; |
| 262 | } |
| 263 | /* build an appropriate PTPContainer */ |
| 264 | resp->Code=dtoh16(usbresp.code); |
| 265 | resp->SessionID=params->session_id; |
| 266 | resp->Transaction_ID=dtoh32(usbresp.trans_id); |
| 267 | resp->Param1=dtoh32(usbresp.payload.params.param1); |
| 268 | resp->Param2=dtoh32(usbresp.payload.params.param2); |
| 269 | resp->Param3=dtoh32(usbresp.payload.params.param3); |
| 270 | resp->Param4=dtoh32(usbresp.payload.params.param4); |
| 271 | resp->Param5=dtoh32(usbresp.payload.params.param5); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 272 | return ret; |
| 273 | } |
| 274 | |
| 275 | /* major PTP functions */ |
| 276 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 277 | /* Transaction data phase description */ |
| 278 | #define PTP_DP_NODATA 0x0000 /* no data phase */ |
| 279 | #define PTP_DP_SENDDATA 0x0001 /* sending data */ |
| 280 | #define PTP_DP_GETDATA 0x0002 /* receiving data */ |
| 281 | #define PTP_DP_DATA_MASK 0x00ff /* data phase mask */ |
| 282 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 283 | /** |
| 284 | * ptp_transaction: |
| 285 | * params: PTPParams* |
| 286 | * PTPContainer* ptp - general ptp container |
| 287 | * uint16_t flags - lower 8 bits - data phase description |
| 288 | * unsigned int sendlen - senddata phase data length |
| 289 | * char** data - send or receive data buffer pointer |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 290 | * int* recvlen - receive data length |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 291 | * |
| 292 | * Performs PTP transaction. ptp is a PTPContainer with appropriate fields |
| 293 | * filled in (i.e. operation code and parameters). It's up to caller to do |
| 294 | * so. |
| 295 | * The flags decide thether the transaction has a data phase and what is its |
| 296 | * direction (send or receive). |
| 297 | * If transaction is sending data the sendlen should contain its length in |
| 298 | * bytes, otherwise it's ignored. |
| 299 | * The data should contain an address of a pointer to data going to be sent |
| 300 | * or is filled with such a pointer address if data are received depending |
| 301 | * od dataphase direction (send or received) or is beeing ignored (no |
| 302 | * dataphase). |
| 303 | * The memory for a pointer should be preserved by the caller, if data are |
| 304 | * beeing retreived the appropriate amount of memory is beeing allocated |
| 305 | * (the caller should handle that!). |
| 306 | * |
| 307 | * Return values: Some PTP_RC_* code. |
| 308 | * Upon success PTPContainer* ptp contains PTP Response Phase container with |
| 309 | * all fields filled in. |
| 310 | **/ |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 311 | static uint16_t |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 312 | ptp_transaction (PTPParams* params, PTPContainer* ptp, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 313 | uint16_t flags, unsigned int sendlen, unsigned char** data, |
| 314 | unsigned int *recvlen) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 315 | { |
| 316 | if ((params==NULL) || (ptp==NULL)) |
| 317 | return PTP_ERROR_BADPARAM; |
| 318 | |
| 319 | ptp->Transaction_ID=params->transaction_id++; |
| 320 | ptp->SessionID=params->session_id; |
| 321 | /* send request */ |
| 322 | CHECK_PTP_RC(params->sendreq_func (params, ptp)); |
| 323 | /* is there a dataphase? */ |
| 324 | switch (flags&PTP_DP_DATA_MASK) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 325 | case PTP_DP_SENDDATA: |
| 326 | CHECK_PTP_RC(params->senddata_func(params, ptp, |
| 327 | *data, sendlen)); |
| 328 | break; |
| 329 | case PTP_DP_GETDATA: |
| 330 | CHECK_PTP_RC(params->getdata_func(params, ptp, |
| 331 | (unsigned char**)data, recvlen)); |
| 332 | break; |
| 333 | case PTP_DP_NODATA: |
| 334 | break; |
| 335 | default: |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 336 | return PTP_ERROR_BADPARAM; |
| 337 | } |
| 338 | /* get response */ |
| 339 | CHECK_PTP_RC(params->getresp_func(params, ptp)); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 340 | |
| 341 | return ptp->Code; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* Enets handling functions */ |
| 345 | |
| 346 | /* PTP Events wait for or check mode */ |
| 347 | #define PTP_EVENT_CHECK 0x0000 /* waits for */ |
| 348 | #define PTP_EVENT_CHECK_FAST 0x0001 /* checks */ |
| 349 | |
| 350 | static inline uint16_t |
| 351 | ptp_usb_event (PTPParams* params, PTPContainer* event, int wait) |
| 352 | { |
| 353 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 354 | unsigned int rlen; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 355 | PTPUSBEventContainer usbevent; |
| 356 | PTP_CNT_INIT(usbevent); |
| 357 | |
| 358 | if ((params==NULL) || (event==NULL)) |
| 359 | return PTP_ERROR_BADPARAM; |
| 360 | |
| 361 | switch(wait) { |
| 362 | case PTP_EVENT_CHECK: |
| 363 | ret=params->check_int_func((unsigned char*)&usbevent, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 364 | sizeof(usbevent), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 365 | break; |
| 366 | case PTP_EVENT_CHECK_FAST: |
| 367 | ret=params->check_int_fast_func((unsigned char*) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 368 | &usbevent, sizeof(usbevent), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 369 | break; |
| 370 | default: |
| 371 | ret=PTP_ERROR_BADPARAM; |
| 372 | } |
| 373 | if (ret!=PTP_RC_OK) { |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 374 | ptp_error (params, |
| 375 | "PTP: reading event an error 0x%04x occured", ret); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 376 | ret = PTP_ERROR_IO; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 377 | /* reading event error is nonfatal (for example timeout) */ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 378 | } |
| 379 | /* if we read anything over interrupt endpoint it must be an event */ |
| 380 | /* build an appropriate PTPContainer */ |
| 381 | event->Code=dtoh16(usbevent.code); |
| 382 | event->SessionID=params->session_id; |
| 383 | event->Transaction_ID=dtoh32(usbevent.trans_id); |
| 384 | event->Param1=dtoh32(usbevent.param1); |
| 385 | event->Param2=dtoh32(usbevent.param2); |
| 386 | event->Param3=dtoh32(usbevent.param3); |
| 387 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 388 | return ret; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | uint16_t |
| 392 | ptp_usb_event_check (PTPParams* params, PTPContainer* event) { |
| 393 | |
| 394 | return ptp_usb_event (params, event, PTP_EVENT_CHECK_FAST); |
| 395 | } |
| 396 | |
| 397 | uint16_t |
| 398 | ptp_usb_event_wait (PTPParams* params, PTPContainer* event) { |
| 399 | |
| 400 | return ptp_usb_event (params, event, PTP_EVENT_CHECK); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * PTP operation functions |
| 405 | * |
| 406 | * all ptp_ functions should take integer parameters |
| 407 | * in host byte order! |
| 408 | **/ |
| 409 | |
| 410 | |
| 411 | /** |
| 412 | * ptp_getdeviceinfo: |
| 413 | * params: PTPParams* |
| 414 | * |
| 415 | * Gets device info dataset and fills deviceinfo structure. |
| 416 | * |
| 417 | * Return values: Some PTP_RC_* code. |
| 418 | **/ |
| 419 | uint16_t |
| 420 | ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo) |
| 421 | { |
| 422 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 423 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 424 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 425 | unsigned char* di=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 426 | |
| 427 | PTP_CNT_INIT(ptp); |
| 428 | ptp.Code=PTP_OC_GetDeviceInfo; |
| 429 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 430 | len=0; |
| 431 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &di, &len); |
| 432 | if (ret == PTP_RC_OK) ptp_unpack_DI(params, di, deviceinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 433 | free(di); |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | |
| 438 | /** |
| 439 | * ptp_opensession: |
| 440 | * params: PTPParams* |
| 441 | * session - session number |
| 442 | * |
| 443 | * Establishes a new session. |
| 444 | * |
| 445 | * Return values: Some PTP_RC_* code. |
| 446 | **/ |
| 447 | uint16_t |
| 448 | ptp_opensession (PTPParams* params, uint32_t session) |
| 449 | { |
| 450 | uint16_t ret; |
| 451 | PTPContainer ptp; |
| 452 | |
| 453 | ptp_debug(params,"PTP: Opening session"); |
| 454 | |
| 455 | /* SessonID field of the operation dataset should always |
| 456 | be set to 0 for OpenSession request! */ |
| 457 | params->session_id=0x00000000; |
| 458 | /* TransactionID should be set to 0 also! */ |
| 459 | params->transaction_id=0x0000000; |
| 460 | |
| 461 | PTP_CNT_INIT(ptp); |
| 462 | ptp.Code=PTP_OC_OpenSession; |
| 463 | ptp.Param1=session; |
| 464 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 465 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 466 | /* now set the global session id to current session number */ |
| 467 | params->session_id=session; |
| 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * ptp_closesession: |
| 473 | * params: PTPParams* |
| 474 | * |
| 475 | * Closes session. |
| 476 | * |
| 477 | * Return values: Some PTP_RC_* code. |
| 478 | **/ |
| 479 | uint16_t |
| 480 | ptp_closesession (PTPParams* params) |
| 481 | { |
| 482 | PTPContainer ptp; |
| 483 | |
| 484 | ptp_debug(params,"PTP: Closing session"); |
| 485 | |
| 486 | PTP_CNT_INIT(ptp); |
| 487 | ptp.Code=PTP_OC_CloseSession; |
| 488 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 489 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
| 493 | * ptp_getststorageids: |
| 494 | * params: PTPParams* |
| 495 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 496 | * Gets array of StorageIDs and fills the storageids structure. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 497 | * |
| 498 | * Return values: Some PTP_RC_* code. |
| 499 | **/ |
| 500 | uint16_t |
| 501 | ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids) |
| 502 | { |
| 503 | uint16_t ret; |
| 504 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 505 | unsigned int len; |
| 506 | unsigned char* sids=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 507 | |
| 508 | PTP_CNT_INIT(ptp); |
| 509 | ptp.Code=PTP_OC_GetStorageIDs; |
| 510 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 511 | len=0; |
| 512 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids, &len); |
| 513 | if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 514 | free(sids); |
| 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * ptp_getststorageinfo: |
| 520 | * params: PTPParams* |
| 521 | * storageid - StorageID |
| 522 | * |
| 523 | * Gets StorageInfo dataset of desired storage and fills storageinfo |
| 524 | * structure. |
| 525 | * |
| 526 | * Return values: Some PTP_RC_* code. |
| 527 | **/ |
| 528 | uint16_t |
| 529 | ptp_getstorageinfo (PTPParams* params, uint32_t storageid, |
| 530 | PTPStorageInfo* storageinfo) |
| 531 | { |
| 532 | uint16_t ret; |
| 533 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 534 | unsigned char* si=NULL; |
| 535 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 536 | |
| 537 | PTP_CNT_INIT(ptp); |
| 538 | ptp.Code=PTP_OC_GetStorageInfo; |
| 539 | ptp.Param1=storageid; |
| 540 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 541 | len=0; |
| 542 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &si, &len); |
| 543 | if (ret == PTP_RC_OK) ptp_unpack_SI(params, si, storageinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 544 | free(si); |
| 545 | return ret; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * ptp_getobjecthandles: |
| 550 | * params: PTPParams* |
| 551 | * storage - StorageID |
| 552 | * objectformatcode - ObjectFormatCode (optional) |
| 553 | * associationOH - ObjectHandle of Association for |
| 554 | * wich a list of children is desired |
| 555 | * (optional) |
| 556 | * objecthandles - pointer to structute |
| 557 | * |
| 558 | * Fills objecthandles with structure returned by device. |
| 559 | * |
| 560 | * Return values: Some PTP_RC_* code. |
| 561 | **/ |
| 562 | uint16_t |
| 563 | ptp_getobjecthandles (PTPParams* params, uint32_t storage, |
| 564 | uint32_t objectformatcode, uint32_t associationOH, |
| 565 | PTPObjectHandles* objecthandles) |
| 566 | { |
| 567 | uint16_t ret; |
| 568 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 569 | unsigned char* oh=NULL; |
| 570 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 571 | |
| 572 | PTP_CNT_INIT(ptp); |
| 573 | ptp.Code=PTP_OC_GetObjectHandles; |
| 574 | ptp.Param1=storage; |
| 575 | ptp.Param2=objectformatcode; |
| 576 | ptp.Param3=associationOH; |
| 577 | ptp.Nparam=3; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 578 | len=0; |
| 579 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oh, &len); |
| 580 | if (ret == PTP_RC_OK) ptp_unpack_OH(params, oh, objecthandles, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 581 | free(oh); |
| 582 | return ret; |
| 583 | } |
| 584 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 585 | /** |
| 586 | * ptp_getnumobjects: |
| 587 | * params: PTPParams* |
| 588 | * storage - StorageID |
| 589 | * objectformatcode - ObjectFormatCode (optional) |
| 590 | * associationOH - ObjectHandle of Association for |
| 591 | * wich a list of children is desired |
| 592 | * (optional) |
| 593 | * numobs - pointer to uint32_t that takes number of objects |
| 594 | * |
| 595 | * Fills numobs with number of objects on device. |
| 596 | * |
| 597 | * Return values: Some PTP_RC_* code. |
| 598 | **/ |
| 599 | uint16_t |
| 600 | ptp_getnumobjects (PTPParams* params, uint32_t storage, |
| 601 | uint32_t objectformatcode, uint32_t associationOH, |
| 602 | uint32_t* numobs) |
| 603 | { |
| 604 | uint16_t ret; |
| 605 | PTPContainer ptp; |
| 606 | int len; |
| 607 | |
| 608 | PTP_CNT_INIT(ptp); |
| 609 | ptp.Code=PTP_OC_GetObjectHandles; |
| 610 | ptp.Param1=storage; |
| 611 | ptp.Param2=objectformatcode; |
| 612 | ptp.Param3=associationOH; |
| 613 | ptp.Nparam=3; |
| 614 | len=0; |
| 615 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 616 | if (ret == PTP_RC_OK) { |
| 617 | if (ptp.Nparam >= 1) |
| 618 | *numobs = ptp.Param1; |
| 619 | else |
| 620 | ret = PTP_RC_GeneralError; |
| 621 | } |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * ptp_getobjectinfo: |
| 627 | * params: PTPParams* |
| 628 | * handle - Object handle |
| 629 | * objectinfo - pointer to objectinfo that is returned |
| 630 | * |
| 631 | * Get objectinfo structure for handle from device. |
| 632 | * |
| 633 | * Return values: Some PTP_RC_* code. |
| 634 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 635 | uint16_t |
| 636 | ptp_getobjectinfo (PTPParams* params, uint32_t handle, |
| 637 | PTPObjectInfo* objectinfo) |
| 638 | { |
| 639 | uint16_t ret; |
| 640 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 641 | unsigned char* oi=NULL; |
| 642 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 643 | |
| 644 | PTP_CNT_INIT(ptp); |
| 645 | ptp.Code=PTP_OC_GetObjectInfo; |
| 646 | ptp.Param1=handle; |
| 647 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 648 | len=0; |
| 649 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oi, &len); |
| 650 | if (ret == PTP_RC_OK) ptp_unpack_OI(params, oi, objectinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 651 | free(oi); |
| 652 | return ret; |
| 653 | } |
| 654 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 655 | /** |
| 656 | * ptp_getobject: |
| 657 | * params: PTPParams* |
| 658 | * handle - Object handle |
| 659 | * object - pointer to data area |
| 660 | * |
| 661 | * Get object 'handle' from device and store the data in newly |
| 662 | * allocated 'object'. |
| 663 | * |
| 664 | * Return values: Some PTP_RC_* code. |
| 665 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 666 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 667 | ptp_getobject (PTPParams* params, uint32_t handle, unsigned char** object) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 668 | { |
| 669 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 670 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 671 | |
| 672 | PTP_CNT_INIT(ptp); |
| 673 | ptp.Code=PTP_OC_GetObject; |
| 674 | ptp.Param1=handle; |
| 675 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 676 | len=0; |
| 677 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 680 | /** |
| 681 | * ptp_getpartialobject: |
| 682 | * params: PTPParams* |
| 683 | * handle - Object handle |
| 684 | * offset - Offset into object |
| 685 | * maxbytes - Maximum of bytes to read |
| 686 | * object - pointer to data area |
| 687 | * |
| 688 | * Get object 'handle' from device and store the data in newly |
| 689 | * allocated 'object'. Start from offset and read at most maxbytes. |
| 690 | * |
| 691 | * Return values: Some PTP_RC_* code. |
| 692 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 693 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 694 | ptp_getpartialobject (PTPParams* params, uint32_t handle, uint32_t offset, |
| 695 | uint32_t maxbytes, unsigned char** object) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 696 | { |
| 697 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 698 | unsigned int len; |
| 699 | |
| 700 | PTP_CNT_INIT(ptp); |
| 701 | ptp.Code=PTP_OC_GetPartialObject; |
| 702 | ptp.Param1=handle; |
| 703 | ptp.Param2=offset; |
| 704 | ptp.Param3=maxbytes; |
| 705 | ptp.Nparam=3; |
| 706 | len=0; |
| 707 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * ptp_getthumb: |
| 712 | * params: PTPParams* |
| 713 | * handle - Object handle |
| 714 | * object - pointer to data area |
| 715 | * |
| 716 | * Get thumb for object 'handle' from device and store the data in newly |
| 717 | * allocated 'object'. |
| 718 | * |
| 719 | * Return values: Some PTP_RC_* code. |
| 720 | **/ |
| 721 | uint16_t |
| 722 | ptp_getthumb (PTPParams* params, uint32_t handle, unsigned char** object) |
| 723 | { |
| 724 | PTPContainer ptp; |
| 725 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 726 | |
| 727 | PTP_CNT_INIT(ptp); |
| 728 | ptp.Code=PTP_OC_GetThumb; |
| 729 | ptp.Param1=handle; |
| 730 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 731 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /** |
| 735 | * ptp_deleteobject: |
| 736 | * params: PTPParams* |
| 737 | * handle - object handle |
| 738 | * ofc - object format code (optional) |
| 739 | * |
| 740 | * Deletes desired objects. |
| 741 | * |
| 742 | * Return values: Some PTP_RC_* code. |
| 743 | **/ |
| 744 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 745 | ptp_deleteobject (PTPParams* params, uint32_t handle, uint32_t ofc) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 746 | { |
| 747 | PTPContainer ptp; |
| 748 | |
| 749 | PTP_CNT_INIT(ptp); |
| 750 | ptp.Code=PTP_OC_DeleteObject; |
| 751 | ptp.Param1=handle; |
| 752 | ptp.Param2=ofc; |
| 753 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 754 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
| 758 | * ptp_sendobjectinfo: |
| 759 | * params: PTPParams* |
| 760 | * uint32_t* store - destination StorageID on Responder |
| 761 | * uint32_t* parenthandle - Parent ObjectHandle on responder |
| 762 | * uint32_t* handle - see Return values |
| 763 | * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent |
| 764 | * |
| 765 | * Sends ObjectInfo of file that is to be sent via SendFileObject. |
| 766 | * |
| 767 | * Return values: Some PTP_RC_* code. |
| 768 | * Upon success : uint32_t* store - Responder StorageID in which |
| 769 | * object will be stored |
| 770 | * uint32_t* parenthandle- Responder Parent ObjectHandle |
| 771 | * in which the object will be stored |
| 772 | * uint32_t* handle - Responder's reserved ObjectHandle |
| 773 | * for the incoming object |
| 774 | **/ |
| 775 | uint16_t |
| 776 | ptp_sendobjectinfo (PTPParams* params, uint32_t* store, |
| 777 | uint32_t* parenthandle, uint32_t* handle, |
| 778 | PTPObjectInfo* objectinfo) |
| 779 | { |
| 780 | uint16_t ret; |
| 781 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 782 | unsigned char* oidata=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 783 | uint32_t size; |
| 784 | |
| 785 | PTP_CNT_INIT(ptp); |
| 786 | ptp.Code=PTP_OC_SendObjectInfo; |
| 787 | ptp.Param1=*store; |
| 788 | ptp.Param2=*parenthandle; |
| 789 | ptp.Nparam=2; |
| 790 | |
| 791 | size=ptp_pack_OI(params, objectinfo, &oidata); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 792 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 793 | free(oidata); |
| 794 | *store=ptp.Param1; |
| 795 | *parenthandle=ptp.Param2; |
| 796 | *handle=ptp.Param3; |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * ptp_sendobject: |
| 802 | * params: PTPParams* |
| 803 | * char* object - contains the object that is to be sent |
| 804 | * uint32_t size - object size |
| 805 | * |
| 806 | * Sends object to Responder. |
| 807 | * |
| 808 | * Return values: Some PTP_RC_* code. |
| 809 | * |
| 810 | */ |
| 811 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 812 | ptp_sendobject (PTPParams* params, unsigned char* object, uint32_t size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 813 | { |
| 814 | PTPContainer ptp; |
| 815 | |
| 816 | PTP_CNT_INIT(ptp); |
| 817 | ptp.Code=PTP_OC_SendObject; |
| 818 | ptp.Nparam=0; |
| 819 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 820 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
| 824 | /** |
| 825 | * ptp_initiatecapture: |
| 826 | * params: PTPParams* |
| 827 | * storageid - destination StorageID on Responder |
| 828 | * ofc - object format code |
| 829 | * |
| 830 | * Causes device to initiate the capture of one or more new data objects |
| 831 | * according to its current device properties, storing the data into store |
| 832 | * indicated by storageid. If storageid is 0x00000000, the object(s) will |
| 833 | * be stored in a store that is determined by the capturing device. |
| 834 | * The capturing of new data objects is an asynchronous operation. |
| 835 | * |
| 836 | * Return values: Some PTP_RC_* code. |
| 837 | **/ |
| 838 | |
| 839 | uint16_t |
| 840 | ptp_initiatecapture (PTPParams* params, uint32_t storageid, |
| 841 | uint32_t ofc) |
| 842 | { |
| 843 | PTPContainer ptp; |
| 844 | |
| 845 | PTP_CNT_INIT(ptp); |
| 846 | ptp.Code=PTP_OC_InitiateCapture; |
| 847 | ptp.Param1=storageid; |
| 848 | ptp.Param2=ofc; |
| 849 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 850 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | uint16_t |
| 854 | ptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, |
| 855 | PTPDevicePropDesc* devicepropertydesc) |
| 856 | { |
| 857 | PTPContainer ptp; |
| 858 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 859 | unsigned int len; |
| 860 | unsigned char* dpd=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 861 | |
| 862 | PTP_CNT_INIT(ptp); |
| 863 | ptp.Code=PTP_OC_GetDevicePropDesc; |
| 864 | ptp.Param1=propcode; |
| 865 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 866 | len=0; |
| 867 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd, &len); |
| 868 | if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 869 | free(dpd); |
| 870 | return ret; |
| 871 | } |
| 872 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 873 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 874 | uint16_t |
| 875 | ptp_getdevicepropvalue (PTPParams* params, uint16_t propcode, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 876 | PTPPropertyValue* value, uint16_t datatype) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 877 | { |
| 878 | PTPContainer ptp; |
| 879 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 880 | unsigned int len; |
| 881 | int offset; |
| 882 | unsigned char* dpv=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 883 | |
| 884 | |
| 885 | PTP_CNT_INIT(ptp); |
| 886 | ptp.Code=PTP_OC_GetDevicePropValue; |
| 887 | ptp.Param1=propcode; |
| 888 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 889 | len=offset=0; |
| 890 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &len); |
| 891 | if (ret == PTP_RC_OK) ptp_unpack_DPV(params, dpv, &offset, len, value, datatype); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 892 | free(dpv); |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | uint16_t |
| 897 | ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 898 | PTPPropertyValue *value, uint16_t datatype) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 899 | { |
| 900 | PTPContainer ptp; |
| 901 | uint16_t ret; |
| 902 | uint32_t size; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 903 | unsigned char* dpv=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 904 | |
| 905 | PTP_CNT_INIT(ptp); |
| 906 | ptp.Code=PTP_OC_SetDevicePropValue; |
| 907 | ptp.Param1=propcode; |
| 908 | ptp.Nparam=1; |
| 909 | size=ptp_pack_DPV(params, value, &dpv, datatype); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 910 | ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 911 | free(dpv); |
| 912 | return ret; |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * ptp_ek_sendfileobjectinfo: |
| 917 | * params: PTPParams* |
| 918 | * uint32_t* store - destination StorageID on Responder |
| 919 | * uint32_t* parenthandle - Parent ObjectHandle on responder |
| 920 | * uint32_t* handle - see Return values |
| 921 | * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent |
| 922 | * |
| 923 | * Sends ObjectInfo of file that is to be sent via SendFileObject. |
| 924 | * |
| 925 | * Return values: Some PTP_RC_* code. |
| 926 | * Upon success : uint32_t* store - Responder StorageID in which |
| 927 | * object will be stored |
| 928 | * uint32_t* parenthandle- Responder Parent ObjectHandle |
| 929 | * in which the object will be stored |
| 930 | * uint32_t* handle - Responder's reserved ObjectHandle |
| 931 | * for the incoming object |
| 932 | **/ |
| 933 | uint16_t |
| 934 | ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store, |
| 935 | uint32_t* parenthandle, uint32_t* handle, |
| 936 | PTPObjectInfo* objectinfo) |
| 937 | { |
| 938 | uint16_t ret; |
| 939 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 940 | unsigned char* oidata=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 941 | uint32_t size; |
| 942 | |
| 943 | PTP_CNT_INIT(ptp); |
| 944 | ptp.Code=PTP_OC_EK_SendFileObjectInfo; |
| 945 | ptp.Param1=*store; |
| 946 | ptp.Param2=*parenthandle; |
| 947 | ptp.Nparam=2; |
| 948 | |
| 949 | size=ptp_pack_OI(params, objectinfo, &oidata); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 950 | ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 951 | free(oidata); |
| 952 | *store=ptp.Param1; |
| 953 | *parenthandle=ptp.Param2; |
| 954 | *handle=ptp.Param3; |
| 955 | return ret; |
| 956 | } |
| 957 | |
| 958 | /** |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 959 | * ptp_ek_getserial: |
| 960 | * params: PTPParams* |
| 961 | * char** serial - contains the serial number of the camera |
| 962 | * uint32_t* size - contains the string length |
| 963 | * |
| 964 | * Gets the serial number from the device. (ptp serial) |
| 965 | * |
| 966 | * Return values: Some PTP_RC_* code. |
| 967 | * |
| 968 | */ |
| 969 | uint16_t |
| 970 | ptp_ek_getserial (PTPParams* params, unsigned char **data, unsigned int *size) |
| 971 | { |
| 972 | PTPContainer ptp; |
| 973 | |
| 974 | PTP_CNT_INIT(ptp); |
| 975 | ptp.Code = PTP_OC_EK_GetSerial; |
| 976 | ptp.Nparam = 0; |
| 977 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * ptp_ek_setserial: |
| 982 | * params: PTPParams* |
| 983 | * char* serial - contains the new serial number |
| 984 | * uint32_t size - string length |
| 985 | * |
| 986 | * Sets the serial number of the device. (ptp serial) |
| 987 | * |
| 988 | * Return values: Some PTP_RC_* code. |
| 989 | * |
| 990 | */ |
| 991 | uint16_t |
| 992 | ptp_ek_setserial (PTPParams* params, unsigned char *data, unsigned int size) |
| 993 | { |
| 994 | PTPContainer ptp; |
| 995 | |
| 996 | PTP_CNT_INIT(ptp); |
| 997 | ptp.Code = PTP_OC_EK_SetSerial; |
| 998 | ptp.Nparam = 0; |
| 999 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1000 | } |
| 1001 | |
| 1002 | /* unclear what it does yet */ |
| 1003 | uint16_t |
| 1004 | ptp_ek_9007 (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1005 | { |
| 1006 | PTPContainer ptp; |
| 1007 | |
| 1008 | PTP_CNT_INIT(ptp); |
| 1009 | ptp.Code = 0x9007; |
| 1010 | ptp.Nparam = 0; |
| 1011 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1012 | } |
| 1013 | |
| 1014 | /* unclear what it does yet */ |
| 1015 | uint16_t |
| 1016 | ptp_ek_9009 (PTPParams* params, uint32_t *p1, uint32_t *p2) |
| 1017 | { |
| 1018 | PTPContainer ptp; |
| 1019 | uint16_t ret; |
| 1020 | |
| 1021 | PTP_CNT_INIT(ptp); |
| 1022 | ptp.Code = 0x9009; |
| 1023 | ptp.Nparam = 0; |
| 1024 | ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1025 | *p1 = ptp.Param1; |
| 1026 | *p2 = ptp.Param2; |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
| 1030 | /* unclear yet, but I guess it returns the info from 9008 */ |
| 1031 | uint16_t |
| 1032 | ptp_ek_900c (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1033 | { |
| 1034 | PTPContainer ptp; |
| 1035 | |
| 1036 | PTP_CNT_INIT(ptp); |
| 1037 | ptp.Code = 0x900c; |
| 1038 | ptp.Nparam = 0; |
| 1039 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1040 | /* returned data is 16bit,16bit,32bit,32bit */ |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * ptp_ek_settext: |
| 1045 | * params: PTPParams* |
| 1046 | * PTPEKTextParams* - contains the texts to display. |
| 1047 | * |
| 1048 | * Displays the specified texts on the TFT of the camera. |
| 1049 | * |
| 1050 | * Return values: Some PTP_RC_* code. |
| 1051 | * |
| 1052 | */ |
| 1053 | uint16_t |
| 1054 | ptp_ek_settext (PTPParams* params, PTPEKTextParams *text) |
| 1055 | { |
| 1056 | PTPContainer ptp; |
| 1057 | uint16_t ret; |
| 1058 | unsigned int size; |
| 1059 | unsigned char *data; |
| 1060 | |
| 1061 | PTP_CNT_INIT(ptp); |
| 1062 | ptp.Code = PTP_OC_EK_SetText; |
| 1063 | ptp.Nparam = 0; |
| 1064 | if (0 == (size = ptp_pack_EK_text(params, text, &data))) |
| 1065 | return PTP_ERROR_BADPARAM; |
| 1066 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1067 | free(data); |
| 1068 | return ret; |
| 1069 | } |
| 1070 | |
| 1071 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1072 | * ptp_ek_sendfileobject: |
| 1073 | * params: PTPParams* |
| 1074 | * char* object - contains the object that is to be sent |
| 1075 | * uint32_t size - object size |
| 1076 | * |
| 1077 | * Sends object to Responder. |
| 1078 | * |
| 1079 | * Return values: Some PTP_RC_* code. |
| 1080 | * |
| 1081 | */ |
| 1082 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1083 | ptp_ek_sendfileobject (PTPParams* params, unsigned char* object, uint32_t size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1084 | { |
| 1085 | PTPContainer ptp; |
| 1086 | |
| 1087 | PTP_CNT_INIT(ptp); |
| 1088 | ptp.Code=PTP_OC_EK_SendFileObject; |
| 1089 | ptp.Nparam=0; |
| 1090 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1091 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | /************************************************************************* |
| 1095 | * |
| 1096 | * Canon PTP extensions support |
| 1097 | * |
| 1098 | * (C) Nikolai Kopanygin 2003 |
| 1099 | * |
| 1100 | *************************************************************************/ |
| 1101 | |
| 1102 | |
| 1103 | /** |
| 1104 | * ptp_canon_getobjectsize: |
| 1105 | * params: PTPParams* |
| 1106 | * uint32_t handle - ObjectHandle |
| 1107 | * uint32_t p2 - Yet unknown parameter, |
| 1108 | * value 0 works. |
| 1109 | * |
| 1110 | * Gets form the responder the size of the specified object. |
| 1111 | * |
| 1112 | * Return values: Some PTP_RC_* code. |
| 1113 | * Upon success : uint32_t* size - The object size |
| 1114 | * uint32_t rp2 - Yet unknown parameter |
| 1115 | * |
| 1116 | **/ |
| 1117 | uint16_t |
| 1118 | ptp_canon_getobjectsize (PTPParams* params, uint32_t handle, uint32_t p2, |
| 1119 | uint32_t* size, uint32_t* rp2) |
| 1120 | { |
| 1121 | uint16_t ret; |
| 1122 | PTPContainer ptp; |
| 1123 | |
| 1124 | PTP_CNT_INIT(ptp); |
| 1125 | ptp.Code=PTP_OC_CANON_GetObjectSize; |
| 1126 | ptp.Param1=handle; |
| 1127 | ptp.Param2=p2; |
| 1128 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1129 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1130 | *size=ptp.Param1; |
| 1131 | *rp2=ptp.Param2; |
| 1132 | return ret; |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * ptp_canon_startshootingmode: |
| 1137 | * params: PTPParams* |
| 1138 | * |
| 1139 | * Starts shooting session. It emits a StorageInfoChanged |
| 1140 | * event via the interrupt pipe and pushes the StorageInfoChanged |
| 1141 | * and CANON_CameraModeChange events onto the event stack |
| 1142 | * (see operation PTP_OC_CANON_CheckEvent). |
| 1143 | * |
| 1144 | * Return values: Some PTP_RC_* code. |
| 1145 | * |
| 1146 | **/ |
| 1147 | uint16_t |
| 1148 | ptp_canon_startshootingmode (PTPParams* params) |
| 1149 | { |
| 1150 | PTPContainer ptp; |
| 1151 | |
| 1152 | PTP_CNT_INIT(ptp); |
| 1153 | ptp.Code=PTP_OC_CANON_StartShootingMode; |
| 1154 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1155 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * ptp_canon_endshootingmode: |
| 1160 | * params: PTPParams* |
| 1161 | * |
| 1162 | * This operation is observed after pressing the Disconnect |
| 1163 | * button on the Remote Capture app. It emits a StorageInfoChanged |
| 1164 | * event via the interrupt pipe and pushes the StorageInfoChanged |
| 1165 | * and CANON_CameraModeChange events onto the event stack |
| 1166 | * (see operation PTP_OC_CANON_CheckEvent). |
| 1167 | * |
| 1168 | * Return values: Some PTP_RC_* code. |
| 1169 | * |
| 1170 | **/ |
| 1171 | uint16_t |
| 1172 | ptp_canon_endshootingmode (PTPParams* params) |
| 1173 | { |
| 1174 | PTPContainer ptp; |
| 1175 | |
| 1176 | PTP_CNT_INIT(ptp); |
| 1177 | ptp.Code=PTP_OC_CANON_EndShootingMode; |
| 1178 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1179 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * ptp_canon_viewfinderon: |
| 1184 | * params: PTPParams* |
| 1185 | * |
| 1186 | * Prior to start reading viewfinder images, one must call this operation. |
| 1187 | * Supposedly, this operation affects the value of the CANON_ViewfinderMode |
| 1188 | * property. |
| 1189 | * |
| 1190 | * Return values: Some PTP_RC_* code. |
| 1191 | * |
| 1192 | **/ |
| 1193 | uint16_t |
| 1194 | ptp_canon_viewfinderon (PTPParams* params) |
| 1195 | { |
| 1196 | PTPContainer ptp; |
| 1197 | |
| 1198 | PTP_CNT_INIT(ptp); |
| 1199 | ptp.Code=PTP_OC_CANON_ViewfinderOn; |
| 1200 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1201 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * ptp_canon_viewfinderoff: |
| 1206 | * params: PTPParams* |
| 1207 | * |
| 1208 | * Before changing the shooting mode, or when one doesn't need to read |
| 1209 | * viewfinder images any more, one must call this operation. |
| 1210 | * Supposedly, this operation affects the value of the CANON_ViewfinderMode |
| 1211 | * property. |
| 1212 | * |
| 1213 | * Return values: Some PTP_RC_* code. |
| 1214 | * |
| 1215 | **/ |
| 1216 | uint16_t |
| 1217 | ptp_canon_viewfinderoff (PTPParams* params) |
| 1218 | { |
| 1219 | PTPContainer ptp; |
| 1220 | |
| 1221 | PTP_CNT_INIT(ptp); |
| 1222 | ptp.Code=PTP_OC_CANON_ViewfinderOff; |
| 1223 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1224 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * ptp_canon_reflectchanges: |
| 1229 | * params: PTPParams* |
| 1230 | * uint32_t p1 - Yet unknown parameter, |
| 1231 | * value 7 works |
| 1232 | * |
| 1233 | * Make viewfinder reflect changes. |
| 1234 | * There is a button for this operation in the Remote Capture app. |
| 1235 | * What it does exactly I don't know. This operation is followed |
| 1236 | * by the CANON_GetChanges(?) operation in the log. |
| 1237 | * |
| 1238 | * Return values: Some PTP_RC_* code. |
| 1239 | * |
| 1240 | **/ |
| 1241 | uint16_t |
| 1242 | ptp_canon_reflectchanges (PTPParams* params, uint32_t p1) |
| 1243 | { |
| 1244 | PTPContainer ptp; |
| 1245 | |
| 1246 | PTP_CNT_INIT(ptp); |
| 1247 | ptp.Code=PTP_OC_CANON_ReflectChanges; |
| 1248 | ptp.Param1=p1; |
| 1249 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1250 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | /** |
| 1255 | * ptp_canon_checkevent: |
| 1256 | * params: PTPParams* |
| 1257 | * |
| 1258 | * The camera has a FIFO stack, in which it accumulates events. |
| 1259 | * Partially these events are communicated also via the USB interrupt pipe |
| 1260 | * according to the PTP USB specification, partially not. |
| 1261 | * This operation returns from the device a block of data, empty, |
| 1262 | * if the event stack is empty, or filled with an event's data otherwise. |
| 1263 | * The event is removed from the stack in the latter case. |
| 1264 | * The Remote Capture app sends this command to the camera all the time |
| 1265 | * of connection, filling with it the gaps between other operations. |
| 1266 | * |
| 1267 | * Return values: Some PTP_RC_* code. |
| 1268 | * Upon success : PTPUSBEventContainer* event - is filled with the event data |
| 1269 | * if any |
| 1270 | * int *isevent - returns 1 in case of event |
| 1271 | * or 0 otherwise |
| 1272 | **/ |
| 1273 | uint16_t |
| 1274 | ptp_canon_checkevent (PTPParams* params, PTPUSBEventContainer* event, int* isevent) |
| 1275 | { |
| 1276 | uint16_t ret; |
| 1277 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1278 | unsigned char *evdata = NULL; |
| 1279 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1280 | |
| 1281 | *isevent=0; |
| 1282 | PTP_CNT_INIT(ptp); |
| 1283 | ptp.Code=PTP_OC_CANON_CheckEvent; |
| 1284 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1285 | len=0; |
| 1286 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1287 | if (evdata!=NULL) { |
| 1288 | if (ret == PTP_RC_OK) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1289 | ptp_unpack_EC(params, evdata, event, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1290 | *isevent=1; |
| 1291 | } |
| 1292 | free(evdata); |
| 1293 | } |
| 1294 | return ret; |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | /** |
| 1299 | * ptp_canon_focuslock: |
| 1300 | * |
| 1301 | * This operation locks the focus. It is followed by the CANON_GetChanges(?) |
| 1302 | * operation in the log. |
| 1303 | * It affects the CANON_MacroMode property. |
| 1304 | * |
| 1305 | * params: PTPParams* |
| 1306 | * |
| 1307 | * Return values: Some PTP_RC_* code. |
| 1308 | * |
| 1309 | **/ |
| 1310 | uint16_t |
| 1311 | ptp_canon_focuslock (PTPParams* params) |
| 1312 | { |
| 1313 | PTPContainer ptp; |
| 1314 | |
| 1315 | PTP_CNT_INIT(ptp); |
| 1316 | ptp.Code=PTP_OC_CANON_FocusLock; |
| 1317 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1318 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * ptp_canon_focusunlock: |
| 1323 | * |
| 1324 | * This operation unlocks the focus. It is followed by the CANON_GetChanges(?) |
| 1325 | * operation in the log. |
| 1326 | * It sets the CANON_MacroMode property value to 1 (where it occurs in the log). |
| 1327 | * |
| 1328 | * params: PTPParams* |
| 1329 | * |
| 1330 | * Return values: Some PTP_RC_* code. |
| 1331 | * |
| 1332 | **/ |
| 1333 | uint16_t |
| 1334 | ptp_canon_focusunlock (PTPParams* params) |
| 1335 | { |
| 1336 | PTPContainer ptp; |
| 1337 | |
| 1338 | PTP_CNT_INIT(ptp); |
| 1339 | ptp.Code=PTP_OC_CANON_FocusUnlock; |
| 1340 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1341 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * ptp_canon_initiatecaptureinmemory: |
| 1346 | * |
| 1347 | * This operation starts the image capture according to the current camera |
| 1348 | * settings. When the capture has happened, the camera emits a CaptureComplete |
| 1349 | * event via the interrupt pipe and pushes the CANON_RequestObjectTransfer, |
| 1350 | * CANON_DeviceInfoChanged and CaptureComplete events onto the event stack |
| 1351 | * (see operation CANON_CheckEvent). From the CANON_RequestObjectTransfer |
| 1352 | * event's parameter one can learn the just captured image's ObjectHandle. |
| 1353 | * The image is stored in the camera's own RAM. |
| 1354 | * On the next capture the image will be overwritten! |
| 1355 | * |
| 1356 | * params: PTPParams* |
| 1357 | * |
| 1358 | * Return values: Some PTP_RC_* code. |
| 1359 | * |
| 1360 | **/ |
| 1361 | uint16_t |
| 1362 | ptp_canon_initiatecaptureinmemory (PTPParams* params) |
| 1363 | { |
| 1364 | PTPContainer ptp; |
| 1365 | |
| 1366 | PTP_CNT_INIT(ptp); |
| 1367 | ptp.Code=PTP_OC_CANON_InitiateCaptureInMemory; |
| 1368 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1369 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1370 | } |
| 1371 | |
| 1372 | uint16_t |
| 1373 | ptp_canon_9012 (PTPParams* params) |
| 1374 | { |
| 1375 | PTPContainer ptp; |
| 1376 | |
| 1377 | PTP_CNT_INIT(ptp); |
| 1378 | ptp.Code=0x9012; |
| 1379 | ptp.Nparam=0; |
| 1380 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * ptp_canon_getpartialobject: |
| 1385 | * |
| 1386 | * This operation is used to read from the device a data |
| 1387 | * block of an object from a specified offset. |
| 1388 | * |
| 1389 | * params: PTPParams* |
| 1390 | * uint32_t handle - the handle of the requested object |
| 1391 | * uint32_t offset - the offset in bytes from the beginning of the object |
| 1392 | * uint32_t size - the requested size of data block to read |
| 1393 | * uint32_t pos - 1 for the first block, 2 - for a block in the middle, |
| 1394 | * 3 - for the last block |
| 1395 | * |
| 1396 | * Return values: Some PTP_RC_* code. |
| 1397 | * char **block - the pointer to the block of data read |
| 1398 | * uint32_t* readnum - the number of bytes read |
| 1399 | * |
| 1400 | **/ |
| 1401 | uint16_t |
| 1402 | ptp_canon_getpartialobject (PTPParams* params, uint32_t handle, |
| 1403 | uint32_t offset, uint32_t size, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1404 | uint32_t pos, unsigned char** block, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1405 | uint32_t* readnum) |
| 1406 | { |
| 1407 | uint16_t ret; |
| 1408 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1409 | unsigned char *data=NULL; |
| 1410 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1411 | |
| 1412 | PTP_CNT_INIT(ptp); |
| 1413 | ptp.Code=PTP_OC_CANON_GetPartialObject; |
| 1414 | ptp.Param1=handle; |
| 1415 | ptp.Param2=offset; |
| 1416 | ptp.Param3=size; |
| 1417 | ptp.Param4=pos; |
| 1418 | ptp.Nparam=4; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1419 | len=0; |
| 1420 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1421 | if (ret==PTP_RC_OK) { |
| 1422 | *block=data; |
| 1423 | *readnum=ptp.Param1; |
| 1424 | } |
| 1425 | return ret; |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * ptp_canon_getviewfinderimage: |
| 1430 | * |
| 1431 | * This operation can be used to read the image which is currently |
| 1432 | * in the camera's viewfinder. The image size is 320x240, format is JPEG. |
| 1433 | * Of course, prior to calling this operation, one must turn the viewfinder |
| 1434 | * on with the CANON_ViewfinderOn command. |
| 1435 | * Invoking this operation many times, one can get live video from the camera! |
| 1436 | * |
| 1437 | * params: PTPParams* |
| 1438 | * |
| 1439 | * Return values: Some PTP_RC_* code. |
| 1440 | * char **image - the pointer to the read image |
| 1441 | * unit32_t *size - the size of the image in bytes |
| 1442 | * |
| 1443 | **/ |
| 1444 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1445 | ptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image, uint32_t* size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1446 | { |
| 1447 | uint16_t ret; |
| 1448 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1449 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1450 | |
| 1451 | PTP_CNT_INIT(ptp); |
| 1452 | ptp.Code=PTP_OC_CANON_GetViewfinderImage; |
| 1453 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1454 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, image, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1455 | if (ret==PTP_RC_OK) *size=ptp.Param1; |
| 1456 | return ret; |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * ptp_canon_getchanges: |
| 1461 | * |
| 1462 | * This is an interesting operation, about the effect of which I am not sure. |
| 1463 | * This command is called every time when a device property has been changed |
| 1464 | * with the SetDevicePropValue operation, and after some other operations. |
| 1465 | * This operation reads the array of Device Properties which have been changed |
| 1466 | * by the previous operation. |
| 1467 | * Probably, this operation is even required to make those changes work. |
| 1468 | * |
| 1469 | * params: PTPParams* |
| 1470 | * |
| 1471 | * Return values: Some PTP_RC_* code. |
| 1472 | * uint16_t** props - the pointer to the array of changed properties |
| 1473 | * uint32_t* propnum - the number of elements in the *props array |
| 1474 | * |
| 1475 | **/ |
| 1476 | uint16_t |
| 1477 | ptp_canon_getchanges (PTPParams* params, uint16_t** props, uint32_t* propnum) |
| 1478 | { |
| 1479 | uint16_t ret; |
| 1480 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1481 | unsigned char* data=NULL; |
| 1482 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1483 | |
| 1484 | PTP_CNT_INIT(ptp); |
| 1485 | ptp.Code=PTP_OC_CANON_GetChanges; |
| 1486 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1487 | len=0; |
| 1488 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1489 | if (ret == PTP_RC_OK) |
| 1490 | *propnum=ptp_unpack_uint16_t_array(params,data,0,props); |
| 1491 | free(data); |
| 1492 | return ret; |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * ptp_canon_getfolderentries: |
| 1497 | * |
| 1498 | * This command reads a specified object's record in a device's filesystem, |
| 1499 | * or the records of all objects belonging to a specified folder (association). |
| 1500 | * |
| 1501 | * params: PTPParams* |
| 1502 | * uint32_t store - StorageID, |
| 1503 | * uint32_t p2 - Yet unknown (0 value works OK) |
| 1504 | * uint32_t parent - Parent Object Handle |
| 1505 | * # If Parent Object Handle is 0xffffffff, |
| 1506 | * # the Parent Object is the top level folder. |
| 1507 | * uint32_t handle - Object Handle |
| 1508 | * # If Object Handle is 0, the records of all objects |
| 1509 | * # belonging to the Parent Object are read. |
| 1510 | * # If Object Handle is not 0, only the record of this |
| 1511 | * # Object is read. |
| 1512 | * |
| 1513 | * Return values: Some PTP_RC_* code. |
| 1514 | * PTPCANONFolderEntry** entries - the pointer to the folder entry array |
| 1515 | * uint32_t* entnum - the number of elements of the array |
| 1516 | * |
| 1517 | **/ |
| 1518 | uint16_t |
| 1519 | ptp_canon_getfolderentries (PTPParams* params, uint32_t store, uint32_t p2, |
| 1520 | uint32_t parent, uint32_t handle, |
| 1521 | PTPCANONFolderEntry** entries, uint32_t* entnum) |
| 1522 | { |
| 1523 | uint16_t ret; |
| 1524 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1525 | unsigned char *data = NULL; |
| 1526 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1527 | |
| 1528 | PTP_CNT_INIT(ptp); |
| 1529 | ptp.Code=PTP_OC_CANON_GetFolderEntries; |
| 1530 | ptp.Param1=store; |
| 1531 | ptp.Param2=p2; |
| 1532 | ptp.Param3=parent; |
| 1533 | ptp.Param4=handle; |
| 1534 | ptp.Nparam=4; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1535 | len=0; |
| 1536 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1537 | if (ret == PTP_RC_OK) { |
| 1538 | int i; |
| 1539 | *entnum=ptp.Param1; |
| 1540 | *entries=calloc(*entnum, sizeof(PTPCANONFolderEntry)); |
| 1541 | if (*entries!=NULL) { |
| 1542 | for(i=0; i<(*entnum); i++) |
| 1543 | ptp_unpack_Canon_FE(params, |
| 1544 | data+i*PTP_CANON_FolderEntryLen, |
| 1545 | &((*entries)[i]) ); |
| 1546 | } else { |
| 1547 | ret=PTP_ERROR_IO; /* Cannot allocate memory */ |
| 1548 | } |
| 1549 | } |
| 1550 | free(data); |
| 1551 | return ret; |
| 1552 | } |
| 1553 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1554 | /** |
| 1555 | * ptp_canon_theme_download: |
| 1556 | * |
| 1557 | * This command downloads the specified theme slot, including jpegs |
| 1558 | * and wav files. |
| 1559 | * |
| 1560 | * params: PTPParams* |
| 1561 | * uint32_t themenr - nr of theme |
| 1562 | * |
| 1563 | * Return values: Some PTP_RC_* code. |
| 1564 | * unsigned char **data - pointer to data pointer |
| 1565 | * unsigned int *size - size of data returned |
| 1566 | * |
| 1567 | **/ |
| 1568 | uint16_t |
| 1569 | ptp_canon_theme_download (PTPParams* params, uint32_t themenr, |
| 1570 | unsigned char **data, unsigned int *size) |
| 1571 | { |
| 1572 | PTPContainer ptp; |
| 1573 | |
| 1574 | *data = NULL; |
| 1575 | *size = 0; |
| 1576 | PTP_CNT_INIT(ptp); |
| 1577 | ptp.Code = PTP_OC_CANON_ThemeDownload; |
| 1578 | ptp.Param1 = themenr; |
| 1579 | ptp.Nparam = 1; |
| 1580 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | uint16_t |
| 1586 | ptp_nikon_curve_download (PTPParams* params, unsigned char **data, unsigned int *size) { |
| 1587 | PTPContainer ptp; |
| 1588 | *data = NULL; |
| 1589 | *size = 0; |
| 1590 | PTP_CNT_INIT(ptp); |
| 1591 | ptp.Code = PTP_OC_NIKON_CurveDownload; |
| 1592 | ptp.Nparam = 0; |
| 1593 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1594 | } |
| 1595 | |
| 1596 | uint16_t |
| 1597 | ptp_nikon_getfileinfoinblock ( PTPParams* params, |
| 1598 | uint32_t p1, uint32_t p2, uint32_t p3, |
| 1599 | unsigned char **data, unsigned int *size |
| 1600 | ) { |
| 1601 | PTPContainer ptp; |
| 1602 | *data = NULL; |
| 1603 | *size = 0; |
| 1604 | PTP_CNT_INIT(ptp); |
| 1605 | ptp.Code = PTP_OC_NIKON_GetFileInfoInBlock; |
| 1606 | ptp.Nparam = 3; |
| 1607 | ptp.Param1 = p1; |
| 1608 | ptp.Param2 = p2; |
| 1609 | ptp.Param3 = p3; |
| 1610 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * ptp_nikon_setcontrolmode: |
| 1615 | * |
| 1616 | * This command can switch the camera to full PC control mode. |
| 1617 | * |
| 1618 | * params: PTPParams* |
| 1619 | * uint32_t mode - mode |
| 1620 | * |
| 1621 | * Return values: Some PTP_RC_* code. |
| 1622 | * |
| 1623 | **/ |
| 1624 | uint16_t |
| 1625 | ptp_nikon_setcontrolmode (PTPParams* params, uint32_t mode) |
| 1626 | { |
| 1627 | PTPContainer ptp; |
| 1628 | |
| 1629 | PTP_CNT_INIT(ptp); |
| 1630 | ptp.Code=PTP_OC_NIKON_SetControlMode; |
| 1631 | ptp.Param1=mode; |
| 1632 | ptp.Nparam=1; |
| 1633 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * ptp_nikon_capture: |
| 1638 | * |
| 1639 | * This command captures a picture on the Nikon. |
| 1640 | * |
| 1641 | * params: PTPParams* |
| 1642 | * uint32_t x - unknown parameter. seen to be -1. |
| 1643 | * |
| 1644 | * Return values: Some PTP_RC_* code. |
| 1645 | * |
| 1646 | **/ |
| 1647 | uint16_t |
| 1648 | ptp_nikon_capture (PTPParams* params, uint32_t x) |
| 1649 | { |
| 1650 | PTPContainer ptp; |
| 1651 | |
| 1652 | PTP_CNT_INIT(ptp); |
| 1653 | ptp.Code=PTP_OC_NIKON_Capture; |
| 1654 | ptp.Param1=x; |
| 1655 | ptp.Nparam=1; |
| 1656 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1657 | } |
| 1658 | |
| 1659 | /** |
| 1660 | * ptp_nikon_check_event: |
| 1661 | * |
| 1662 | * This command checks the event queue on the Nikon. |
| 1663 | * |
| 1664 | * params: PTPParams* |
| 1665 | * PTPUSBEventContainer **event - list of usb events. |
| 1666 | * int *evtcnt - number of usb events in event structure. |
| 1667 | * |
| 1668 | * Return values: Some PTP_RC_* code. |
| 1669 | * |
| 1670 | **/ |
| 1671 | uint16_t |
| 1672 | ptp_nikon_check_event (PTPParams* params, PTPUSBEventContainer** event, int* evtcnt) |
| 1673 | { |
| 1674 | PTPContainer ptp; |
| 1675 | uint16_t ret; |
| 1676 | unsigned char *data = NULL; |
| 1677 | unsigned int size = 0; |
| 1678 | |
| 1679 | PTP_CNT_INIT(ptp); |
| 1680 | ptp.Code=PTP_OC_NIKON_CheckEvent; |
| 1681 | ptp.Nparam=0; |
| 1682 | *evtcnt = 0; |
| 1683 | ret = ptp_transaction (params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 1684 | if (ret == PTP_RC_OK) { |
| 1685 | ptp_unpack_Nikon_EC (params, data, size, event, evtcnt); |
| 1686 | free (data); |
| 1687 | } |
| 1688 | return ret; |
| 1689 | } |
| 1690 | |
| 1691 | /** |
| 1692 | * ptp_nikon_device_ready: |
| 1693 | * |
| 1694 | * This command checks if the device is ready. Used after |
| 1695 | * a capture. |
| 1696 | * |
| 1697 | * params: PTPParams* |
| 1698 | * |
| 1699 | * Return values: Some PTP_RC_* code. |
| 1700 | * |
| 1701 | **/ |
| 1702 | uint16_t |
| 1703 | ptp_nikon_device_ready (PTPParams* params) |
| 1704 | { |
| 1705 | PTPContainer ptp; |
| 1706 | |
| 1707 | PTP_CNT_INIT(ptp); |
| 1708 | ptp.Code=PTP_OC_NIKON_DeviceReady; |
| 1709 | ptp.Nparam=0; |
| 1710 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1711 | } |
| 1712 | |
| 1713 | /** |
| 1714 | * ptp_nikon_getptpipinfo: |
| 1715 | * |
| 1716 | * This command gets the ptpip info data. |
| 1717 | * |
| 1718 | * params: PTPParams* |
| 1719 | * unsigned char *data - data |
| 1720 | * unsigned int size - size of returned data |
| 1721 | * |
| 1722 | * Return values: Some PTP_RC_* code. |
| 1723 | * |
| 1724 | **/ |
| 1725 | uint16_t |
| 1726 | ptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1727 | { |
| 1728 | PTPContainer ptp; |
| 1729 | |
| 1730 | PTP_CNT_INIT(ptp); |
| 1731 | ptp.Code=PTP_OC_NIKON_GetDevicePTPIPInfo; |
| 1732 | ptp.Nparam=0; |
| 1733 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1734 | } |
| 1735 | |
| 1736 | /** |
| 1737 | * ptp_nikon_getprofilealldata: |
| 1738 | * |
| 1739 | * This command gets the ptpip info data. |
| 1740 | * |
| 1741 | * params: PTPParams* |
| 1742 | * unsigned char *data - data |
| 1743 | * unsigned int size - size of returned data |
| 1744 | * |
| 1745 | * Return values: Some PTP_RC_* code. |
| 1746 | * |
| 1747 | **/ |
| 1748 | uint16_t |
| 1749 | ptp_nikon_getprofilealldata (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1750 | { |
| 1751 | PTPContainer ptp; |
| 1752 | |
| 1753 | PTP_CNT_INIT(ptp); |
| 1754 | ptp.Code=PTP_OC_NIKON_GetProfileAllData; |
| 1755 | ptp.Nparam=0; |
| 1756 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1757 | } |
| 1758 | |
| 1759 | /** |
| 1760 | * ptp_nikon_sendprofiledata: |
| 1761 | * |
| 1762 | * This command gets the ptpip info data. |
| 1763 | * |
| 1764 | * params: PTPParams* |
| 1765 | * unsigned char *data - data |
| 1766 | * unsigned int size - size of returned data |
| 1767 | * |
| 1768 | * Return values: Some PTP_RC_* code. |
| 1769 | * |
| 1770 | **/ |
| 1771 | uint16_t |
| 1772 | ptp_nikon_sendprofiledata (PTPParams* params, uint32_t profilenr, unsigned char *data, unsigned int size) |
| 1773 | { |
| 1774 | PTPContainer ptp; |
| 1775 | |
| 1776 | PTP_CNT_INIT(ptp); |
| 1777 | ptp.Code=PTP_OC_NIKON_SendProfileData; |
| 1778 | ptp.Nparam=1; |
| 1779 | ptp.Param1=profilenr; |
| 1780 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * ptp_mtp_getobjectpropssupported: |
| 1785 | * |
| 1786 | * This command gets the object properties possible from the device. |
| 1787 | * |
| 1788 | * params: PTPParams* |
| 1789 | * uint ofc - object format code |
| 1790 | * unsigned int *propnum - number of elements in returned array |
| 1791 | * uint16_t *props - array of supported properties |
| 1792 | * |
| 1793 | * Return values: Some PTP_RC_* code. |
| 1794 | * |
| 1795 | **/ |
| 1796 | uint16_t |
| 1797 | ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc, |
| 1798 | uint32_t *propnum, uint16_t **props |
| 1799 | ) { |
| 1800 | PTPContainer ptp; |
| 1801 | uint16_t ret; |
| 1802 | unsigned char *data = NULL; |
| 1803 | unsigned int size = 0; |
| 1804 | |
| 1805 | PTP_CNT_INIT(ptp); |
| 1806 | ptp.Code=PTP_OC_MTP_GetObjectPropsSupported; |
| 1807 | ptp.Nparam = 1; |
| 1808 | ptp.Param1 = ofc; |
| 1809 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 1810 | if (ret == PTP_RC_OK) |
| 1811 | *propnum=ptp_unpack_uint16_t_array(params,data,0,props); |
| 1812 | free(data); |
| 1813 | return ret; |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * ptp_mtp_getobjectpropdesc: |
| 1818 | * |
| 1819 | * This command gets the object property description. |
| 1820 | * |
| 1821 | * params: PTPParams* |
| 1822 | * uint16_t opc - object property code |
| 1823 | * uint16_t ofc - object format code |
| 1824 | * |
| 1825 | * Return values: Some PTP_RC_* code. |
| 1826 | * |
| 1827 | **/ |
| 1828 | uint16_t |
| 1829 | ptp_mtp_getobjectpropdesc ( |
| 1830 | PTPParams* params, uint16_t opc, uint16_t ofc, PTPObjectPropDesc *opd |
| 1831 | ) { |
| 1832 | PTPContainer ptp; |
| 1833 | uint16_t ret; |
| 1834 | unsigned char *data = NULL; |
| 1835 | unsigned int size = 0; |
| 1836 | |
| 1837 | PTP_CNT_INIT(ptp); |
| 1838 | ptp.Code=PTP_OC_MTP_GetObjectPropDesc; |
| 1839 | ptp.Nparam = 2; |
| 1840 | ptp.Param1 = opc; |
| 1841 | ptp.Param2 = ofc; |
| 1842 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 1843 | if (ret == PTP_RC_OK) |
| 1844 | ptp_unpack_OPD (params, data, opd, size); |
| 1845 | free(data); |
| 1846 | return ret; |
| 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * ptp_mtp_getobjectpropvalue: |
| 1851 | * |
| 1852 | * This command gets the object properties of an object handle. |
| 1853 | * |
| 1854 | * params: PTPParams* |
| 1855 | * uint32_t objectid - object format code |
| 1856 | * uint16_t opc - object prop code |
| 1857 | * |
| 1858 | * Return values: Some PTP_RC_* code. |
| 1859 | * |
| 1860 | **/ |
| 1861 | uint16_t |
| 1862 | ptp_mtp_getobjectpropvalue ( |
| 1863 | PTPParams* params, uint32_t oid, uint16_t opc, |
| 1864 | PTPPropertyValue *value, uint16_t datatype |
| 1865 | ) { |
| 1866 | PTPContainer ptp; |
| 1867 | uint16_t ret; |
| 1868 | unsigned char *data = NULL; |
| 1869 | unsigned int size = 0; |
| 1870 | int offset = 0; |
| 1871 | |
| 1872 | PTP_CNT_INIT(ptp); |
| 1873 | ptp.Code=PTP_OC_MTP_GetObjectPropValue; |
| 1874 | ptp.Nparam = 2; |
| 1875 | ptp.Param1 = oid; |
| 1876 | ptp.Param2 = opc; |
| 1877 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 1878 | if (ret == PTP_RC_OK) |
| 1879 | ptp_unpack_DPV(params, data, &offset, size, value, datatype); |
| 1880 | free(data); |
| 1881 | return ret; |
| 1882 | } |
| 1883 | |
| 1884 | /** |
| 1885 | * ptp_mtp_setobjectpropvalue: |
| 1886 | * |
| 1887 | * This command gets the object properties of an object handle. |
| 1888 | * |
| 1889 | * params: PTPParams* |
| 1890 | * uint32_t objectid - object format code |
| 1891 | * uint16_t opc - object prop code |
| 1892 | * |
| 1893 | * Return values: Some PTP_RC_* code. |
| 1894 | * |
| 1895 | **/ |
| 1896 | uint16_t |
| 1897 | ptp_mtp_setobjectpropvalue ( |
| 1898 | PTPParams* params, uint32_t oid, uint16_t opc, |
| 1899 | PTPPropertyValue *value, uint16_t datatype |
| 1900 | ) { |
| 1901 | PTPContainer ptp; |
| 1902 | uint16_t ret; |
| 1903 | unsigned char *data = NULL; |
| 1904 | unsigned int size ; |
| 1905 | |
| 1906 | PTP_CNT_INIT(ptp); |
| 1907 | ptp.Code=PTP_OC_MTP_SetObjectPropValue; |
| 1908 | ptp.Nparam = 2; |
| 1909 | ptp.Param1 = oid; |
| 1910 | ptp.Param2 = opc; |
| 1911 | size = ptp_pack_DPV(params, value, &data, datatype); |
| 1912 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1913 | free(data); |
| 1914 | return ret; |
| 1915 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1916 | |
| 1917 | /* Non PTP protocol functions */ |
| 1918 | /* devinfo testing functions */ |
| 1919 | |
| 1920 | int |
| 1921 | ptp_operation_issupported(PTPParams* params, uint16_t operation) |
| 1922 | { |
| 1923 | int i=0; |
| 1924 | |
| 1925 | for (;i<params->deviceinfo.OperationsSupported_len;i++) { |
| 1926 | if (params->deviceinfo.OperationsSupported[i]==operation) |
| 1927 | return 1; |
| 1928 | } |
| 1929 | return 0; |
| 1930 | } |
| 1931 | |
| 1932 | |
| 1933 | int |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1934 | ptp_event_issupported(PTPParams* params, uint16_t event) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1935 | { |
| 1936 | int i=0; |
| 1937 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1938 | for (;i<params->deviceinfo.EventsSupported_len;i++) { |
| 1939 | if (params->deviceinfo.EventsSupported[i]==event) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1940 | return 1; |
| 1941 | } |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1945 | |
| 1946 | int |
| 1947 | ptp_property_issupported(PTPParams* params, uint16_t property) |
| 1948 | { |
| 1949 | int i=0; |
| 1950 | |
| 1951 | for (;i<params->deviceinfo.DevicePropertiesSupported_len;i++) |
| 1952 | if (params->deviceinfo.DevicePropertiesSupported[i]==property) |
| 1953 | return 1; |
| 1954 | return 0; |
| 1955 | } |
| 1956 | |
| 1957 | /* ptp structures freeing functions */ |
| 1958 | void |
| 1959 | ptp_free_devicepropvalue(uint16_t dt, PTPPropertyValue* dpd) { |
| 1960 | switch (dt) { |
| 1961 | case PTP_DTC_INT8: case PTP_DTC_UINT8: |
| 1962 | case PTP_DTC_UINT16: case PTP_DTC_INT16: |
| 1963 | case PTP_DTC_UINT32: case PTP_DTC_INT32: |
| 1964 | case PTP_DTC_UINT64: case PTP_DTC_INT64: |
| 1965 | case PTP_DTC_UINT128: case PTP_DTC_INT128: |
| 1966 | /* Nothing to free */ |
| 1967 | break; |
| 1968 | case PTP_DTC_AINT8: case PTP_DTC_AUINT8: |
| 1969 | case PTP_DTC_AUINT16: case PTP_DTC_AINT16: |
| 1970 | case PTP_DTC_AUINT32: case PTP_DTC_AINT32: |
| 1971 | case PTP_DTC_AUINT64: case PTP_DTC_AINT64: |
| 1972 | case PTP_DTC_AUINT128: case PTP_DTC_AINT128: |
| 1973 | if (dpd->a.v) |
| 1974 | free(dpd->a.v); |
| 1975 | break; |
| 1976 | case PTP_DTC_STR: |
| 1977 | if (dpd->str) |
| 1978 | free(dpd->str); |
| 1979 | break; |
| 1980 | } |
| 1981 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1982 | |
| 1983 | void |
| 1984 | ptp_free_devicepropdesc(PTPDevicePropDesc* dpd) |
| 1985 | { |
| 1986 | uint16_t i; |
| 1987 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1988 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FactoryDefaultValue); |
| 1989 | ptp_free_devicepropvalue (dpd->DataType, &dpd->CurrentValue); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1990 | switch (dpd->FormFlag) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1991 | case PTP_DPFF_Range: |
| 1992 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MinimumValue); |
| 1993 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MaximumValue); |
| 1994 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.StepSize); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1995 | break; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1996 | case PTP_DPFF_Enumeration: |
| 1997 | if (dpd->FORM.Enum.SupportedValue) { |
| 1998 | for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++) |
| 1999 | ptp_free_devicepropvalue (dpd->DataType, dpd->FORM.Enum.SupportedValue+i); |
| 2000 | free (dpd->FORM.Enum.SupportedValue); |
| 2001 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2005 | void |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2006 | ptp_free_objectpropdesc(PTPObjectPropDesc* opd) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2007 | { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2008 | uint16_t i; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2009 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2010 | ptp_free_devicepropvalue (opd->DataType, &opd->FactoryDefaultValue); |
| 2011 | switch (opd->FormFlag) { |
| 2012 | case PTP_OPFF_None: |
| 2013 | break; |
| 2014 | case PTP_OPFF_Range: |
| 2015 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MinimumValue); |
| 2016 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MaximumValue); |
| 2017 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.StepSize); |
| 2018 | break; |
| 2019 | case PTP_OPFF_Enumeration: |
| 2020 | if (opd->FORM.Enum.SupportedValue) { |
| 2021 | for (i=0;i<opd->FORM.Enum.NumberOfValues;i++) |
| 2022 | ptp_free_devicepropvalue (opd->DataType, opd->FORM.Enum.SupportedValue+i); |
| 2023 | free (opd->FORM.Enum.SupportedValue); |
| 2024 | } |
| 2025 | default: |
| 2026 | fprintf (stderr, "Unknown OPFF type %d\n", opd->FormFlag); |
| 2027 | break; |
| 2028 | } |
| 2029 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2030 | |
| 2031 | void |
| 2032 | ptp_perror(PTPParams* params, uint16_t error) { |
| 2033 | |
| 2034 | int i; |
| 2035 | /* PTP error descriptions */ |
| 2036 | static struct { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2037 | short n; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2038 | const char *txt; |
| 2039 | } ptp_errors[] = { |
| 2040 | {PTP_RC_Undefined, N_("PTP: Undefined Error")}, |
| 2041 | {PTP_RC_OK, N_("PTP: OK!")}, |
| 2042 | {PTP_RC_GeneralError, N_("PTP: General Error")}, |
| 2043 | {PTP_RC_SessionNotOpen, N_("PTP: Session Not Open")}, |
| 2044 | {PTP_RC_InvalidTransactionID, N_("PTP: Invalid Transaction ID")}, |
| 2045 | {PTP_RC_OperationNotSupported, N_("PTP: Operation Not Supported")}, |
| 2046 | {PTP_RC_ParameterNotSupported, N_("PTP: Parameter Not Supported")}, |
| 2047 | {PTP_RC_IncompleteTransfer, N_("PTP: Incomplete Transfer")}, |
| 2048 | {PTP_RC_InvalidStorageId, N_("PTP: Invalid Storage ID")}, |
| 2049 | {PTP_RC_InvalidObjectHandle, N_("PTP: Invalid Object Handle")}, |
| 2050 | {PTP_RC_DevicePropNotSupported, N_("PTP: Device Prop Not Supported")}, |
| 2051 | {PTP_RC_InvalidObjectFormatCode, N_("PTP: Invalid Object Format Code")}, |
| 2052 | {PTP_RC_StoreFull, N_("PTP: Store Full")}, |
| 2053 | {PTP_RC_ObjectWriteProtected, N_("PTP: Object Write Protected")}, |
| 2054 | {PTP_RC_StoreReadOnly, N_("PTP: Store Read Only")}, |
| 2055 | {PTP_RC_AccessDenied, N_("PTP: Access Denied")}, |
| 2056 | {PTP_RC_NoThumbnailPresent, N_("PTP: No Thumbnail Present")}, |
| 2057 | {PTP_RC_SelfTestFailed, N_("PTP: Self Test Failed")}, |
| 2058 | {PTP_RC_PartialDeletion, N_("PTP: Partial Deletion")}, |
| 2059 | {PTP_RC_StoreNotAvailable, N_("PTP: Store Not Available")}, |
| 2060 | {PTP_RC_SpecificationByFormatUnsupported, |
| 2061 | N_("PTP: Specification By Format Unsupported")}, |
| 2062 | {PTP_RC_NoValidObjectInfo, N_("PTP: No Valid Object Info")}, |
| 2063 | {PTP_RC_InvalidCodeFormat, N_("PTP: Invalid Code Format")}, |
| 2064 | {PTP_RC_UnknownVendorCode, N_("PTP: Unknown Vendor Code")}, |
| 2065 | {PTP_RC_CaptureAlreadyTerminated, |
| 2066 | N_("PTP: Capture Already Terminated")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2067 | {PTP_RC_DeviceBusy, N_("PTP: Device Busy")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2068 | {PTP_RC_InvalidParentObject, N_("PTP: Invalid Parent Object")}, |
| 2069 | {PTP_RC_InvalidDevicePropFormat, N_("PTP: Invalid Device Prop Format")}, |
| 2070 | {PTP_RC_InvalidDevicePropValue, N_("PTP: Invalid Device Prop Value")}, |
| 2071 | {PTP_RC_InvalidParameter, N_("PTP: Invalid Parameter")}, |
| 2072 | {PTP_RC_SessionAlreadyOpened, N_("PTP: Session Already Opened")}, |
| 2073 | {PTP_RC_TransactionCanceled, N_("PTP: Transaction Canceled")}, |
| 2074 | {PTP_RC_SpecificationOfDestinationUnsupported, |
| 2075 | N_("PTP: Specification Of Destination Unsupported")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2076 | {PTP_RC_EK_FilenameRequired, N_("PTP: EK Filename Required")}, |
| 2077 | {PTP_RC_EK_FilenameConflicts, N_("PTP: EK Filename Conflicts")}, |
| 2078 | {PTP_RC_EK_FilenameInvalid, N_("PTP: EK Filename Invalid")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2079 | |
| 2080 | {PTP_ERROR_IO, N_("PTP: I/O error")}, |
| 2081 | {PTP_ERROR_BADPARAM, N_("PTP: Error: bad parameter")}, |
| 2082 | {PTP_ERROR_DATA_EXPECTED, N_("PTP: Protocol error, data expected")}, |
| 2083 | {PTP_ERROR_RESP_EXPECTED, N_("PTP: Protocol error, response expected")}, |
| 2084 | {0, NULL} |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2085 | }; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2086 | |
| 2087 | for (i=0; ptp_errors[i].txt!=NULL; i++) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2088 | if (ptp_errors[i].n == error) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2089 | ptp_error(params, ptp_errors[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2092 | const char* |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2093 | ptp_get_property_description(PTPParams* params, uint16_t dpc) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2094 | { |
| 2095 | int i; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2096 | // Device Property descriptions |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2097 | struct { |
| 2098 | uint16_t dpc; |
| 2099 | const char *txt; |
| 2100 | } ptp_device_properties[] = { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2101 | {PTP_DPC_Undefined, N_("Undefined PTP Property")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2102 | {PTP_DPC_BatteryLevel, N_("Battery Level")}, |
| 2103 | {PTP_DPC_FunctionalMode, N_("Functional Mode")}, |
| 2104 | {PTP_DPC_ImageSize, N_("Image Size")}, |
| 2105 | {PTP_DPC_CompressionSetting, N_("Compression Setting")}, |
| 2106 | {PTP_DPC_WhiteBalance, N_("White Balance")}, |
| 2107 | {PTP_DPC_RGBGain, N_("RGB Gain")}, |
| 2108 | {PTP_DPC_FNumber, N_("F-Number")}, |
| 2109 | {PTP_DPC_FocalLength, N_("Focal Length")}, |
| 2110 | {PTP_DPC_FocusDistance, N_("Focus Distance")}, |
| 2111 | {PTP_DPC_FocusMode, N_("Focus Mode")}, |
| 2112 | {PTP_DPC_ExposureMeteringMode, N_("Exposure Metering Mode")}, |
| 2113 | {PTP_DPC_FlashMode, N_("Flash Mode")}, |
| 2114 | {PTP_DPC_ExposureTime, N_("Exposure Time")}, |
| 2115 | {PTP_DPC_ExposureProgramMode, N_("Exposure Program Mode")}, |
| 2116 | {PTP_DPC_ExposureIndex, |
| 2117 | N_("Exposure Index (film speed ISO)")}, |
| 2118 | {PTP_DPC_ExposureBiasCompensation, |
| 2119 | N_("Exposure Bias Compensation")}, |
| 2120 | {PTP_DPC_DateTime, N_("Date Time")}, |
| 2121 | {PTP_DPC_CaptureDelay, N_("Pre-Capture Delay")}, |
| 2122 | {PTP_DPC_StillCaptureMode, N_("Still Capture Mode")}, |
| 2123 | {PTP_DPC_Contrast, N_("Contrast")}, |
| 2124 | {PTP_DPC_Sharpness, N_("Sharpness")}, |
| 2125 | {PTP_DPC_DigitalZoom, N_("Digital Zoom")}, |
| 2126 | {PTP_DPC_EffectMode, N_("Effect Mode")}, |
| 2127 | {PTP_DPC_BurstNumber, N_("Burst Number")}, |
| 2128 | {PTP_DPC_BurstInterval, N_("Burst Interval")}, |
| 2129 | {PTP_DPC_TimelapseNumber, N_("Timelapse Number")}, |
| 2130 | {PTP_DPC_TimelapseInterval, N_("Timelapse Interval")}, |
| 2131 | {PTP_DPC_FocusMeteringMode, N_("Focus Metering Mode")}, |
| 2132 | {PTP_DPC_UploadURL, N_("Upload URL")}, |
| 2133 | {PTP_DPC_Artist, N_("Artist")}, |
| 2134 | {PTP_DPC_CopyrightInfo, N_("Copyright Info")}, |
| 2135 | {0,NULL} |
| 2136 | }; |
| 2137 | struct { |
| 2138 | uint16_t dpc; |
| 2139 | const char *txt; |
| 2140 | } ptp_device_properties_EK[] = { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2141 | {PTP_DPC_EK_ColorTemperature, N_("Color Temperature")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2142 | {PTP_DPC_EK_DateTimeStampFormat, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2143 | N_("Date Time Stamp Format")}, |
| 2144 | {PTP_DPC_EK_BeepMode, N_("Beep Mode")}, |
| 2145 | {PTP_DPC_EK_VideoOut, N_("Video Out")}, |
| 2146 | {PTP_DPC_EK_PowerSaving, N_("Power Saving")}, |
| 2147 | {PTP_DPC_EK_UI_Language, N_("UI Language")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2148 | {0,NULL} |
| 2149 | }; |
| 2150 | |
| 2151 | struct { |
| 2152 | uint16_t dpc; |
| 2153 | const char *txt; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2154 | } ptp_device_properties_Canon[] = { |
| 2155 | {PTP_DPC_CANON_BeepMode, N_("Beep Mode")}, |
| 2156 | {PTP_DPC_CANON_ViewfinderMode, N_("Viewfinder Mode")}, |
| 2157 | {PTP_DPC_CANON_ImageQuality, N_("Image Quality")}, |
| 2158 | {PTP_DPC_CANON_ImageSize, N_("Image Size")}, |
| 2159 | {PTP_DPC_CANON_FlashMode, N_("Flash Mode")}, |
| 2160 | {PTP_DPC_CANON_ShootingMode, N_("Shooting Mode")}, |
| 2161 | {PTP_DPC_CANON_MeteringMode, N_("Metering Mode")}, |
| 2162 | {PTP_DPC_CANON_AFDistance, N_("AF Distance")}, |
| 2163 | {PTP_DPC_CANON_FocusingPoint, N_("Focusing Point")}, |
| 2164 | {PTP_DPC_CANON_WhiteBalance, N_("White Balance")}, |
| 2165 | {PTP_DPC_CANON_ISOSpeed, N_("ISO Speed")}, |
| 2166 | {PTP_DPC_CANON_Aperture, N_("Aperture")}, |
| 2167 | {PTP_DPC_CANON_ShutterSpeed, N_("ShutterSpeed")}, |
| 2168 | {PTP_DPC_CANON_ExpCompensation, N_("Exposure Compensation")}, |
| 2169 | {PTP_DPC_CANON_Zoom, N_("Zoom")}, |
| 2170 | {PTP_DPC_CANON_SizeQualityMode, N_("Size Quality Mode")}, |
| 2171 | {PTP_DPC_CANON_FirmwareVersion, N_("Firmware Version")}, |
| 2172 | {PTP_DPC_CANON_CameraModel, N_("Camera Model")}, |
| 2173 | {PTP_DPC_CANON_CameraOwner, N_("Camera Owner")}, |
| 2174 | {PTP_DPC_CANON_UnixTime, N_("UNIX Time")}, |
| 2175 | {PTP_DPC_CANON_DZoomMagnification, N_("Digital Zoom Magnification")}, |
| 2176 | {PTP_DPC_CANON_PhotoEffect, N_("Photo Effect")}, |
| 2177 | {PTP_DPC_CANON_AssistLight, N_("Assist Light")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2178 | {0,NULL} |
| 2179 | }; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2180 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2181 | struct { |
| 2182 | uint16_t dpc; |
| 2183 | const char *txt; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2184 | } ptp_device_properties_Nikon[] = { |
| 2185 | {PTP_DPC_NIKON_WhiteBalanceAutoBias, /* 0xD017 */ |
| 2186 | N_("Auto White Balance Bias")}, |
| 2187 | {PTP_DPC_NIKON_WhiteBalanceTungstenBias, /* 0xD018 */ |
| 2188 | N_("Tungsten White Balance Bias")}, |
| 2189 | {PTP_DPC_NIKON_WhiteBalanceFlourescentBias, /* 0xD019 */ |
| 2190 | N_("Flourescent White Balance Bias")}, |
| 2191 | {PTP_DPC_NIKON_WhiteBalanceDaylightBias, /* 0xD01a */ |
| 2192 | N_("Daylight White Balance Bias")}, |
| 2193 | {PTP_DPC_NIKON_WhiteBalanceFlashBias, /* 0xD01b */ |
| 2194 | N_("Flash White Balance Bias")}, |
| 2195 | {PTP_DPC_NIKON_WhiteBalanceCloudyBias, /* 0xD01c */ |
| 2196 | N_("Cloudy White Balance Bias")}, |
| 2197 | {PTP_DPC_NIKON_WhiteBalanceShadeBias, /* 0xD01d */ |
| 2198 | N_("Shady White Balance Bias")}, |
| 2199 | {PTP_DPC_NIKON_WhiteBalanceColorTemperature, /* 0xD01e */ |
| 2200 | N_("White Balance Colour Temperature")}, |
| 2201 | {PTP_DPC_NIKON_ImageSharpening, /* 0xD02a */ |
| 2202 | N_("Sharpening")}, |
| 2203 | {PTP_DPC_NIKON_ToneCompensation, /* 0xD02b */ |
| 2204 | N_("Tone Compensation")}, |
| 2205 | {PTP_DPC_NIKON_ColorModel, /* 0xD02c */ |
| 2206 | N_("Color Model")}, |
| 2207 | {PTP_DPC_NIKON_HueAdjustment, /* 0xD02d */ |
| 2208 | N_("Hue Adjustment")}, |
| 2209 | {PTP_DPC_NIKON_NonCPULensDataFocalLength, /* 0xD02e */ |
| 2210 | N_("Lens Focal Length (Non CPU)")}, |
| 2211 | {PTP_DPC_NIKON_NonCPULensDataMaximumAperture, /* 0xD02f */ |
| 2212 | N_("Lens Max. Aperture (Non CPU)")}, |
| 2213 | {PTP_DPC_NIKON_CSMMenuBankSelect, /* 0xD040 */ |
| 2214 | "PTP_DPC_NIKON_CSMMenuBankSelect"}, |
| 2215 | {PTP_DPC_NIKON_MenuBankNameA, /* 0xD041 */ |
| 2216 | "PTP_DPC_NIKON_MenuBankNameA"}, |
| 2217 | {PTP_DPC_NIKON_MenuBankNameB, /* 0xD042 */ |
| 2218 | "PTP_DPC_NIKON_MenuBankNameB"}, |
| 2219 | {PTP_DPC_NIKON_MenuBankNameC, /* 0xD043 */ |
| 2220 | "PTP_DPC_NIKON_MenuBankNameC"}, |
| 2221 | {PTP_DPC_NIKON_MenuBankNameD, /* 0xD044 */ |
| 2222 | "PTP_DPC_NIKON_MenuBankNameD"}, |
| 2223 | {PTP_DPC_NIKON_A1AFCModePriority, /* 0xD048 */ |
| 2224 | "PTP_DPC_NIKON_A1AFCModePriority"}, |
| 2225 | {PTP_DPC_NIKON_A2AFSModePriority, /* 0xD049 */ |
| 2226 | "PTP_DPC_NIKON_A2AFSModePriority"}, |
| 2227 | {PTP_DPC_NIKON_A3GroupDynamicAF, /* 0xD04a */ |
| 2228 | "PTP_DPC_NIKON_A3GroupDynamicAF"}, |
| 2229 | {PTP_DPC_NIKON_A4AFActivation, /* 0xD04b */ |
| 2230 | "PTP_DPC_NIKON_A4AFActivation"}, |
| 2231 | {PTP_DPC_NIKON_A5FocusAreaIllumManualFocus, /* 0xD04c */ |
| 2232 | "PTP_DPC_NIKON_A5FocusAreaIllumManualFocus"}, |
| 2233 | {PTP_DPC_NIKON_FocusAreaIllumContinuous, /* 0xD04d */ |
| 2234 | "PTP_DPC_NIKON_FocusAreaIllumContinuous"}, |
| 2235 | {PTP_DPC_NIKON_FocusAreaIllumWhenSelected, /* 0xD04e */ |
| 2236 | "PTP_DPC_NIKON_FocusAreaIllumWhenSelected"}, |
| 2237 | {PTP_DPC_NIKON_FocusAreaWrap, /* 0xD04f */ |
| 2238 | N_("Focus Area Wrap")}, |
| 2239 | {PTP_DPC_NIKON_A7VerticalAFON, /* 0xD050 */ |
| 2240 | N_("Vertical AF On")}, |
| 2241 | {PTP_DPC_NIKON_ISOAuto, /* 0xD054 */ |
| 2242 | N_("Auto ISO")}, |
| 2243 | {PTP_DPC_NIKON_B2ISOStep, /* 0xD055 */ |
| 2244 | N_("ISO Step")}, |
| 2245 | {PTP_DPC_NIKON_EVStep, /* 0xD056 */ |
| 2246 | N_("Exposure Step")}, |
| 2247 | {PTP_DPC_NIKON_B4ExposureCompEv, /* 0xD057 */ |
| 2248 | N_("Exposure Compensation (EV)")}, |
| 2249 | {PTP_DPC_NIKON_ExposureCompensation, /* 0xD058 */ |
| 2250 | N_("Exposure Compensation")}, |
| 2251 | {PTP_DPC_NIKON_CenterWeightArea, /* 0xD059 */ |
| 2252 | N_("Centre Weight Area")}, |
| 2253 | {PTP_DPC_NIKON_AELockMode, /* 0xD05e */ |
| 2254 | N_("Exposure Lock")}, |
| 2255 | {PTP_DPC_NIKON_AELAFLMode, /* 0xD05f */ |
| 2256 | N_("Focus Lock")}, |
| 2257 | {PTP_DPC_NIKON_MeterOff, /* 0xD062 */ |
| 2258 | N_("Auto Meter Off Time")}, |
| 2259 | {PTP_DPC_NIKON_SelfTimer, /* 0xD063 */ |
| 2260 | N_("Self Timer Delay")}, |
| 2261 | {PTP_DPC_NIKON_MonitorOff, /* 0xD064 */ |
| 2262 | N_("LCD Off Time")}, |
| 2263 | {PTP_DPC_NIKON_D1ShootingSpeed, /* 0xD068 */ |
| 2264 | N_("Shooting Speed")}, |
| 2265 | {PTP_DPC_NIKON_D2MaximumShots, /* 0xD069 */ |
| 2266 | N_("Max. Shots")}, |
| 2267 | {PTP_DPC_NIKON_D3ExpDelayMode, /* 0xD06a */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame^] | 2268 | "PTP_DPC_NIKON_D3ExpDelayMode"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2269 | {PTP_DPC_NIKON_LongExposureNoiseReduction, /* 0xD06b */ |
| 2270 | N_("Long Exposure Noise Reduction")}, |
| 2271 | {PTP_DPC_NIKON_FileNumberSequence, /* 0xD06c */ |
| 2272 | N_("File Number Sequencing")}, |
| 2273 | {PTP_DPC_NIKON_D6ControlPanelFinderRearControl, /* 0xD06d */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame^] | 2274 | "PTP_DPC_NIKON_D6ControlPanelFinderRearControl"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2275 | {PTP_DPC_NIKON_ControlPanelFinderViewfinder, /* 0xD06e */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame^] | 2276 | "PTP_DPC_NIKON_ControlPanelFinderViewfinder"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2277 | {PTP_DPC_NIKON_D7Illumination, /* 0xD06f */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame^] | 2278 | "PTP_DPC_NIKON_D7Illumination"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2279 | {PTP_DPC_NIKON_E1FlashSyncSpeed, /* 0xD074 */ |
| 2280 | N_("Flash Sync. Speed")}, |
| 2281 | {PTP_DPC_NIKON_FlashShutterSpeed, /* 0xD075 */ |
| 2282 | N_("Flash Shutter Speed")}, |
| 2283 | {PTP_DPC_NIKON_E3AAFlashMode, /* 0xD076 */ |
| 2284 | N_("Flash Mode")}, |
| 2285 | {PTP_DPC_NIKON_E4ModelingFlash, /* 0xD077 */ |
| 2286 | N_("Modeling Flash")}, |
| 2287 | {PTP_DPC_NIKON_BracketSet, /* 0xD078 */ |
| 2288 | N_("Bracket Set")}, |
| 2289 | {PTP_DPC_NIKON_E6ManualModeBracketing, /* 0xD079 */ |
| 2290 | N_("Manual Mode Bracketing")}, |
| 2291 | {PTP_DPC_NIKON_BracketOrder, /* 0xD07a */ |
| 2292 | N_("Bracket Order")}, |
| 2293 | {PTP_DPC_NIKON_E8AutoBracketSelection, /* 0xD07b */ |
| 2294 | N_("Auto Bracket Selection")}, |
| 2295 | {PTP_DPC_NIKON_F1CenterButtonShootingMode, /* 0xD080 */ |
| 2296 | N_("Center Button Shooting Mode")}, |
| 2297 | {PTP_DPC_NIKON_CenterButtonPlaybackMode, /* 0xD081 */ |
| 2298 | N_("Center Button Playback Mode")}, |
| 2299 | {PTP_DPC_NIKON_F2Multiselector, /* 0xD082 */ |
| 2300 | N_("Multiselector")}, |
| 2301 | {PTP_DPC_NIKON_F3PhotoInfoPlayback, /* 0xD083 */ |
| 2302 | N_("Photo Info. Playback")}, |
| 2303 | {PTP_DPC_NIKON_F4AssignFuncButton, /* 0xD084 */ |
| 2304 | N_("Assign Func. Button")}, |
| 2305 | {PTP_DPC_NIKON_F5CustomizeCommDials, /* 0xD085 */ |
| 2306 | N_("Customise Command Dials")}, |
| 2307 | {PTP_DPC_NIKON_ReverseCommandDial, /* 0xD086 */ |
| 2308 | N_("Reverse Command Dial")}, |
| 2309 | {PTP_DPC_NIKON_ApertureSetting, /* 0xD087 */ |
| 2310 | N_("Aperture Setting")}, |
| 2311 | {PTP_DPC_NIKON_MenusAndPlayback, /* 0xD088 */ |
| 2312 | N_("Menus and Playback")}, |
| 2313 | {PTP_DPC_NIKON_F6ButtonsAndDials, /* 0xD089 */ |
| 2314 | N_("Buttons and Dials")}, |
| 2315 | {PTP_DPC_NIKON_NoCFCard, /* 0xD08a */ |
| 2316 | N_("No CF Card Release")}, |
| 2317 | {PTP_DPC_NIKON_ImageRotation, /* 0xD092 */ |
| 2318 | N_("Image Rotation")}, |
| 2319 | {PTP_DPC_NIKON_Bracketing, /* 0xD0c0 */ |
| 2320 | N_("Exposure Bracketing")}, |
| 2321 | {PTP_DPC_NIKON_ExposureBracketingIntervalDist, /* 0xD0c1 */ |
| 2322 | N_("Exposure Bracketing Distance")}, |
| 2323 | {PTP_DPC_NIKON_BracketingProgram, /* 0xD0c2 */ |
| 2324 | N_("Exposure Bracketing Number")}, |
| 2325 | {PTP_DPC_NIKON_AutofocusLCDTopMode2, /* 0xD107 */ |
| 2326 | N_("AF LCD Top Mode 2")}, |
| 2327 | {PTP_DPC_NIKON_AutofocusArea, /* 0xD108 */ |
| 2328 | N_("Active AF Sensor")}, |
| 2329 | {PTP_DPC_NIKON_LightMeter, /* 0xD10a */ |
| 2330 | N_("Exposure Meter")}, |
| 2331 | {PTP_DPC_NIKON_ExposureApertureLock, /* 0xD111 */ |
| 2332 | N_("Exposure Aperture Lock")}, |
| 2333 | {PTP_DPC_NIKON_MaximumShots, /* 0xD103 */ |
| 2334 | N_("Maximum Shots")}, |
| 2335 | {PTP_DPC_NIKON_OptimizeImage, /* 0xD140 */ |
| 2336 | N_("Optimize Image")}, |
| 2337 | {PTP_DPC_NIKON_Saturation, /* 0xD142 */ |
| 2338 | N_("Saturation")}, |
| 2339 | {PTP_DPC_NIKON_CSMMenu, /* 0xD180 */ |
| 2340 | N_("CSM Menu")}, |
| 2341 | {PTP_DPC_NIKON_BeepOff, |
| 2342 | N_("AF Beep Mode")}, |
| 2343 | {PTP_DPC_NIKON_AutofocusMode, |
| 2344 | N_("Autofocus Mode")}, |
| 2345 | {PTP_DPC_NIKON_AFAssist, |
| 2346 | N_("AF Assist Lamp")}, |
| 2347 | {PTP_DPC_NIKON_PADVPMode, |
| 2348 | N_("Auto ISO P/A/DVP Setting")}, |
| 2349 | {PTP_DPC_NIKON_ImageReview, |
| 2350 | N_("Image Review")}, |
| 2351 | {PTP_DPC_NIKON_GridDisplay, |
| 2352 | N_("Viewfinder Grid Display")}, |
| 2353 | {PTP_DPC_NIKON_AFAreaIllumination, |
| 2354 | N_("AF Area Illumination")}, |
| 2355 | {PTP_DPC_NIKON_FlashMode, |
| 2356 | N_("Flash Mode")}, |
| 2357 | {PTP_DPC_NIKON_FlashModeManualPower, |
| 2358 | N_("Flash Mode Manual Power")}, |
| 2359 | {PTP_DPC_NIKON_FlashSign, |
| 2360 | N_("Flash Sign")}, |
| 2361 | {PTP_DPC_NIKON_FlashExposureCompensation, |
| 2362 | N_("Flash Exposure Compensation")}, |
| 2363 | {PTP_DPC_NIKON_RemoteTimeout, |
| 2364 | N_("Remote Timeout")}, |
| 2365 | {PTP_DPC_NIKON_ImageCommentString, |
| 2366 | N_("Image Comment String")}, |
| 2367 | {PTP_DPC_NIKON_FlashOpen, |
| 2368 | N_("Flash Open")}, |
| 2369 | {PTP_DPC_NIKON_FlashCharged, |
| 2370 | N_("Flash Charged")}, |
| 2371 | {PTP_DPC_NIKON_LensID, |
| 2372 | N_("Lens ID")}, |
| 2373 | {PTP_DPC_NIKON_FocalLengthMin, |
| 2374 | N_("Min. Focal Length")}, |
| 2375 | {PTP_DPC_NIKON_FocalLengthMax, |
| 2376 | N_("Max. Focal Length")}, |
| 2377 | {PTP_DPC_NIKON_MaxApAtMinFocalLength, |
| 2378 | N_("Max. Aperture at Min. Focal Length")}, |
| 2379 | {PTP_DPC_NIKON_MaxApAtMaxFocalLength, |
| 2380 | N_("Max. Aperture at Max. Focal Length")}, |
| 2381 | {PTP_DPC_NIKON_LowLight, |
| 2382 | N_("Low Light")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2383 | {0,NULL} |
| 2384 | }; |
| 2385 | |
| 2386 | for (i=0; ptp_device_properties[i].txt!=NULL; i++) |
| 2387 | if (ptp_device_properties[i].dpc==dpc) |
| 2388 | return (ptp_device_properties[i].txt); |
| 2389 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2390 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_EASTMAN_KODAK) |
| 2391 | for (i=0; ptp_device_properties_EK[i].txt!=NULL; i++) |
| 2392 | if (ptp_device_properties_EK[i].dpc==dpc) |
| 2393 | return (ptp_device_properties_EK[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2394 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2395 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_CANON) |
| 2396 | for (i=0; ptp_device_properties_Canon[i].txt!=NULL; i++) |
| 2397 | if (ptp_device_properties_Canon[i].dpc==dpc) |
| 2398 | return (ptp_device_properties_Canon[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2399 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2400 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON) |
| 2401 | for (i=0; ptp_device_properties_Nikon[i].txt!=NULL; i++) |
| 2402 | if (ptp_device_properties_Nikon[i].dpc==dpc) |
| 2403 | return (ptp_device_properties_Nikon[i].txt); |
| 2404 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2405 | return NULL; |
| 2406 | } |
| 2407 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2408 | static int64_t |
| 2409 | _value_to_num(PTPPropertyValue *data, uint16_t dt) { |
| 2410 | if (dt == PTP_DTC_STR) { |
| 2411 | if (!data->str) |
| 2412 | return 0; |
| 2413 | return atol(data->str); |
| 2414 | } |
| 2415 | if (dt & PTP_DTC_ARRAY_MASK) { |
| 2416 | return 0; |
| 2417 | } else { |
| 2418 | switch (dt) { |
| 2419 | case PTP_DTC_UNDEF: |
| 2420 | return 0; |
| 2421 | case PTP_DTC_INT8: |
| 2422 | return data->i8; |
| 2423 | case PTP_DTC_UINT8: |
| 2424 | return data->u8; |
| 2425 | case PTP_DTC_INT16: |
| 2426 | return data->i16; |
| 2427 | case PTP_DTC_UINT16: |
| 2428 | return data->u16; |
| 2429 | case PTP_DTC_INT32: |
| 2430 | return data->i32; |
| 2431 | case PTP_DTC_UINT32: |
| 2432 | return data->u32; |
| 2433 | /* |
| 2434 | PTP_DTC_INT64 |
| 2435 | PTP_DTC_UINT64 |
| 2436 | PTP_DTC_INT128 |
| 2437 | PTP_DTC_UINT128 |
| 2438 | */ |
| 2439 | default: |
| 2440 | return 0; |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | return 0; |
| 2445 | } |
| 2446 | |
| 2447 | #define PTP_VAL_BOOL(dpc) {dpc, 0, N_("Off")}, {dpc, 1, N_("On")} |
| 2448 | #define PTP_VAL_RBOOL(dpc) {dpc, 0, N_("On")}, {dpc, 1, N_("Off")} |
| 2449 | #define PTP_VAL_YN(dpc) {dpc, 0, N_("No")}, {dpc, 1, N_("Yes")} |
| 2450 | |
| 2451 | int |
| 2452 | ptp_render_property_value(PTPParams* params, uint16_t dpc, |
| 2453 | PTPDevicePropDesc *dpd, int length, char *out) |
| 2454 | { |
| 2455 | int i; |
| 2456 | |
| 2457 | struct { |
| 2458 | uint16_t dpc; |
| 2459 | double coef; |
| 2460 | double bias; |
| 2461 | const char *format; |
| 2462 | } ptp_value_trans[] = { |
| 2463 | {PTP_DPC_ExposureIndex, 1.0, 0.0, "ISO %.0f"}, |
| 2464 | {0, 0.0, 0.0, NULL} |
| 2465 | }; |
| 2466 | |
| 2467 | struct { |
| 2468 | uint16_t dpc; |
| 2469 | double coef; |
| 2470 | double bias; |
| 2471 | const char *format; |
| 2472 | } ptp_value_trans_Nikon[] = { |
| 2473 | {PTP_DPC_BatteryLevel, 1.0, 0.0, "%.0f%%"}, |
| 2474 | {PTP_DPC_FNumber, 0.01, 0.0, "f/%.2g"}, |
| 2475 | {PTP_DPC_FocalLength, 0.01, 0.0, "%.0f mm"}, |
| 2476 | {PTP_DPC_ExposureTime, 0.00001, 0.0, "%.2g sec"}, |
| 2477 | {PTP_DPC_ExposureBiasCompensation, 0.001, 0.0, N_("%.1f stops")}, |
| 2478 | {PTP_DPC_NIKON_LightMeter, 0.08333, 0.0, N_("%.1f stops")}, |
| 2479 | {PTP_DPC_NIKON_FlashExposureCompensation, 0.16666, 0.0, N_("%.1f stops")}, |
| 2480 | {PTP_DPC_NIKON_CenterWeightArea, 2.0, 6.0, N_("%.0f mm")}, |
| 2481 | {PTP_DPC_NIKON_FocalLengthMin, 0.01, 0.0, "%.0f mm"}, |
| 2482 | {PTP_DPC_NIKON_FocalLengthMax, 0.01, 0.0, "%.0f mm"}, |
| 2483 | {PTP_DPC_NIKON_MaxApAtMinFocalLength, 0.01, 0.0, "f/%.2g"}, |
| 2484 | {PTP_DPC_NIKON_MaxApAtMaxFocalLength, 0.01, 0.0, "f/%.2g"}, |
| 2485 | {0, 0.0, 0.0, NULL} |
| 2486 | }; |
| 2487 | |
| 2488 | struct { |
| 2489 | uint16_t dpc; |
| 2490 | int64_t key; |
| 2491 | char *value; |
| 2492 | } ptp_value_list_Nikon[] = { |
| 2493 | {PTP_DPC_CompressionSetting, 0, N_("JPEG Basic")}, |
| 2494 | {PTP_DPC_CompressionSetting, 1, N_("JPEG Norm")}, |
| 2495 | {PTP_DPC_CompressionSetting, 2, N_("JPEG Fine")}, |
| 2496 | {PTP_DPC_CompressionSetting, 4, N_("RAW")}, |
| 2497 | {PTP_DPC_CompressionSetting, 5, N_("RAW + JPEG Basic")}, |
| 2498 | {PTP_DPC_WhiteBalance, 2, N_("Auto")}, |
| 2499 | {PTP_DPC_WhiteBalance, 6, N_("Incandescent")}, |
| 2500 | {PTP_DPC_WhiteBalance, 5, N_("Fluorescent")}, |
| 2501 | {PTP_DPC_WhiteBalance, 4, N_("Daylight")}, |
| 2502 | {PTP_DPC_WhiteBalance, 7, N_("Flash")}, |
| 2503 | {PTP_DPC_WhiteBalance, 32784, N_("Cloudy")}, |
| 2504 | {PTP_DPC_WhiteBalance, 32785, N_("Shade")}, |
| 2505 | {PTP_DPC_WhiteBalance, 32787, N_("Preset")}, |
| 2506 | {PTP_DPC_FlashMode, 32784, N_("Default")}, |
| 2507 | {PTP_DPC_FlashMode, 4, N_("Red-eye Reduction")}, |
| 2508 | {PTP_DPC_FlashMode, 32787, N_("Red-eye Reduction + Slow Sync")}, |
| 2509 | {PTP_DPC_FlashMode, 32785, N_("Slow Sync")}, |
| 2510 | {PTP_DPC_FlashMode, 32785, N_("Rear Curtain Sync + Slow Sync")}, |
| 2511 | {PTP_DPC_FocusMeteringMode, 2, N_("Dynamic Area")}, |
| 2512 | {PTP_DPC_FocusMeteringMode, 32784, N_("Single Area")}, |
| 2513 | {PTP_DPC_FocusMeteringMode, 32785, N_("Closest Subject")}, |
| 2514 | {PTP_DPC_FocusMode, 1, N_("Manual Focus")}, |
| 2515 | {PTP_DPC_FocusMode, 32784, "AF-S"}, |
| 2516 | {PTP_DPC_FocusMode, 32785, "AF-C"}, |
| 2517 | PTP_VAL_BOOL(PTP_DPC_NIKON_ISOAuto), |
| 2518 | PTP_VAL_BOOL(PTP_DPC_NIKON_ExposureCompensation), |
| 2519 | PTP_VAL_BOOL(PTP_DPC_NIKON_AELockMode), |
| 2520 | {PTP_DPC_NIKON_AELAFLMode, 0, N_("AE/AF Lock")}, |
| 2521 | {PTP_DPC_NIKON_AELAFLMode, 1, N_("AF Lock only")}, |
| 2522 | {PTP_DPC_NIKON_AELAFLMode, 2, N_("AE Lock only")}, |
| 2523 | {PTP_DPC_NIKON_AELAFLMode, 3, N_("AF Lock Hold")}, |
| 2524 | {PTP_DPC_NIKON_AELAFLMode, 4, N_("AF On")}, |
| 2525 | {PTP_DPC_NIKON_AELAFLMode, 5, N_("Flash Lock")}, |
| 2526 | {PTP_DPC_ExposureMeteringMode, 2, N_("Center Weighted")}, |
| 2527 | {PTP_DPC_ExposureMeteringMode, 3, N_("Matrix")}, |
| 2528 | {PTP_DPC_ExposureMeteringMode, 4, N_("Spot")}, |
| 2529 | {PTP_DPC_ExposureProgramMode, 1, "M"}, |
| 2530 | {PTP_DPC_ExposureProgramMode, 3, "A"}, |
| 2531 | {PTP_DPC_ExposureProgramMode, 4, "S"}, |
| 2532 | {PTP_DPC_ExposureProgramMode, 2, "P"}, |
| 2533 | {PTP_DPC_ExposureProgramMode, 32784, N_("Auto")}, |
| 2534 | {PTP_DPC_ExposureProgramMode, 32785, N_("Portrait")}, |
| 2535 | {PTP_DPC_ExposureProgramMode, 32786, N_("Landscape")}, |
| 2536 | {PTP_DPC_ExposureProgramMode, 32787, N_("Macro")}, |
| 2537 | {PTP_DPC_ExposureProgramMode, 32788, N_("Sports")}, |
| 2538 | {PTP_DPC_ExposureProgramMode, 32790, N_("Night Landscape")}, |
| 2539 | {PTP_DPC_ExposureProgramMode, 32789, N_("Night Portrait")}, |
| 2540 | {PTP_DPC_StillCaptureMode, 1, N_("Single Shot")}, |
| 2541 | {PTP_DPC_StillCaptureMode, 2, N_("Power Wind")}, |
| 2542 | {PTP_DPC_StillCaptureMode, 32785, N_("Timer")}, |
| 2543 | {PTP_DPC_StillCaptureMode, 32787, N_("Remote")}, |
| 2544 | {PTP_DPC_StillCaptureMode, 32788, N_("Timer + Remote")}, |
| 2545 | PTP_VAL_BOOL(PTP_DPC_NIKON_AutofocusMode), |
| 2546 | PTP_VAL_RBOOL(PTP_DPC_NIKON_AFAssist), |
| 2547 | PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageReview), |
| 2548 | PTP_VAL_BOOL(PTP_DPC_NIKON_GridDisplay), |
| 2549 | {PTP_DPC_NIKON_AFAreaIllumination, 0, N_("Auto")}, |
| 2550 | {PTP_DPC_NIKON_AFAreaIllumination, 1, N_("Off")}, |
| 2551 | {PTP_DPC_NIKON_AFAreaIllumination, 2, N_("On")}, |
| 2552 | {PTP_DPC_NIKON_ColorModel, 0, "sRGB"}, |
| 2553 | {PTP_DPC_NIKON_ColorModel, 1, "AdobeRGB"}, |
| 2554 | {PTP_DPC_NIKON_ColorModel, 2, "sRGB"}, |
| 2555 | {PTP_DPC_NIKON_FlashMode, 0, "iTTL"}, |
| 2556 | {PTP_DPC_NIKON_FlashMode, 1, N_("Manual")}, |
| 2557 | {PTP_DPC_NIKON_FlashMode, 2, N_("Commander")}, |
| 2558 | {PTP_DPC_NIKON_FlashModeManualPower, 0, N_("Full")}, |
| 2559 | {PTP_DPC_NIKON_FlashModeManualPower, 1, "1/2"}, |
| 2560 | {PTP_DPC_NIKON_FlashModeManualPower, 2, "1/4"}, |
| 2561 | {PTP_DPC_NIKON_FlashModeManualPower, 3, "1/8"}, |
| 2562 | {PTP_DPC_NIKON_FlashModeManualPower, 4, "1/16"}, |
| 2563 | PTP_VAL_RBOOL(PTP_DPC_NIKON_FlashSign), |
| 2564 | {PTP_DPC_NIKON_RemoteTimeout, 0, N_("1 min")}, |
| 2565 | {PTP_DPC_NIKON_RemoteTimeout, 1, N_("5 mins")}, |
| 2566 | {PTP_DPC_NIKON_RemoteTimeout, 2, N_("10 mins")}, |
| 2567 | {PTP_DPC_NIKON_RemoteTimeout, 3, N_("15 mins")}, |
| 2568 | PTP_VAL_YN(PTP_DPC_NIKON_FlashOpen), |
| 2569 | PTP_VAL_YN(PTP_DPC_NIKON_FlashCharged), |
| 2570 | PTP_VAL_BOOL(PTP_DPC_NIKON_LongExposureNoiseReduction), |
| 2571 | PTP_VAL_BOOL(PTP_DPC_NIKON_FileNumberSequence), |
| 2572 | PTP_VAL_BOOL(PTP_DPC_NIKON_ReverseCommandDial), |
| 2573 | PTP_VAL_RBOOL(PTP_DPC_NIKON_NoCFCard), |
| 2574 | PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageRotation), |
| 2575 | PTP_VAL_BOOL(PTP_DPC_NIKON_Bracketing), |
| 2576 | {PTP_DPC_NIKON_AutofocusArea, 0, N_("Centre")}, |
| 2577 | {PTP_DPC_NIKON_AutofocusArea, 1, N_("Top")}, |
| 2578 | {PTP_DPC_NIKON_AutofocusArea, 2, N_("Bottom")}, |
| 2579 | {PTP_DPC_NIKON_AutofocusArea, 3, N_("Left")}, |
| 2580 | {PTP_DPC_NIKON_AutofocusArea, 4, N_("Right")}, |
| 2581 | {PTP_DPC_NIKON_OptimizeImage, 0, N_("Normal")}, |
| 2582 | {PTP_DPC_NIKON_OptimizeImage, 1, N_("Vivid")}, |
| 2583 | {PTP_DPC_NIKON_OptimizeImage, 2, N_("Sharper")}, |
| 2584 | {PTP_DPC_NIKON_OptimizeImage, 3, N_("Softer")}, |
| 2585 | {PTP_DPC_NIKON_OptimizeImage, 4, N_("Direct Print")}, |
| 2586 | {PTP_DPC_NIKON_OptimizeImage, 5, N_("Portrait")}, |
| 2587 | {PTP_DPC_NIKON_OptimizeImage, 6, N_("Landscape")}, |
| 2588 | {PTP_DPC_NIKON_OptimizeImage, 7, N_("Custom")}, |
| 2589 | |
| 2590 | {PTP_DPC_NIKON_ImageSharpening, 0, N_("Auto")}, |
| 2591 | {PTP_DPC_NIKON_ImageSharpening, 1, N_("Normal")}, |
| 2592 | {PTP_DPC_NIKON_ImageSharpening, 2, N_("Low")}, |
| 2593 | {PTP_DPC_NIKON_ImageSharpening, 3, N_("Medium Low")}, |
| 2594 | {PTP_DPC_NIKON_ImageSharpening, 4, N_("Medium high")}, |
| 2595 | {PTP_DPC_NIKON_ImageSharpening, 5, N_("High")}, |
| 2596 | {PTP_DPC_NIKON_ImageSharpening, 6, N_("None")}, |
| 2597 | |
| 2598 | {PTP_DPC_NIKON_ToneCompensation, 0, N_("Auto")}, |
| 2599 | {PTP_DPC_NIKON_ToneCompensation, 1, N_("Normal")}, |
| 2600 | {PTP_DPC_NIKON_ToneCompensation, 2, N_("Low contrast")}, |
| 2601 | {PTP_DPC_NIKON_ToneCompensation, 3, N_("Medium low")}, |
| 2602 | {PTP_DPC_NIKON_ToneCompensation, 4, N_("Medium high")}, |
| 2603 | {PTP_DPC_NIKON_ToneCompensation, 5, N_("High control")}, |
| 2604 | {PTP_DPC_NIKON_ToneCompensation, 6, N_("Custom")}, |
| 2605 | |
| 2606 | {PTP_DPC_NIKON_Saturation, 0, N_("Normal")}, |
| 2607 | {PTP_DPC_NIKON_Saturation, 1, N_("Moderate")}, |
| 2608 | {PTP_DPC_NIKON_Saturation, 2, N_("Enhanced")}, |
| 2609 | |
| 2610 | {PTP_DPC_NIKON_LensID, 0, N_("Unknown")}, |
| 2611 | {PTP_DPC_NIKON_LensID, 38, "Sigma 70-300mm 1:4-5.6 D APO Macro"}, |
| 2612 | {PTP_DPC_NIKON_LensID, 83, "AF Nikkor 80-200mm 1:2.8 D ED"}, |
| 2613 | {PTP_DPC_NIKON_LensID, 118, "AF Nikkor 50mm 1:1.8 D"}, |
| 2614 | {PTP_DPC_NIKON_LensID, 127, "AF-S Nikkor 18-70mm 1:3.5-4.5G ED DX"}, |
| 2615 | PTP_VAL_YN(PTP_DPC_NIKON_LowLight), |
| 2616 | PTP_VAL_YN(PTP_DPC_NIKON_CSMMenu), |
| 2617 | PTP_VAL_RBOOL(PTP_DPC_NIKON_BeepOff), |
| 2618 | {0, 0, NULL} |
| 2619 | }; |
| 2620 | |
| 2621 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON) { |
| 2622 | int64_t kval; |
| 2623 | |
| 2624 | for (i=0; ptp_value_trans[i].dpc!=0; i++) |
| 2625 | if (ptp_value_trans[i].dpc==dpc) { |
| 2626 | double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 2627 | |
| 2628 | return snprintf(out, length, |
| 2629 | _(ptp_value_trans[i].format), |
| 2630 | value * ptp_value_trans[i].coef + |
| 2631 | ptp_value_trans[i].bias); |
| 2632 | } |
| 2633 | |
| 2634 | for (i=0; ptp_value_trans_Nikon[i].dpc!=0; i++) |
| 2635 | if (ptp_value_trans_Nikon[i].dpc==dpc) { |
| 2636 | double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 2637 | |
| 2638 | return snprintf(out, length, |
| 2639 | _(ptp_value_trans_Nikon[i].format), |
| 2640 | value * ptp_value_trans_Nikon[i].coef + |
| 2641 | ptp_value_trans_Nikon[i].bias); |
| 2642 | } |
| 2643 | |
| 2644 | kval = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 2645 | |
| 2646 | for (i=0; ptp_value_list_Nikon[i].dpc!=0; i++) |
| 2647 | if (ptp_value_list_Nikon[i].dpc==dpc && |
| 2648 | ptp_value_list_Nikon[i].key==kval) |
| 2649 | return snprintf(out, length, "%s", |
| 2650 | _(ptp_value_list_Nikon[i].value)); |
| 2651 | } |
| 2652 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT) { |
| 2653 | switch (dpc) { |
| 2654 | case PTP_DPC_MTP_Synchronization_Partner: |
| 2655 | case PTP_DPC_MTP_Device_Friendly_Name: |
| 2656 | return snprintf(out, length, "%s", dpd->CurrentValue.str); |
| 2657 | case 0xd101: |
| 2658 | case 0xd102: { |
| 2659 | for (i=0;(i<dpd->CurrentValue.a.count) && (i<length);i++) |
| 2660 | out[i] = dpd->CurrentValue.a.v[i].u16; |
| 2661 | if ( dpd->CurrentValue.a.count && |
| 2662 | (dpd->CurrentValue.a.count < length)) { |
| 2663 | out[dpd->CurrentValue.a.count-1] = 0; |
| 2664 | return dpd->CurrentValue.a.count-1; |
| 2665 | } else { |
| 2666 | out[length-1] = 0; |
| 2667 | return length; |
| 2668 | } |
| 2669 | break; |
| 2670 | } |
| 2671 | default: |
| 2672 | break; |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | return 0; |
| 2677 | } |
| 2678 | |
| 2679 | struct { |
| 2680 | uint16_t ofc; |
| 2681 | const char *format; |
| 2682 | } ptp_ofc_trans[] = { |
| 2683 | {PTP_OFC_Undefined,"Undefined Type"}, |
| 2684 | {PTP_OFC_Association,"Association/Directory"}, |
| 2685 | {PTP_OFC_Script,"Script"}, |
| 2686 | {PTP_OFC_Executable,"Executable"}, |
| 2687 | {PTP_OFC_Text,"Text"}, |
| 2688 | {PTP_OFC_HTML,"HTML"}, |
| 2689 | {PTP_OFC_DPOF,"DPOF"}, |
| 2690 | {PTP_OFC_AIFF,"AIFF"}, |
| 2691 | {PTP_OFC_WAV,"MS Wave"}, |
| 2692 | {PTP_OFC_MP3,"MP3"}, |
| 2693 | {PTP_OFC_AVI,"MS AVI"}, |
| 2694 | {PTP_OFC_MPEG,"MPEG"}, |
| 2695 | {PTP_OFC_ASF,"ASF"}, |
| 2696 | {PTP_OFC_QT,"Apple Quicktime"}, |
| 2697 | {PTP_OFC_EXIF_JPEG,"JPEG"}, |
| 2698 | {PTP_OFC_TIFF_EP,"TIFF EP"}, |
| 2699 | {PTP_OFC_FlashPix,"FlashPix"}, |
| 2700 | {PTP_OFC_BMP,"BMP"}, |
| 2701 | {PTP_OFC_CIFF,"CIFF"}, |
| 2702 | {PTP_OFC_GIF,"GIF"}, |
| 2703 | {PTP_OFC_JFIF,"JFIF"}, |
| 2704 | {PTP_OFC_PCD,"PCD"}, |
| 2705 | {PTP_OFC_PICT,"PICT"}, |
| 2706 | {PTP_OFC_PNG,"PNG"}, |
| 2707 | {PTP_OFC_TIFF,"TIFF"}, |
| 2708 | {PTP_OFC_TIFF_IT,"TIFF_IT"}, |
| 2709 | {PTP_OFC_JP2,"JP2"}, |
| 2710 | {PTP_OFC_JPX,"JPX"}, |
| 2711 | }; |
| 2712 | |
| 2713 | struct { |
| 2714 | uint16_t ofc; |
| 2715 | const char *format; |
| 2716 | } ptp_ofc_mtp_trans[] = { |
| 2717 | {PTP_OFC_MTP_Firmware,N_("Firmware")}, |
| 2718 | {PTP_OFC_MTP_WindowsImageFormat,N_("WindowsImageFormat")}, |
| 2719 | {PTP_OFC_MTP_UndefinedAudio,N_("Undefined Audio")}, |
| 2720 | {PTP_OFC_MTP_WMA,"WMA"}, |
| 2721 | {PTP_OFC_MTP_OGG,"OGG"}, |
| 2722 | {PTP_OFC_MTP_UndefinedVideo,N_("Undefined Video")}, |
| 2723 | {PTP_OFC_MTP_WMV,"WMV"}, |
| 2724 | {PTP_OFC_MTP_MP4,"MP4"}, |
| 2725 | {PTP_OFC_MTP_UndefinedCollection,N_("Undefined Collection")}, |
| 2726 | {PTP_OFC_MTP_AbstractMultimediaAlbum,N_("Abstract Multimedia Album")}, |
| 2727 | {PTP_OFC_MTP_AbstractImageAlbum,N_("Abstract Image Album")}, |
| 2728 | {PTP_OFC_MTP_AbstractAudioAlbum,N_("Abstract Audio Album")}, |
| 2729 | {PTP_OFC_MTP_AbstractVideoAlbum,N_("Abstract Video Album")}, |
| 2730 | {PTP_OFC_MTP_AbstractAudioVideoPlaylist,N_("Abstract Audio Video Playlist")}, |
| 2731 | {PTP_OFC_MTP_AbstractContactGroup,N_("Abstract Contact Group")}, |
| 2732 | {PTP_OFC_MTP_AbstractMessageFolder,N_("Abstract Message Folder")}, |
| 2733 | {PTP_OFC_MTP_AbstractChapteredProduction,N_("Abstract Chaptered Production")}, |
| 2734 | {PTP_OFC_MTP_WPLPlaylist,N_("WPL Playlist")}, |
| 2735 | {PTP_OFC_MTP_M3UPlaylist,N_("M3U Playlist")}, |
| 2736 | {PTP_OFC_MTP_MPLPlaylist,N_("MPL Playlist")}, |
| 2737 | {PTP_OFC_MTP_ASXPlaylist,N_("ASX Playlist")}, |
| 2738 | {PTP_OFC_MTP_PLSPlaylist,N_("PLS Playlist")}, |
| 2739 | {PTP_OFC_MTP_UndefinedDocument,N_("UndefinedDocument")}, |
| 2740 | {PTP_OFC_MTP_AbstractDocument,N_("AbstractDocument")}, |
| 2741 | {PTP_OFC_MTP_UndefinedMessage,N_("UndefinedMessage")}, |
| 2742 | {PTP_OFC_MTP_AbstractMessage,N_("AbstractMessage")}, |
| 2743 | {PTP_OFC_MTP_UndefinedContact,N_("UndefinedContact")}, |
| 2744 | {PTP_OFC_MTP_AbstractContact,N_("AbstractContact")}, |
| 2745 | {PTP_OFC_MTP_vCard2,N_("vCard2")}, |
| 2746 | {PTP_OFC_MTP_vCard3,N_("vCard3")}, |
| 2747 | {PTP_OFC_MTP_UndefinedCalendarItem,N_("UndefinedCalendarItem")}, |
| 2748 | {PTP_OFC_MTP_AbstractCalendarItem,N_("AbstractCalendarItem")}, |
| 2749 | {PTP_OFC_MTP_vCalendar1,N_("vCalendar1")}, |
| 2750 | {PTP_OFC_MTP_vCalendar2,N_("vCalendar2")}, |
| 2751 | {PTP_OFC_MTP_UndefinedWindowsExecutable,N_("Undefined Windows Executable")}, |
| 2752 | }; |
| 2753 | |
| 2754 | int |
| 2755 | ptp_render_ofc(PTPParams* params, uint16_t ofc, int spaceleft, char *txt) |
| 2756 | { |
| 2757 | int i; |
| 2758 | |
| 2759 | if (!(ofc & 0x8000)) { |
| 2760 | for (i=0;i<sizeof(ptp_ofc_trans)/sizeof(ptp_ofc_trans[0]);i++) |
| 2761 | if (ofc == ptp_ofc_trans[i].ofc) |
| 2762 | return snprintf(txt, spaceleft,_(ptp_ofc_trans[i].format)); |
| 2763 | } else { |
| 2764 | switch (params->deviceinfo.VendorExtensionID) { |
| 2765 | case PTP_VENDOR_EASTMAN_KODAK: |
| 2766 | switch (ofc) { |
| 2767 | case PTP_OFC_EK_M3U: |
| 2768 | return snprintf (txt, spaceleft,_("M3U")); |
| 2769 | default: |
| 2770 | break; |
| 2771 | } |
| 2772 | break; |
| 2773 | case PTP_VENDOR_MICROSOFT: |
| 2774 | for (i=0;i<sizeof(ptp_ofc_mtp_trans)/sizeof(ptp_ofc_mtp_trans[0]);i++) |
| 2775 | if (ofc == ptp_ofc_mtp_trans[i].ofc) |
| 2776 | return snprintf(txt, spaceleft,_(ptp_ofc_mtp_trans[i].format)); |
| 2777 | break; |
| 2778 | default:break; |
| 2779 | } |
| 2780 | } |
| 2781 | return snprintf (txt, spaceleft,_("Unknown(%04x)"), ofc); |
| 2782 | } |
| 2783 | |
| 2784 | struct { |
| 2785 | uint16_t id; |
| 2786 | const char *name; |
| 2787 | } ptp_opc_trans[] = { |
| 2788 | {PTP_OPC_StorageID,"StorageID"}, |
| 2789 | {PTP_OPC_ObjectFormat,"ObjectFormat"}, |
| 2790 | {PTP_OPC_ProtectionStatus,"ProtectionStatus"}, |
| 2791 | {PTP_OPC_ObjectSize,"ObjectSize"}, |
| 2792 | {PTP_OPC_AssociationType,"AssociationType"}, |
| 2793 | {PTP_OPC_AssociationDesc,"AssociationDesc"}, |
| 2794 | {PTP_OPC_ObjectFileName,"ObjectFileName"}, |
| 2795 | {PTP_OPC_DateCreated,"DateCreated"}, |
| 2796 | {PTP_OPC_DateModified,"DateModified"}, |
| 2797 | {PTP_OPC_Keywords,"Keywords"}, |
| 2798 | {PTP_OPC_ParentObject,"ParentObject"}, |
| 2799 | {PTP_OPC_PersistantUniqueObjectIdentifier,"PersistantUniqueObjectIdentifier"}, |
| 2800 | {PTP_OPC_SyncID,"SyncID"}, |
| 2801 | {PTP_OPC_PropertyBag,"PropertyBag"}, |
| 2802 | {PTP_OPC_Name,"Name"}, |
| 2803 | {PTP_OPC_CreatedBy,"CreatedBy"}, |
| 2804 | {PTP_OPC_Artist,"Artist"}, |
| 2805 | {PTP_OPC_DateAuthored,"DateAuthored"}, |
| 2806 | {PTP_OPC_Description,"Description"}, |
| 2807 | {PTP_OPC_URLReference,"URLReference"}, |
| 2808 | {PTP_OPC_LanguageLocale,"LanguageLocale"}, |
| 2809 | {PTP_OPC_CopyrightInformation,"CopyrightInformation"}, |
| 2810 | {PTP_OPC_Source,"Source"}, |
| 2811 | {PTP_OPC_OriginLocation,"OriginLocation"}, |
| 2812 | {PTP_OPC_DateAdded,"DateAdded"}, |
| 2813 | {PTP_OPC_NonConsumable,"NonConsumable"}, |
| 2814 | {PTP_OPC_CorruptOrUnplayable,"CorruptOrUnplayable"}, |
| 2815 | {PTP_OPC_RepresentativeSampleFormat,"RepresentativeSampleFormat"}, |
| 2816 | {PTP_OPC_RepresentativeSampleSize,"RepresentativeSampleSize"}, |
| 2817 | {PTP_OPC_RepresentativeSampleHeight,"RepresentativeSampleHeight"}, |
| 2818 | {PTP_OPC_RepresentativeSampleWidth,"RepresentativeSampleWidth"}, |
| 2819 | {PTP_OPC_RepresentativeSampleDuration,"RepresentativeSampleDuration"}, |
| 2820 | {PTP_OPC_RepresentativeSampleData,"RepresentativeSampleData"}, |
| 2821 | {PTP_OPC_Width,"Width"}, |
| 2822 | {PTP_OPC_Height,"Height"}, |
| 2823 | {PTP_OPC_Duration,"Duration"}, |
| 2824 | {PTP_OPC_Rating,"Rating"}, |
| 2825 | {PTP_OPC_Track,"Track"}, |
| 2826 | {PTP_OPC_Genre,"Genre"}, |
| 2827 | {PTP_OPC_Credits,"Credits"}, |
| 2828 | {PTP_OPC_Lyrics,"Lyrics"}, |
| 2829 | {PTP_OPC_SubscriptionContentID,"SubscriptionContentID"}, |
| 2830 | {PTP_OPC_ProducedBy,"ProducedBy"}, |
| 2831 | {PTP_OPC_UseCount,"UseCount"}, |
| 2832 | {PTP_OPC_SkipCount,"SkipCount"}, |
| 2833 | {PTP_OPC_LastAccessed,"LastAccessed"}, |
| 2834 | {PTP_OPC_ParentalRating,"ParentalRating"}, |
| 2835 | {PTP_OPC_MetaGenre,"MetaGenre"}, |
| 2836 | {PTP_OPC_Composer,"Composer"}, |
| 2837 | {PTP_OPC_EffectiveRating,"EffectiveRating"}, |
| 2838 | {PTP_OPC_Subtitle,"Subtitle"}, |
| 2839 | {PTP_OPC_OriginalReleaseDate,"OriginalReleaseDate"}, |
| 2840 | {PTP_OPC_AlbumName,"AlbumName"}, |
| 2841 | {PTP_OPC_AlbumArtist,"AlbumArtist"}, |
| 2842 | {PTP_OPC_Mood,"Mood"}, |
| 2843 | {PTP_OPC_DRMStatus,"DRMStatus"}, |
| 2844 | {PTP_OPC_SubDescription,"SubDescription"}, |
| 2845 | {PTP_OPC_IsCropped,"IsCropped"}, |
| 2846 | {PTP_OPC_IsColorCorrected,"IsColorCorrected"}, |
| 2847 | {PTP_OPC_TotalBitRate,"TotalBitRate"}, |
| 2848 | {PTP_OPC_BitRateType,"BitRateType"}, |
| 2849 | {PTP_OPC_SampleRate,"SampleRate"}, |
| 2850 | {PTP_OPC_NumberOfChannels,"NumberOfChannels"}, |
| 2851 | {PTP_OPC_AudioBitDepth,"AudioBitDepth"}, |
| 2852 | {PTP_OPC_ScanDepth,"ScanDepth"}, |
| 2853 | {PTP_OPC_AudioWAVECodec,"AudioWAVECodec"}, |
| 2854 | {PTP_OPC_AudioBitRate,"AudioBitRate"}, |
| 2855 | {PTP_OPC_VideoFourCCCodec,"VideoFourCCCodec"}, |
| 2856 | {PTP_OPC_VideoBitRate,"VideoBitRate"}, |
| 2857 | {PTP_OPC_FramesPerThousandSeconds,"FramesPerThousandSeconds"}, |
| 2858 | {PTP_OPC_KeyFrameDistance,"KeyFrameDistance"}, |
| 2859 | {PTP_OPC_BufferSize,"BufferSize"}, |
| 2860 | {PTP_OPC_EncodingQuality,"EncodingQuality"}, |
| 2861 | }; |
| 2862 | |
| 2863 | int |
| 2864 | ptp_render_mtp_propname(uint16_t propid, int spaceleft, char *txt) { |
| 2865 | int i; |
| 2866 | for (i=0;i<sizeof(ptp_opc_trans)/sizeof(ptp_opc_trans[0]);i++) |
| 2867 | if (propid == ptp_opc_trans[i].id) |
| 2868 | return snprintf(txt, spaceleft,ptp_opc_trans[i].name); |
| 2869 | return snprintf (txt, spaceleft,"unknown(%04x)", propid); |
| 2870 | } |