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 | a823a70 | 2006-08-27 21:27:46 +0000 | [diff] [blame] | 5 | * Copyright (C) 2006 Linus Walleij <triad@df.lth.se> |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 6 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 11 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 16 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <config.h> |
| 24 | #include "ptp.h" |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 25 | |
| 26 | #include <stdlib.h> |
| 27 | #include <stdarg.h> |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 30 | #include <unistd.h> |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef ENABLE_NLS |
| 33 | # include <libintl.h> |
| 34 | # undef _ |
| 35 | # define _(String) dgettext (PACKAGE, String) |
| 36 | # ifdef gettext_noop |
| 37 | # define N_(String) gettext_noop (String) |
| 38 | # else |
| 39 | # define N_(String) (String) |
| 40 | # endif |
| 41 | #else |
| 42 | # define textdomain(String) (String) |
| 43 | # define gettext(String) (String) |
| 44 | # define dgettext(Domain,Message) (Message) |
| 45 | # define dcgettext(Domain,Message,Type) (Message) |
| 46 | # define bindtextdomain(Domain,Directory) (Domain) |
| 47 | # define _(String) (String) |
| 48 | # define N_(String) (String) |
| 49 | #endif |
| 50 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 51 | #define CHECK_PTP_RC(result) {uint16_t r=(result); if (r!=PTP_RC_OK) return r;} |
| 52 | |
| 53 | #define PTP_CNT_INIT(cnt) {memset(&cnt,0,sizeof(cnt));} |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 54 | |
| 55 | static void |
| 56 | ptp_debug (PTPParams *params, const char *format, ...) |
| 57 | { |
| 58 | va_list args; |
| 59 | |
| 60 | va_start (args, format); |
| 61 | if (params->debug_func!=NULL) |
| 62 | params->debug_func (params->data, format, args); |
| 63 | else |
| 64 | { |
| 65 | vfprintf (stderr, format, args); |
| 66 | fprintf (stderr,"\n"); |
| 67 | fflush (stderr); |
| 68 | } |
| 69 | va_end (args); |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | ptp_error (PTPParams *params, const char *format, ...) |
| 74 | { |
| 75 | va_list args; |
| 76 | |
| 77 | va_start (args, format); |
| 78 | if (params->error_func!=NULL) |
| 79 | params->error_func (params->data, format, args); |
| 80 | else |
| 81 | { |
| 82 | vfprintf (stderr, format, args); |
| 83 | fprintf (stderr,"\n"); |
| 84 | fflush (stderr); |
| 85 | } |
| 86 | va_end (args); |
| 87 | } |
| 88 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 89 | /* Pack / unpack functions */ |
| 90 | |
| 91 | #include "ptp-pack.c" |
| 92 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 93 | /* send / receive functions */ |
| 94 | |
| 95 | uint16_t |
| 96 | ptp_usb_sendreq (PTPParams* params, PTPContainer* req) |
| 97 | { |
| 98 | uint16_t ret; |
| 99 | PTPUSBBulkContainer usbreq; |
| 100 | |
| 101 | /* build appropriate USB container */ |
| 102 | usbreq.length=htod32(PTP_USB_BULK_REQ_LEN- |
| 103 | (sizeof(uint32_t)*(5-req->Nparam))); |
| 104 | usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND); |
| 105 | usbreq.code=htod16(req->Code); |
| 106 | usbreq.trans_id=htod32(req->Transaction_ID); |
| 107 | usbreq.payload.params.param1=htod32(req->Param1); |
| 108 | usbreq.payload.params.param2=htod32(req->Param2); |
| 109 | usbreq.payload.params.param3=htod32(req->Param3); |
| 110 | usbreq.payload.params.param4=htod32(req->Param4); |
| 111 | usbreq.payload.params.param5=htod32(req->Param5); |
| 112 | /* send it to responder */ |
| 113 | ret=params->write_func((unsigned char *)&usbreq, |
| 114 | PTP_USB_BULK_REQ_LEN-(sizeof(uint32_t)*(5-req->Nparam)), |
| 115 | params->data); |
| 116 | if (ret!=PTP_RC_OK) { |
| 117 | ret = PTP_ERROR_IO; |
| 118 | /* ptp_error (params, |
| 119 | "PTP: request code 0x%04x sending req error 0x%04x", |
| 120 | req->Code,ret); */ |
| 121 | } |
| 122 | return ret; |
| 123 | } |
| 124 | |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 125 | /* Used for file transactions */ |
| 126 | #define FILE_BUFFER_SIZE 0x10000 |
| 127 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 128 | uint16_t |
| 129 | ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 130 | unsigned char *data, unsigned int size, |
| 131 | int from_fd) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 132 | { |
| 133 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 134 | int wlen, datawlen; |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 135 | size_t written; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 136 | PTPUSBBulkContainer usbdata; |
| 137 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 138 | /* build appropriate USB container */ |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 139 | usbdata.length = htod32(PTP_USB_BULK_HDR_LEN+size); |
| 140 | usbdata.type = htod16(PTP_USB_CONTAINER_DATA); |
| 141 | usbdata.code = htod16(ptp->Code); |
| 142 | usbdata.trans_id= htod32(ptp->Transaction_ID); |
| 143 | |
| 144 | if (params->split_header_data) { |
| 145 | datawlen = 0; |
| 146 | wlen = PTP_USB_BULK_HDR_LEN; |
| 147 | } else { |
| 148 | /* For all camera devices. */ |
| 149 | datawlen = (size<PTP_USB_BULK_PAYLOAD_LEN)?size:PTP_USB_BULK_PAYLOAD_LEN; |
| 150 | wlen = PTP_USB_BULK_HDR_LEN + datawlen; |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 151 | if (from_fd == -1) { |
| 152 | memcpy(usbdata.payload.data, data, datawlen); |
| 153 | } else { |
| 154 | written = read(from_fd, usbdata.payload.data, datawlen); |
| 155 | if (written != datawlen) |
| 156 | return PTP_ERROR_IO; |
| 157 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 158 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 159 | /* send first part of data */ |
| 160 | ret = params->write_func((unsigned char *)&usbdata, wlen, params->data); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 161 | if (ret!=PTP_RC_OK) { |
| 162 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 163 | /* ptp_error (params, |
| 164 | "PTP: request code 0x%04x sending data error 0x%04x", |
| 165 | ptp->Code,ret);*/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 166 | return ret; |
| 167 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 168 | if (size <= datawlen) return ret; |
| 169 | /* if everything OK send the rest */ |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 170 | if (from_fd == -1) { |
| 171 | ret=params->write_func (data + datawlen, size - datawlen, params->data); |
| 172 | } else { |
| 173 | uint32_t bytes_to_transfer; |
| 174 | uint32_t bytes_left_to_transfer; |
| 175 | void *temp_buf; |
| 176 | |
| 177 | written = 0; |
| 178 | bytes_left_to_transfer = size-datawlen; |
| 179 | |
| 180 | temp_buf = malloc(FILE_BUFFER_SIZE); |
| 181 | if (temp_buf == NULL) |
| 182 | return PTP_ERROR_IO; |
| 183 | |
| 184 | ret = PTP_RC_OK; |
| 185 | while(bytes_left_to_transfer > 0) { |
| 186 | if (bytes_left_to_transfer > FILE_BUFFER_SIZE) { |
| 187 | bytes_to_transfer = FILE_BUFFER_SIZE; |
| 188 | } else { |
| 189 | bytes_to_transfer = bytes_left_to_transfer; |
| 190 | } |
| 191 | written = read(from_fd, temp_buf, bytes_to_transfer); |
| 192 | if (written != bytes_to_transfer) { |
| 193 | ret = PTP_ERROR_IO; |
| 194 | break; |
| 195 | } |
| 196 | ret=params->write_func (temp_buf, bytes_to_transfer, params->data); |
| 197 | bytes_left_to_transfer -= bytes_to_transfer; |
| 198 | } |
| 199 | free(temp_buf); |
| 200 | |
| 201 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 202 | if (ret!=PTP_RC_OK) { |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 203 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 204 | /* ptp_error (params, |
| 205 | "PTP: request code 0x%04x sending data error 0x%04x", |
| 206 | ptp->Code,ret); */ |
| 207 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 208 | return ret; |
| 209 | } |
| 210 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 211 | uint16_t |
| 212 | ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 213 | unsigned char **data, unsigned int *readlen, |
| 214 | int to_fd) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 215 | { |
| 216 | uint16_t ret; |
| 217 | PTPUSBBulkContainer usbdata; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 218 | |
| 219 | PTP_CNT_INIT(usbdata); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 220 | |
| 221 | if (to_fd == -1 && *data != NULL) |
| 222 | return PTP_ERROR_BADPARAM; |
| 223 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 224 | do { |
| 225 | unsigned int len, rlen; |
| 226 | /* read the header and potentially the first data */ |
| 227 | ret=params->read_func((unsigned char *)&usbdata, |
| 228 | sizeof(usbdata), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 229 | if (ret!=PTP_RC_OK) { |
| 230 | ret = PTP_ERROR_IO; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 231 | break; |
| 232 | } else |
| 233 | if (dtoh16(usbdata.type)!=PTP_USB_CONTAINER_DATA) { |
| 234 | ret = PTP_ERROR_DATA_EXPECTED; |
| 235 | break; |
| 236 | } else |
| 237 | if (dtoh16(usbdata.code)!=ptp->Code) { |
| 238 | ret = dtoh16(usbdata.code); |
| 239 | break; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 240 | } |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 241 | if (usbdata.length == 0xffffffffU) { |
| 242 | /* This only happens for MTP_GetObjPropList */ |
| 243 | uint32_t tsize = PTP_USB_BULK_HS_MAX_PACKET_LEN; |
| 244 | unsigned char *tdata = malloc(tsize); |
| 245 | uint32_t curoff = 0; |
| 246 | |
| 247 | while (1) { |
| 248 | ret=params->read_func(tdata+curoff, |
| 249 | PTP_USB_BULK_HS_MAX_PACKET_LEN, params->data, &rlen); |
| 250 | if (ret!=PTP_RC_OK) { |
| 251 | ret = PTP_ERROR_IO; |
| 252 | break; |
| 253 | } |
| 254 | if (rlen < PTP_USB_BULK_HS_MAX_PACKET_LEN) { |
| 255 | tsize += rlen; |
| 256 | break; |
| 257 | } |
| 258 | tsize += PTP_USB_BULK_HS_MAX_PACKET_LEN; |
| 259 | curoff+= PTP_USB_BULK_HS_MAX_PACKET_LEN; |
| 260 | tdata = realloc(tdata, tsize); |
| 261 | } |
| 262 | if (to_fd == -1) { |
| 263 | *data = tdata; |
| 264 | } else { |
| 265 | write (to_fd, tdata, tsize); |
| 266 | free (tdata); |
| 267 | } |
| 268 | return PTP_RC_OK; |
| 269 | } |
Linus Walleij | c60275a | 2006-04-30 10:58:11 +0000 | [diff] [blame] | 270 | if (rlen > dtoh32(usbdata.length)) { |
| 271 | /* I observed this on iRiver MTP devices. -Marcus */ |
| 272 | ptp_debug (params, "ptp2/ptp_usb_getdata: read %d bytes too much, expect problems!", rlen - dtoh32(usbdata.length) |
| 273 | ); |
| 274 | rlen = dtoh32(usbdata.length); |
| 275 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 276 | |
| 277 | /* For most PTP devices rlen is 512 == sizeof(usbdata) |
| 278 | * here. For MTP devices splitting header and data it might |
| 279 | * be 12. |
| 280 | */ |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 281 | /* Evaluate full data length. */ |
| 282 | len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 283 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 284 | /* autodetect split header/data MTP devices */ |
| 285 | if (dtoh32(usbdata.length) > 12 && (rlen==12)) |
| 286 | params->split_header_data = 1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 287 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 288 | if (to_fd == -1) { |
| 289 | /* Allocate memory for data. */ |
| 290 | *data=calloc(len,1); |
| 291 | if (readlen) |
| 292 | *readlen = len; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 293 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 294 | /* Copy first part of data to 'data' */ |
| 295 | memcpy(*data,usbdata.payload.data,rlen - PTP_USB_BULK_HDR_LEN); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 296 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 297 | /* Is that all of data? */ |
| 298 | if (len+PTP_USB_BULK_HDR_LEN<=rlen) break; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 299 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 300 | /* If not read the rest of it. */ |
| 301 | ret=params->read_func(((unsigned char *)(*data))+ |
| 302 | rlen - PTP_USB_BULK_HDR_LEN, |
| 303 | len-(rlen - PTP_USB_BULK_HDR_LEN), |
| 304 | params->data, &rlen); |
| 305 | if (ret!=PTP_RC_OK) { |
| 306 | ret = PTP_ERROR_IO; |
| 307 | break; |
| 308 | } |
| 309 | } else { |
| 310 | uint32_t bytes_to_write, written; |
| 311 | uint32_t bytes_left_to_transfer; |
| 312 | void *temp_buf; |
| 313 | |
| 314 | if (readlen) |
| 315 | *readlen = len; |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 316 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 317 | bytes_to_write = rlen - PTP_USB_BULK_HDR_LEN; |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 318 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 319 | ret = write(to_fd, usbdata.payload.data, bytes_to_write); |
| 320 | if (ret != bytes_to_write) { |
| 321 | ret = PTP_ERROR_IO; |
| 322 | break; |
| 323 | } |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 324 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 325 | if (len + PTP_USB_BULK_HDR_LEN <= rlen) |
| 326 | break; |
| 327 | |
| 328 | temp_buf = malloc(FILE_BUFFER_SIZE); |
| 329 | if (temp_buf == NULL) { |
| 330 | ret = PTP_ERROR_IO; |
| 331 | break; |
| 332 | } |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 333 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 334 | ret = PTP_RC_OK; |
| 335 | bytes_left_to_transfer = len - (rlen - PTP_USB_BULK_HDR_LEN); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 336 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 337 | while (bytes_left_to_transfer > 0) { |
| 338 | bytes_to_write = ((bytes_left_to_transfer > FILE_BUFFER_SIZE) ? |
| 339 | FILE_BUFFER_SIZE : bytes_left_to_transfer); |
| 340 | |
| 341 | ret = params->read_func(temp_buf, |
| 342 | bytes_to_write, |
| 343 | params->data, &rlen); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 344 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 345 | if (ret != PTP_RC_OK) { |
| 346 | ret = PTP_ERROR_IO; |
| 347 | break; |
| 348 | } |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 349 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 350 | written = write(to_fd, temp_buf, bytes_to_write); |
| 351 | if (written != bytes_to_write) { |
| 352 | ret = PTP_ERROR_IO; |
| 353 | break; |
| 354 | } else { |
| 355 | ret = PTP_RC_OK; |
| 356 | } |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 357 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 358 | bytes_left_to_transfer -= bytes_to_write; |
| 359 | } |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 360 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 361 | free(temp_buf); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 362 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 363 | if (ret != PTP_RC_OK) |
| 364 | break; |
| 365 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 366 | } |
| 367 | } while (0); |
| 368 | /* |
| 369 | if (ret!=PTP_RC_OK) { |
| 370 | ptp_error (params, |
| 371 | "PTP: request code 0x%04x getting data error 0x%04x", |
| 372 | ptp->Code, ret); |
| 373 | }*/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 374 | return ret; |
| 375 | } |
| 376 | |
| 377 | uint16_t |
| 378 | ptp_usb_getresp (PTPParams* params, PTPContainer* resp) |
| 379 | { |
| 380 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 381 | unsigned int rlen; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 382 | PTPUSBBulkContainer usbresp; |
| 383 | |
| 384 | PTP_CNT_INIT(usbresp); |
| 385 | /* read response, it should never be longer than sizeof(usbresp) */ |
| 386 | ret=params->read_func((unsigned char *)&usbresp, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 387 | sizeof(usbresp), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 388 | |
| 389 | if (ret!=PTP_RC_OK) { |
| 390 | ret = PTP_ERROR_IO; |
| 391 | } else |
| 392 | if (dtoh16(usbresp.type)!=PTP_USB_CONTAINER_RESPONSE) { |
| 393 | ret = PTP_ERROR_RESP_EXPECTED; |
| 394 | } else |
| 395 | if (dtoh16(usbresp.code)!=resp->Code) { |
| 396 | ret = dtoh16(usbresp.code); |
| 397 | } |
| 398 | if (ret!=PTP_RC_OK) { |
| 399 | /* ptp_error (params, |
| 400 | "PTP: request code 0x%04x getting resp error 0x%04x", |
| 401 | resp->Code, ret);*/ |
| 402 | return ret; |
| 403 | } |
| 404 | /* build an appropriate PTPContainer */ |
| 405 | resp->Code=dtoh16(usbresp.code); |
| 406 | resp->SessionID=params->session_id; |
| 407 | resp->Transaction_ID=dtoh32(usbresp.trans_id); |
| 408 | resp->Param1=dtoh32(usbresp.payload.params.param1); |
| 409 | resp->Param2=dtoh32(usbresp.payload.params.param2); |
| 410 | resp->Param3=dtoh32(usbresp.payload.params.param3); |
| 411 | resp->Param4=dtoh32(usbresp.payload.params.param4); |
| 412 | resp->Param5=dtoh32(usbresp.payload.params.param5); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 413 | return ret; |
| 414 | } |
| 415 | |
| 416 | /* major PTP functions */ |
| 417 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 418 | /* Transaction data phase description */ |
| 419 | #define PTP_DP_NODATA 0x0000 /* no data phase */ |
| 420 | #define PTP_DP_SENDDATA 0x0001 /* sending data */ |
| 421 | #define PTP_DP_GETDATA 0x0002 /* receiving data */ |
| 422 | #define PTP_DP_DATA_MASK 0x00ff /* data phase mask */ |
| 423 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 424 | /** |
| 425 | * ptp_transaction: |
| 426 | * params: PTPParams* |
| 427 | * PTPContainer* ptp - general ptp container |
| 428 | * uint16_t flags - lower 8 bits - data phase description |
| 429 | * unsigned int sendlen - senddata phase data length |
| 430 | * char** data - send or receive data buffer pointer |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 431 | * int* recvlen - receive data length |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 432 | * |
| 433 | * Performs PTP transaction. ptp is a PTPContainer with appropriate fields |
| 434 | * filled in (i.e. operation code and parameters). It's up to caller to do |
| 435 | * so. |
| 436 | * The flags decide thether the transaction has a data phase and what is its |
| 437 | * direction (send or receive). |
| 438 | * If transaction is sending data the sendlen should contain its length in |
| 439 | * bytes, otherwise it's ignored. |
| 440 | * The data should contain an address of a pointer to data going to be sent |
| 441 | * or is filled with such a pointer address if data are received depending |
| 442 | * od dataphase direction (send or received) or is beeing ignored (no |
| 443 | * dataphase). |
| 444 | * The memory for a pointer should be preserved by the caller, if data are |
| 445 | * beeing retreived the appropriate amount of memory is beeing allocated |
| 446 | * (the caller should handle that!). |
| 447 | * |
| 448 | * Return values: Some PTP_RC_* code. |
| 449 | * Upon success PTPContainer* ptp contains PTP Response Phase container with |
| 450 | * all fields filled in. |
| 451 | **/ |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 452 | static uint16_t |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 453 | _ptp_transaction (PTPParams* params, PTPContainer* ptp, |
| 454 | uint16_t flags, unsigned int sendlen, unsigned char** data, |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 455 | int fd, unsigned int *recvlen) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 456 | { |
| 457 | if ((params==NULL) || (ptp==NULL)) |
| 458 | return PTP_ERROR_BADPARAM; |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 459 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 460 | ptp->Transaction_ID=params->transaction_id++; |
| 461 | ptp->SessionID=params->session_id; |
| 462 | /* send request */ |
| 463 | CHECK_PTP_RC(params->sendreq_func (params, ptp)); |
| 464 | /* is there a dataphase? */ |
| 465 | switch (flags&PTP_DP_DATA_MASK) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 466 | case PTP_DP_SENDDATA: |
| 467 | CHECK_PTP_RC(params->senddata_func(params, ptp, |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 468 | *data, sendlen, fd)); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 469 | break; |
| 470 | case PTP_DP_GETDATA: |
| 471 | CHECK_PTP_RC(params->getdata_func(params, ptp, |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 472 | (unsigned char**)data, recvlen, fd)); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 473 | break; |
| 474 | case PTP_DP_NODATA: |
| 475 | break; |
| 476 | default: |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 477 | return PTP_ERROR_BADPARAM; |
| 478 | } |
| 479 | /* get response */ |
| 480 | CHECK_PTP_RC(params->getresp_func(params, ptp)); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 481 | if (ptp->Transaction_ID != params->transaction_id-1) { |
| 482 | ptp_error (params, |
| 483 | "PTP: Sequence number mismatch %d vs expected %d.", |
| 484 | ptp->Transaction_ID, params->transaction_id-1 |
| 485 | ); |
| 486 | return PTP_ERROR_BADPARAM; |
| 487 | } |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 488 | return ptp->Code; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 491 | static uint16_t |
| 492 | ptp_transaction (PTPParams* params, PTPContainer* ptp, |
| 493 | uint16_t flags, unsigned int sendlen, unsigned char** data, |
| 494 | unsigned int *recvlen) |
| 495 | { |
| 496 | return _ptp_transaction(params, ptp, flags, sendlen, data, -1, recvlen); |
| 497 | } |
| 498 | |
| 499 | static uint16_t |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 500 | ptp_transaction_fd (PTPParams* params, PTPContainer* ptp, |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 501 | uint16_t flags, unsigned int sendlen, |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 502 | int fd, unsigned int *recvlen) |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 503 | { |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 504 | /* |
| 505 | * This dummy data needed since _ptp_transaction() |
| 506 | * will dereference the data argument |
| 507 | */ |
| 508 | unsigned char *dummydata = NULL; |
| 509 | |
| 510 | return _ptp_transaction(params, ptp, flags, sendlen, &dummydata, fd, recvlen); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 513 | /* Enets handling functions */ |
| 514 | |
| 515 | /* PTP Events wait for or check mode */ |
| 516 | #define PTP_EVENT_CHECK 0x0000 /* waits for */ |
| 517 | #define PTP_EVENT_CHECK_FAST 0x0001 /* checks */ |
| 518 | |
| 519 | static inline uint16_t |
| 520 | ptp_usb_event (PTPParams* params, PTPContainer* event, int wait) |
| 521 | { |
| 522 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 523 | unsigned int rlen; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 524 | PTPUSBEventContainer usbevent; |
| 525 | PTP_CNT_INIT(usbevent); |
| 526 | |
| 527 | if ((params==NULL) || (event==NULL)) |
| 528 | return PTP_ERROR_BADPARAM; |
| 529 | |
| 530 | switch(wait) { |
| 531 | case PTP_EVENT_CHECK: |
| 532 | ret=params->check_int_func((unsigned char*)&usbevent, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 533 | sizeof(usbevent), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 534 | break; |
| 535 | case PTP_EVENT_CHECK_FAST: |
| 536 | ret=params->check_int_fast_func((unsigned char*) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 537 | &usbevent, sizeof(usbevent), params->data, &rlen); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 538 | break; |
| 539 | default: |
| 540 | ret=PTP_ERROR_BADPARAM; |
| 541 | } |
| 542 | if (ret!=PTP_RC_OK) { |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 543 | ptp_error (params, |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 544 | "PTP: reading event an error 0x%04x occurred", ret); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 545 | ret = PTP_ERROR_IO; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 546 | /* reading event error is nonfatal (for example timeout) */ |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 547 | } |
| 548 | /* Only do the additional reads for "events". Canon IXUS 2 likes to |
| 549 | * send unrelated data. |
| 550 | */ |
| 551 | if (dtoh16(usbevent.type) == PTP_USB_CONTAINER_EVENT) { |
| 552 | while (dtoh32(usbevent.length) > rlen) { |
| 553 | unsigned int newrlen = 0; |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 554 | |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 555 | ret=params->check_int_fast_func(((unsigned char*)&usbevent)+rlen, |
| 556 | dtoh32(usbevent.length)-rlen,params->data,&newrlen |
| 557 | ); |
| 558 | if (ret != PTP_RC_OK) |
| 559 | break; |
| 560 | rlen+=newrlen; |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 561 | } |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 562 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 563 | /* if we read anything over interrupt endpoint it must be an event */ |
| 564 | /* build an appropriate PTPContainer */ |
| 565 | event->Code=dtoh16(usbevent.code); |
| 566 | event->SessionID=params->session_id; |
| 567 | event->Transaction_ID=dtoh32(usbevent.trans_id); |
| 568 | event->Param1=dtoh32(usbevent.param1); |
| 569 | event->Param2=dtoh32(usbevent.param2); |
| 570 | event->Param3=dtoh32(usbevent.param3); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 571 | return ret; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | uint16_t |
| 575 | ptp_usb_event_check (PTPParams* params, PTPContainer* event) { |
| 576 | |
| 577 | return ptp_usb_event (params, event, PTP_EVENT_CHECK_FAST); |
| 578 | } |
| 579 | |
| 580 | uint16_t |
| 581 | ptp_usb_event_wait (PTPParams* params, PTPContainer* event) { |
| 582 | |
| 583 | return ptp_usb_event (params, event, PTP_EVENT_CHECK); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * PTP operation functions |
| 588 | * |
| 589 | * all ptp_ functions should take integer parameters |
| 590 | * in host byte order! |
| 591 | **/ |
| 592 | |
| 593 | |
| 594 | /** |
| 595 | * ptp_getdeviceinfo: |
| 596 | * params: PTPParams* |
| 597 | * |
| 598 | * Gets device info dataset and fills deviceinfo structure. |
| 599 | * |
| 600 | * Return values: Some PTP_RC_* code. |
| 601 | **/ |
| 602 | uint16_t |
| 603 | ptp_getdeviceinfo (PTPParams* params, PTPDeviceInfo* deviceinfo) |
| 604 | { |
| 605 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 606 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 607 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 608 | unsigned char* di=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 609 | |
| 610 | PTP_CNT_INIT(ptp); |
| 611 | ptp.Code=PTP_OC_GetDeviceInfo; |
| 612 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 613 | len=0; |
| 614 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &di, &len); |
| 615 | if (ret == PTP_RC_OK) ptp_unpack_DI(params, di, deviceinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 616 | free(di); |
| 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | |
| 621 | /** |
| 622 | * ptp_opensession: |
| 623 | * params: PTPParams* |
| 624 | * session - session number |
| 625 | * |
| 626 | * Establishes a new session. |
| 627 | * |
| 628 | * Return values: Some PTP_RC_* code. |
| 629 | **/ |
| 630 | uint16_t |
| 631 | ptp_opensession (PTPParams* params, uint32_t session) |
| 632 | { |
| 633 | uint16_t ret; |
| 634 | PTPContainer ptp; |
| 635 | |
| 636 | ptp_debug(params,"PTP: Opening session"); |
| 637 | |
| 638 | /* SessonID field of the operation dataset should always |
| 639 | be set to 0 for OpenSession request! */ |
| 640 | params->session_id=0x00000000; |
| 641 | /* TransactionID should be set to 0 also! */ |
| 642 | params->transaction_id=0x0000000; |
| 643 | |
| 644 | PTP_CNT_INIT(ptp); |
| 645 | ptp.Code=PTP_OC_OpenSession; |
| 646 | ptp.Param1=session; |
| 647 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 648 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 649 | /* now set the global session id to current session number */ |
| 650 | params->session_id=session; |
| 651 | return ret; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * ptp_closesession: |
| 656 | * params: PTPParams* |
| 657 | * |
| 658 | * Closes session. |
| 659 | * |
| 660 | * Return values: Some PTP_RC_* code. |
| 661 | **/ |
| 662 | uint16_t |
| 663 | ptp_closesession (PTPParams* params) |
| 664 | { |
| 665 | PTPContainer ptp; |
| 666 | |
| 667 | ptp_debug(params,"PTP: Closing session"); |
| 668 | |
| 669 | PTP_CNT_INIT(ptp); |
| 670 | ptp.Code=PTP_OC_CloseSession; |
| 671 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 672 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
| 676 | * ptp_getststorageids: |
| 677 | * params: PTPParams* |
| 678 | * |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 679 | * Gets array of StorageIDs and fills the storageids structure. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 680 | * |
| 681 | * Return values: Some PTP_RC_* code. |
| 682 | **/ |
| 683 | uint16_t |
| 684 | ptp_getstorageids (PTPParams* params, PTPStorageIDs* storageids) |
| 685 | { |
| 686 | uint16_t ret; |
| 687 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 688 | unsigned int len; |
| 689 | unsigned char* sids=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 690 | |
| 691 | PTP_CNT_INIT(ptp); |
| 692 | ptp.Code=PTP_OC_GetStorageIDs; |
| 693 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 694 | len=0; |
| 695 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &sids, &len); |
| 696 | if (ret == PTP_RC_OK) ptp_unpack_SIDs(params, sids, storageids, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 697 | free(sids); |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * ptp_getststorageinfo: |
| 703 | * params: PTPParams* |
| 704 | * storageid - StorageID |
| 705 | * |
| 706 | * Gets StorageInfo dataset of desired storage and fills storageinfo |
| 707 | * structure. |
| 708 | * |
| 709 | * Return values: Some PTP_RC_* code. |
| 710 | **/ |
| 711 | uint16_t |
| 712 | ptp_getstorageinfo (PTPParams* params, uint32_t storageid, |
| 713 | PTPStorageInfo* storageinfo) |
| 714 | { |
| 715 | uint16_t ret; |
| 716 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 717 | unsigned char* si=NULL; |
| 718 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 719 | |
| 720 | PTP_CNT_INIT(ptp); |
| 721 | ptp.Code=PTP_OC_GetStorageInfo; |
| 722 | ptp.Param1=storageid; |
| 723 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 724 | len=0; |
| 725 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &si, &len); |
| 726 | if (ret == PTP_RC_OK) ptp_unpack_SI(params, si, storageinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 727 | free(si); |
| 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | /** |
Linus Walleij | 13374a4 | 2006-09-13 11:55:30 +0000 | [diff] [blame] | 732 | * ptp_formatstore: |
| 733 | * params: PTPParams* |
| 734 | * storageid - StorageID |
| 735 | * |
| 736 | * Formats the storage on the device. |
| 737 | * |
| 738 | * Return values: Some PTP_RC_* code. |
| 739 | **/ |
| 740 | uint16_t |
| 741 | ptp_formatstore (PTPParams* params, uint32_t storageid) |
| 742 | { |
Linus Walleij | 13374a4 | 2006-09-13 11:55:30 +0000 | [diff] [blame] | 743 | PTPContainer ptp; |
| 744 | |
| 745 | PTP_CNT_INIT(ptp); |
| 746 | ptp.Code=PTP_OC_FormatStore; |
| 747 | ptp.Param1=storageid; |
| 748 | ptp.Param2=PTP_FST_Undefined; |
| 749 | ptp.Nparam=2; |
Linus Walleij | 4f40d11 | 2006-09-21 07:44:53 +0000 | [diff] [blame] | 750 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | 13374a4 | 2006-09-13 11:55:30 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 754 | * ptp_getobjecthandles: |
| 755 | * params: PTPParams* |
| 756 | * storage - StorageID |
| 757 | * objectformatcode - ObjectFormatCode (optional) |
| 758 | * associationOH - ObjectHandle of Association for |
| 759 | * wich a list of children is desired |
| 760 | * (optional) |
| 761 | * objecthandles - pointer to structute |
| 762 | * |
| 763 | * Fills objecthandles with structure returned by device. |
| 764 | * |
| 765 | * Return values: Some PTP_RC_* code. |
| 766 | **/ |
| 767 | uint16_t |
| 768 | ptp_getobjecthandles (PTPParams* params, uint32_t storage, |
| 769 | uint32_t objectformatcode, uint32_t associationOH, |
| 770 | PTPObjectHandles* objecthandles) |
| 771 | { |
| 772 | uint16_t ret; |
| 773 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 774 | unsigned char* oh=NULL; |
| 775 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 776 | |
| 777 | PTP_CNT_INIT(ptp); |
| 778 | ptp.Code=PTP_OC_GetObjectHandles; |
| 779 | ptp.Param1=storage; |
| 780 | ptp.Param2=objectformatcode; |
| 781 | ptp.Param3=associationOH; |
| 782 | ptp.Nparam=3; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 783 | len=0; |
| 784 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oh, &len); |
| 785 | if (ret == PTP_RC_OK) ptp_unpack_OH(params, oh, objecthandles, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 786 | free(oh); |
| 787 | return ret; |
| 788 | } |
| 789 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 790 | /** |
| 791 | * ptp_getnumobjects: |
| 792 | * params: PTPParams* |
| 793 | * storage - StorageID |
| 794 | * objectformatcode - ObjectFormatCode (optional) |
| 795 | * associationOH - ObjectHandle of Association for |
| 796 | * wich a list of children is desired |
| 797 | * (optional) |
| 798 | * numobs - pointer to uint32_t that takes number of objects |
| 799 | * |
| 800 | * Fills numobs with number of objects on device. |
| 801 | * |
| 802 | * Return values: Some PTP_RC_* code. |
| 803 | **/ |
| 804 | uint16_t |
| 805 | ptp_getnumobjects (PTPParams* params, uint32_t storage, |
| 806 | uint32_t objectformatcode, uint32_t associationOH, |
| 807 | uint32_t* numobs) |
| 808 | { |
| 809 | uint16_t ret; |
| 810 | PTPContainer ptp; |
| 811 | int len; |
| 812 | |
| 813 | PTP_CNT_INIT(ptp); |
| 814 | ptp.Code=PTP_OC_GetObjectHandles; |
| 815 | ptp.Param1=storage; |
| 816 | ptp.Param2=objectformatcode; |
| 817 | ptp.Param3=associationOH; |
| 818 | ptp.Nparam=3; |
| 819 | len=0; |
| 820 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 821 | if (ret == PTP_RC_OK) { |
| 822 | if (ptp.Nparam >= 1) |
| 823 | *numobs = ptp.Param1; |
| 824 | else |
| 825 | ret = PTP_RC_GeneralError; |
| 826 | } |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | /** |
| 831 | * ptp_getobjectinfo: |
| 832 | * params: PTPParams* |
| 833 | * handle - Object handle |
| 834 | * objectinfo - pointer to objectinfo that is returned |
| 835 | * |
| 836 | * Get objectinfo structure for handle from device. |
| 837 | * |
| 838 | * Return values: Some PTP_RC_* code. |
| 839 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 840 | uint16_t |
| 841 | ptp_getobjectinfo (PTPParams* params, uint32_t handle, |
| 842 | PTPObjectInfo* objectinfo) |
| 843 | { |
| 844 | uint16_t ret; |
| 845 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 846 | unsigned char* oi=NULL; |
| 847 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 848 | |
| 849 | PTP_CNT_INIT(ptp); |
| 850 | ptp.Code=PTP_OC_GetObjectInfo; |
| 851 | ptp.Param1=handle; |
| 852 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 853 | len=0; |
| 854 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &oi, &len); |
| 855 | if (ret == PTP_RC_OK) ptp_unpack_OI(params, oi, objectinfo, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 856 | free(oi); |
| 857 | return ret; |
| 858 | } |
| 859 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 860 | /** |
| 861 | * ptp_getobject: |
| 862 | * params: PTPParams* |
| 863 | * handle - Object handle |
| 864 | * object - pointer to data area |
| 865 | * |
| 866 | * Get object 'handle' from device and store the data in newly |
| 867 | * allocated 'object'. |
| 868 | * |
| 869 | * Return values: Some PTP_RC_* code. |
| 870 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 871 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 872 | ptp_getobject (PTPParams* params, uint32_t handle, unsigned char** object) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 873 | { |
| 874 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 875 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 876 | |
| 877 | PTP_CNT_INIT(ptp); |
| 878 | ptp.Code=PTP_OC_GetObject; |
| 879 | ptp.Param1=handle; |
| 880 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 881 | len=0; |
| 882 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 885 | /** |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 886 | * ptp_getobject_tofd: |
| 887 | * params: PTPParams* |
| 888 | * handle - Object handle |
| 889 | * fd - File descriptor to write() to |
| 890 | * |
| 891 | * Get object 'handle' from device and write the data to the |
| 892 | * given file descriptor. |
| 893 | * |
| 894 | * Return values: Some PTP_RC_* code. |
| 895 | **/ |
| 896 | uint16_t |
| 897 | ptp_getobject_tofd (PTPParams* params, uint32_t handle, int fd) |
| 898 | { |
| 899 | PTPContainer ptp; |
| 900 | unsigned int len; |
| 901 | |
| 902 | PTP_CNT_INIT(ptp); |
| 903 | ptp.Code=PTP_OC_GetObject; |
| 904 | ptp.Param1=handle; |
| 905 | ptp.Nparam=1; |
| 906 | len=0; |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 907 | return ptp_transaction_fd(params, &ptp, PTP_DP_GETDATA, 0, fd, &len); |
Linus Walleij | 96c6243 | 2006-08-21 10:04:02 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /** |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 911 | * ptp_getpartialobject: |
| 912 | * params: PTPParams* |
| 913 | * handle - Object handle |
| 914 | * offset - Offset into object |
| 915 | * maxbytes - Maximum of bytes to read |
| 916 | * object - pointer to data area |
| 917 | * |
| 918 | * Get object 'handle' from device and store the data in newly |
| 919 | * allocated 'object'. Start from offset and read at most maxbytes. |
| 920 | * |
| 921 | * Return values: Some PTP_RC_* code. |
| 922 | **/ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 923 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 924 | ptp_getpartialobject (PTPParams* params, uint32_t handle, uint32_t offset, |
| 925 | uint32_t maxbytes, unsigned char** object) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 926 | { |
| 927 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 928 | unsigned int len; |
| 929 | |
| 930 | PTP_CNT_INIT(ptp); |
| 931 | ptp.Code=PTP_OC_GetPartialObject; |
| 932 | ptp.Param1=handle; |
| 933 | ptp.Param2=offset; |
| 934 | ptp.Param3=maxbytes; |
| 935 | ptp.Nparam=3; |
| 936 | len=0; |
| 937 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * ptp_getthumb: |
| 942 | * params: PTPParams* |
| 943 | * handle - Object handle |
| 944 | * object - pointer to data area |
| 945 | * |
| 946 | * Get thumb for object 'handle' from device and store the data in newly |
| 947 | * allocated 'object'. |
| 948 | * |
| 949 | * Return values: Some PTP_RC_* code. |
| 950 | **/ |
| 951 | uint16_t |
| 952 | ptp_getthumb (PTPParams* params, uint32_t handle, unsigned char** object) |
| 953 | { |
| 954 | PTPContainer ptp; |
| 955 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 956 | |
| 957 | PTP_CNT_INIT(ptp); |
| 958 | ptp.Code=PTP_OC_GetThumb; |
| 959 | ptp.Param1=handle; |
| 960 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 961 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, object, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
| 965 | * ptp_deleteobject: |
| 966 | * params: PTPParams* |
| 967 | * handle - object handle |
| 968 | * ofc - object format code (optional) |
| 969 | * |
| 970 | * Deletes desired objects. |
| 971 | * |
| 972 | * Return values: Some PTP_RC_* code. |
| 973 | **/ |
| 974 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 975 | ptp_deleteobject (PTPParams* params, uint32_t handle, uint32_t ofc) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 976 | { |
| 977 | PTPContainer ptp; |
| 978 | |
| 979 | PTP_CNT_INIT(ptp); |
| 980 | ptp.Code=PTP_OC_DeleteObject; |
| 981 | ptp.Param1=handle; |
| 982 | ptp.Param2=ofc; |
| 983 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 984 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | /** |
| 988 | * ptp_sendobjectinfo: |
| 989 | * params: PTPParams* |
| 990 | * uint32_t* store - destination StorageID on Responder |
| 991 | * uint32_t* parenthandle - Parent ObjectHandle on responder |
| 992 | * uint32_t* handle - see Return values |
| 993 | * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent |
| 994 | * |
| 995 | * Sends ObjectInfo of file that is to be sent via SendFileObject. |
| 996 | * |
| 997 | * Return values: Some PTP_RC_* code. |
| 998 | * Upon success : uint32_t* store - Responder StorageID in which |
| 999 | * object will be stored |
| 1000 | * uint32_t* parenthandle- Responder Parent ObjectHandle |
| 1001 | * in which the object will be stored |
| 1002 | * uint32_t* handle - Responder's reserved ObjectHandle |
| 1003 | * for the incoming object |
| 1004 | **/ |
| 1005 | uint16_t |
| 1006 | ptp_sendobjectinfo (PTPParams* params, uint32_t* store, |
| 1007 | uint32_t* parenthandle, uint32_t* handle, |
| 1008 | PTPObjectInfo* objectinfo) |
| 1009 | { |
| 1010 | uint16_t ret; |
| 1011 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1012 | unsigned char* oidata=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1013 | uint32_t size; |
| 1014 | |
| 1015 | PTP_CNT_INIT(ptp); |
| 1016 | ptp.Code=PTP_OC_SendObjectInfo; |
| 1017 | ptp.Param1=*store; |
| 1018 | ptp.Param2=*parenthandle; |
| 1019 | ptp.Nparam=2; |
| 1020 | |
| 1021 | size=ptp_pack_OI(params, objectinfo, &oidata); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1022 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1023 | free(oidata); |
| 1024 | *store=ptp.Param1; |
| 1025 | *parenthandle=ptp.Param2; |
| 1026 | *handle=ptp.Param3; |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * ptp_sendobject: |
| 1032 | * params: PTPParams* |
| 1033 | * char* object - contains the object that is to be sent |
| 1034 | * uint32_t size - object size |
| 1035 | * |
| 1036 | * Sends object to Responder. |
| 1037 | * |
| 1038 | * Return values: Some PTP_RC_* code. |
| 1039 | * |
| 1040 | */ |
| 1041 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1042 | ptp_sendobject (PTPParams* params, unsigned char* object, uint32_t size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1043 | { |
| 1044 | PTPContainer ptp; |
| 1045 | |
| 1046 | PTP_CNT_INIT(ptp); |
| 1047 | ptp.Code=PTP_OC_SendObject; |
| 1048 | ptp.Nparam=0; |
| 1049 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1050 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Linus Walleij | e7f44be | 2006-08-25 19:32:29 +0000 | [diff] [blame] | 1053 | /** |
| 1054 | * ptp_sendobject_fromfd: |
| 1055 | * params: PTPParams* |
| 1056 | * fd - File descriptor to read() object from |
| 1057 | * uint32_t size - File/object size |
| 1058 | * |
| 1059 | * Sends object from file descriptor by consecutive reads from this |
| 1060 | * descriptor. |
| 1061 | * |
| 1062 | * Return values: Some PTP_RC_* code. |
| 1063 | **/ |
| 1064 | uint16_t |
| 1065 | ptp_sendobject_fromfd (PTPParams* params, int fd, uint32_t size) |
| 1066 | { |
| 1067 | PTPContainer ptp; |
| 1068 | |
| 1069 | PTP_CNT_INIT(ptp); |
| 1070 | ptp.Code=PTP_OC_SendObject; |
| 1071 | ptp.Nparam=0; |
| 1072 | |
| 1073 | return ptp_transaction_fd(params, &ptp, PTP_DP_SENDDATA, size, fd, NULL); |
| 1074 | } |
| 1075 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1076 | |
| 1077 | /** |
| 1078 | * ptp_initiatecapture: |
| 1079 | * params: PTPParams* |
| 1080 | * storageid - destination StorageID on Responder |
| 1081 | * ofc - object format code |
| 1082 | * |
| 1083 | * Causes device to initiate the capture of one or more new data objects |
| 1084 | * according to its current device properties, storing the data into store |
| 1085 | * indicated by storageid. If storageid is 0x00000000, the object(s) will |
| 1086 | * be stored in a store that is determined by the capturing device. |
| 1087 | * The capturing of new data objects is an asynchronous operation. |
| 1088 | * |
| 1089 | * Return values: Some PTP_RC_* code. |
| 1090 | **/ |
| 1091 | |
| 1092 | uint16_t |
| 1093 | ptp_initiatecapture (PTPParams* params, uint32_t storageid, |
| 1094 | uint32_t ofc) |
| 1095 | { |
| 1096 | PTPContainer ptp; |
| 1097 | |
| 1098 | PTP_CNT_INIT(ptp); |
| 1099 | ptp.Code=PTP_OC_InitiateCapture; |
| 1100 | ptp.Param1=storageid; |
| 1101 | ptp.Param2=ofc; |
| 1102 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1103 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | uint16_t |
| 1107 | ptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, |
| 1108 | PTPDevicePropDesc* devicepropertydesc) |
| 1109 | { |
| 1110 | PTPContainer ptp; |
| 1111 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1112 | unsigned int len; |
| 1113 | unsigned char* dpd=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1114 | |
| 1115 | PTP_CNT_INIT(ptp); |
| 1116 | ptp.Code=PTP_OC_GetDevicePropDesc; |
| 1117 | ptp.Param1=propcode; |
| 1118 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1119 | len=0; |
| 1120 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpd, &len); |
| 1121 | if (ret == PTP_RC_OK) ptp_unpack_DPD(params, dpd, devicepropertydesc, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1122 | free(dpd); |
| 1123 | return ret; |
| 1124 | } |
| 1125 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1126 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1127 | uint16_t |
| 1128 | ptp_getdevicepropvalue (PTPParams* params, uint16_t propcode, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1129 | PTPPropertyValue* value, uint16_t datatype) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1130 | { |
| 1131 | PTPContainer ptp; |
| 1132 | uint16_t ret; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1133 | unsigned int len; |
| 1134 | int offset; |
| 1135 | unsigned char* dpv=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1136 | |
| 1137 | |
| 1138 | PTP_CNT_INIT(ptp); |
| 1139 | ptp.Code=PTP_OC_GetDevicePropValue; |
| 1140 | ptp.Param1=propcode; |
| 1141 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1142 | len=offset=0; |
| 1143 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, &len); |
| 1144 | 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] | 1145 | free(dpv); |
| 1146 | return ret; |
| 1147 | } |
| 1148 | |
| 1149 | uint16_t |
| 1150 | ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1151 | PTPPropertyValue *value, uint16_t datatype) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1152 | { |
| 1153 | PTPContainer ptp; |
| 1154 | uint16_t ret; |
| 1155 | uint32_t size; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1156 | unsigned char* dpv=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1157 | |
| 1158 | PTP_CNT_INIT(ptp); |
| 1159 | ptp.Code=PTP_OC_SetDevicePropValue; |
| 1160 | ptp.Param1=propcode; |
| 1161 | ptp.Nparam=1; |
| 1162 | size=ptp_pack_DPV(params, value, &dpv, datatype); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1163 | ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &dpv, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1164 | free(dpv); |
| 1165 | return ret; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * ptp_ek_sendfileobjectinfo: |
| 1170 | * params: PTPParams* |
| 1171 | * uint32_t* store - destination StorageID on Responder |
| 1172 | * uint32_t* parenthandle - Parent ObjectHandle on responder |
| 1173 | * uint32_t* handle - see Return values |
| 1174 | * PTPObjectInfo* objectinfo- ObjectInfo that is to be sent |
| 1175 | * |
| 1176 | * Sends ObjectInfo of file that is to be sent via SendFileObject. |
| 1177 | * |
| 1178 | * Return values: Some PTP_RC_* code. |
| 1179 | * Upon success : uint32_t* store - Responder StorageID in which |
| 1180 | * object will be stored |
| 1181 | * uint32_t* parenthandle- Responder Parent ObjectHandle |
| 1182 | * in which the object will be stored |
| 1183 | * uint32_t* handle - Responder's reserved ObjectHandle |
| 1184 | * for the incoming object |
| 1185 | **/ |
| 1186 | uint16_t |
| 1187 | ptp_ek_sendfileobjectinfo (PTPParams* params, uint32_t* store, |
| 1188 | uint32_t* parenthandle, uint32_t* handle, |
| 1189 | PTPObjectInfo* objectinfo) |
| 1190 | { |
| 1191 | uint16_t ret; |
| 1192 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1193 | unsigned char* oidata=NULL; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1194 | uint32_t size; |
| 1195 | |
| 1196 | PTP_CNT_INIT(ptp); |
| 1197 | ptp.Code=PTP_OC_EK_SendFileObjectInfo; |
| 1198 | ptp.Param1=*store; |
| 1199 | ptp.Param2=*parenthandle; |
| 1200 | ptp.Nparam=2; |
| 1201 | |
| 1202 | size=ptp_pack_OI(params, objectinfo, &oidata); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1203 | ret=ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &oidata, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1204 | free(oidata); |
| 1205 | *store=ptp.Param1; |
| 1206 | *parenthandle=ptp.Param2; |
| 1207 | *handle=ptp.Param3; |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
| 1211 | /** |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1212 | * ptp_ek_getserial: |
| 1213 | * params: PTPParams* |
| 1214 | * char** serial - contains the serial number of the camera |
| 1215 | * uint32_t* size - contains the string length |
| 1216 | * |
| 1217 | * Gets the serial number from the device. (ptp serial) |
| 1218 | * |
| 1219 | * Return values: Some PTP_RC_* code. |
| 1220 | * |
| 1221 | */ |
| 1222 | uint16_t |
| 1223 | ptp_ek_getserial (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1224 | { |
| 1225 | PTPContainer ptp; |
| 1226 | |
| 1227 | PTP_CNT_INIT(ptp); |
| 1228 | ptp.Code = PTP_OC_EK_GetSerial; |
| 1229 | ptp.Nparam = 0; |
| 1230 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * ptp_ek_setserial: |
| 1235 | * params: PTPParams* |
| 1236 | * char* serial - contains the new serial number |
| 1237 | * uint32_t size - string length |
| 1238 | * |
| 1239 | * Sets the serial number of the device. (ptp serial) |
| 1240 | * |
| 1241 | * Return values: Some PTP_RC_* code. |
| 1242 | * |
| 1243 | */ |
| 1244 | uint16_t |
| 1245 | ptp_ek_setserial (PTPParams* params, unsigned char *data, unsigned int size) |
| 1246 | { |
| 1247 | PTPContainer ptp; |
| 1248 | |
| 1249 | PTP_CNT_INIT(ptp); |
| 1250 | ptp.Code = PTP_OC_EK_SetSerial; |
| 1251 | ptp.Nparam = 0; |
| 1252 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1253 | } |
| 1254 | |
| 1255 | /* unclear what it does yet */ |
| 1256 | uint16_t |
| 1257 | ptp_ek_9007 (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1258 | { |
| 1259 | PTPContainer ptp; |
| 1260 | |
| 1261 | PTP_CNT_INIT(ptp); |
| 1262 | ptp.Code = 0x9007; |
| 1263 | ptp.Nparam = 0; |
| 1264 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1265 | } |
| 1266 | |
| 1267 | /* unclear what it does yet */ |
| 1268 | uint16_t |
| 1269 | ptp_ek_9009 (PTPParams* params, uint32_t *p1, uint32_t *p2) |
| 1270 | { |
| 1271 | PTPContainer ptp; |
| 1272 | uint16_t ret; |
| 1273 | |
| 1274 | PTP_CNT_INIT(ptp); |
| 1275 | ptp.Code = 0x9009; |
| 1276 | ptp.Nparam = 0; |
| 1277 | ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1278 | *p1 = ptp.Param1; |
| 1279 | *p2 = ptp.Param2; |
| 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | /* unclear yet, but I guess it returns the info from 9008 */ |
| 1284 | uint16_t |
| 1285 | ptp_ek_900c (PTPParams* params, unsigned char **data, unsigned int *size) |
| 1286 | { |
| 1287 | PTPContainer ptp; |
| 1288 | |
| 1289 | PTP_CNT_INIT(ptp); |
| 1290 | ptp.Code = 0x900c; |
| 1291 | ptp.Nparam = 0; |
| 1292 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 1293 | /* returned data is 16bit,16bit,32bit,32bit */ |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * ptp_ek_settext: |
| 1298 | * params: PTPParams* |
| 1299 | * PTPEKTextParams* - contains the texts to display. |
| 1300 | * |
| 1301 | * Displays the specified texts on the TFT of the camera. |
| 1302 | * |
| 1303 | * Return values: Some PTP_RC_* code. |
| 1304 | * |
| 1305 | */ |
| 1306 | uint16_t |
| 1307 | ptp_ek_settext (PTPParams* params, PTPEKTextParams *text) |
| 1308 | { |
| 1309 | PTPContainer ptp; |
| 1310 | uint16_t ret; |
| 1311 | unsigned int size; |
| 1312 | unsigned char *data; |
| 1313 | |
| 1314 | PTP_CNT_INIT(ptp); |
| 1315 | ptp.Code = PTP_OC_EK_SetText; |
| 1316 | ptp.Nparam = 0; |
| 1317 | if (0 == (size = ptp_pack_EK_text(params, text, &data))) |
| 1318 | return PTP_ERROR_BADPARAM; |
| 1319 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
| 1320 | free(data); |
| 1321 | return ret; |
| 1322 | } |
| 1323 | |
| 1324 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1325 | * ptp_ek_sendfileobject: |
| 1326 | * params: PTPParams* |
| 1327 | * char* object - contains the object that is to be sent |
| 1328 | * uint32_t size - object size |
| 1329 | * |
| 1330 | * Sends object to Responder. |
| 1331 | * |
| 1332 | * Return values: Some PTP_RC_* code. |
| 1333 | * |
| 1334 | */ |
| 1335 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1336 | ptp_ek_sendfileobject (PTPParams* params, unsigned char* object, uint32_t size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1337 | { |
| 1338 | PTPContainer ptp; |
| 1339 | |
| 1340 | PTP_CNT_INIT(ptp); |
| 1341 | ptp.Code=PTP_OC_EK_SendFileObject; |
| 1342 | ptp.Nparam=0; |
| 1343 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1344 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &object, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /************************************************************************* |
| 1348 | * |
| 1349 | * Canon PTP extensions support |
| 1350 | * |
| 1351 | * (C) Nikolai Kopanygin 2003 |
| 1352 | * |
| 1353 | *************************************************************************/ |
| 1354 | |
| 1355 | |
| 1356 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1357 | * ptp_canon_getpartialobjectinfo: |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1358 | * params: PTPParams* |
| 1359 | * uint32_t handle - ObjectHandle |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1360 | * uint32_t p2 - Not fully understood parameter |
| 1361 | * 0 - returns full size |
| 1362 | * 1 - returns thumbnail size (or EXIF?) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1363 | * |
| 1364 | * Gets form the responder the size of the specified object. |
| 1365 | * |
| 1366 | * Return values: Some PTP_RC_* code. |
| 1367 | * Upon success : uint32_t* size - The object size |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1368 | * uint32_t* rp2 - Still unknown return parameter |
| 1369 | * (perhaps upper 32bit of size) |
| 1370 | * |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1371 | * |
| 1372 | **/ |
| 1373 | uint16_t |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1374 | ptp_canon_getpartialobjectinfo (PTPParams* params, uint32_t handle, uint32_t p2, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1375 | uint32_t* size, uint32_t* rp2) |
| 1376 | { |
| 1377 | uint16_t ret; |
| 1378 | PTPContainer ptp; |
| 1379 | |
| 1380 | PTP_CNT_INIT(ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1381 | ptp.Code=PTP_OC_CANON_GetPartialObjectInfo; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1382 | ptp.Param1=handle; |
| 1383 | ptp.Param2=p2; |
| 1384 | ptp.Nparam=2; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1385 | ret=ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1386 | *size=ptp.Param1; |
| 1387 | *rp2=ptp.Param2; |
| 1388 | return ret; |
| 1389 | } |
| 1390 | |
| 1391 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1392 | * ptp_canon_get_mac_address: |
| 1393 | * params: PTPParams* |
| 1394 | * value 0 works. |
| 1395 | * Gets the MAC address of the wireless transmitter. |
| 1396 | * |
| 1397 | * Return values: Some PTP_RC_* code. |
| 1398 | * Upon success : unsigned char* mac - The MAC address |
| 1399 | * |
| 1400 | **/ |
| 1401 | uint16_t |
| 1402 | ptp_canon_get_mac_address (PTPParams* params, unsigned char **mac) |
| 1403 | { |
| 1404 | PTPContainer ptp; |
| 1405 | unsigned int size = 0; |
| 1406 | |
| 1407 | PTP_CNT_INIT(ptp); |
| 1408 | ptp.Code=PTP_OC_CANON_GetMACAddress; |
| 1409 | ptp.Nparam=0; |
| 1410 | *mac = NULL; |
| 1411 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, mac, &size); |
| 1412 | } |
| 1413 | |
| 1414 | /** |
| 1415 | * ptp_canon_get_directory: |
| 1416 | * params: PTPParams* |
| 1417 | |
| 1418 | * Gets the full directory of the camera. |
| 1419 | * |
| 1420 | * Return values: Some PTP_RC_* code. |
| 1421 | * Upon success : PTPObjectHandles *handles - filled out with handles |
| 1422 | * PTPObjectInfo **oinfos - allocated array of PTP Object Infos |
| 1423 | * uint32_t **flags - allocated array of CANON Flags |
| 1424 | * |
| 1425 | **/ |
| 1426 | uint16_t |
| 1427 | ptp_canon_get_directory (PTPParams* params, |
| 1428 | PTPObjectHandles *handles, |
| 1429 | PTPObjectInfo **oinfos, /* size(handles->n) */ |
| 1430 | uint32_t **flags /* size(handles->n) */ |
| 1431 | ) { |
| 1432 | PTPContainer ptp; |
| 1433 | unsigned char *dir = NULL; |
| 1434 | unsigned int size = 0; |
| 1435 | uint16_t ret; |
| 1436 | |
| 1437 | PTP_CNT_INIT(ptp); |
| 1438 | ptp.Code=PTP_OC_CANON_GetDirectory; |
| 1439 | ptp.Nparam=0; |
| 1440 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dir, &size); |
| 1441 | if (ret != PTP_RC_OK) |
| 1442 | return ret; |
| 1443 | ret = ptp_unpack_canon_directory(params, dir, ptp.Param1, handles, oinfos, flags); |
| 1444 | free (dir); |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | /** |
| 1449 | * ptp_canon_setobjectarchive: |
| 1450 | * |
| 1451 | * params: PTPParams* |
| 1452 | * uint32_t objectid |
| 1453 | * uint32_t flags |
| 1454 | * |
| 1455 | * Return values: Some PTP_RC_* code. |
| 1456 | * |
| 1457 | **/ |
| 1458 | uint16_t |
| 1459 | ptp_canon_setobjectarchive (PTPParams* params, uint32_t oid, uint32_t flags) |
| 1460 | { |
| 1461 | PTPContainer ptp; |
| 1462 | |
| 1463 | PTP_CNT_INIT(ptp); |
| 1464 | ptp.Code=PTP_OC_CANON_SetObjectArchive; |
| 1465 | ptp.Nparam=2; |
| 1466 | ptp.Param1=oid; |
| 1467 | ptp.Param2=flags; |
| 1468 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1473 | * ptp_canon_startshootingmode: |
| 1474 | * params: PTPParams* |
| 1475 | * |
| 1476 | * Starts shooting session. It emits a StorageInfoChanged |
| 1477 | * event via the interrupt pipe and pushes the StorageInfoChanged |
| 1478 | * and CANON_CameraModeChange events onto the event stack |
| 1479 | * (see operation PTP_OC_CANON_CheckEvent). |
| 1480 | * |
| 1481 | * Return values: Some PTP_RC_* code. |
| 1482 | * |
| 1483 | **/ |
| 1484 | uint16_t |
| 1485 | ptp_canon_startshootingmode (PTPParams* params) |
| 1486 | { |
| 1487 | PTPContainer ptp; |
| 1488 | |
| 1489 | PTP_CNT_INIT(ptp); |
| 1490 | ptp.Code=PTP_OC_CANON_StartShootingMode; |
| 1491 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1492 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1496 | * ptp_canon_initiate_direct_transfer: |
| 1497 | * params: PTPParams* |
| 1498 | * uint32_t *out |
| 1499 | * |
| 1500 | * Switches the camera display to on and lets the user |
| 1501 | * select what to transfer. Sends a 0xc011 event when started |
| 1502 | * and 0xc013 if direct transfer aborted. |
| 1503 | * |
| 1504 | * Return values: Some PTP_RC_* code. |
| 1505 | * |
| 1506 | **/ |
| 1507 | uint16_t |
| 1508 | ptp_canon_initiate_direct_transfer (PTPParams* params, uint32_t *out) |
| 1509 | { |
| 1510 | PTPContainer ptp; |
| 1511 | uint16_t ret; |
| 1512 | |
| 1513 | PTP_CNT_INIT(ptp); |
| 1514 | ptp.Code = PTP_OC_CANON_InitiateDirectTransferEx2; |
| 1515 | ptp.Nparam = 1; |
| 1516 | ptp.Param1 = 0xf; |
| 1517 | ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1518 | if ((ret == PTP_RC_OK) && (ptp.Nparam>0)) |
| 1519 | *out = ptp.Param1; |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * ptp_canon_get_target_handles: |
| 1525 | * params: PTPParams* |
| 1526 | * PTPCanon_directtransfer_entry **out |
| 1527 | * unsigned int *outsize |
| 1528 | * |
| 1529 | * Retrieves direct transfer entries specifying the images to transfer |
| 1530 | * from the camera (to be retrieved after 0xc011 event). |
| 1531 | * |
| 1532 | * Return values: Some PTP_RC_* code. |
| 1533 | * |
| 1534 | **/ |
| 1535 | uint16_t |
| 1536 | ptp_canon_get_target_handles (PTPParams* params, |
| 1537 | PTPCanon_directtransfer_entry **entries, unsigned int *cnt) |
| 1538 | { |
| 1539 | PTPContainer ptp; |
| 1540 | uint16_t ret; |
| 1541 | unsigned char *out = NULL, *cur; |
| 1542 | int i; |
| 1543 | unsigned int size; |
| 1544 | |
| 1545 | PTP_CNT_INIT(ptp); |
| 1546 | ptp.Code = PTP_OC_CANON_GetTargetHandles; |
| 1547 | ptp.Nparam = 0; |
| 1548 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &out, &size); |
| 1549 | if (ret != PTP_RC_OK) |
| 1550 | return ret; |
| 1551 | *cnt = dtoh32a(out); |
| 1552 | *entries = malloc(sizeof(PTPCanon_directtransfer_entry)*(*cnt)); |
| 1553 | cur = out+4; |
| 1554 | for (i=0;i<*cnt;i++) { |
| 1555 | unsigned char len; |
| 1556 | (*entries)[i].oid = dtoh32a(cur); |
| 1557 | (*entries)[i].str = ptp_unpack_string(params, cur, 4, &len); |
| 1558 | cur += 4+(cur[4]*2+1); |
| 1559 | } |
| 1560 | free (out); |
| 1561 | return PTP_RC_OK; |
| 1562 | } |
| 1563 | /** |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1564 | * ptp_canon_endshootingmode: |
| 1565 | * params: PTPParams* |
| 1566 | * |
| 1567 | * This operation is observed after pressing the Disconnect |
| 1568 | * button on the Remote Capture app. It emits a StorageInfoChanged |
| 1569 | * event via the interrupt pipe and pushes the StorageInfoChanged |
| 1570 | * and CANON_CameraModeChange events onto the event stack |
| 1571 | * (see operation PTP_OC_CANON_CheckEvent). |
| 1572 | * |
| 1573 | * Return values: Some PTP_RC_* code. |
| 1574 | * |
| 1575 | **/ |
| 1576 | uint16_t |
| 1577 | ptp_canon_endshootingmode (PTPParams* params) |
| 1578 | { |
| 1579 | PTPContainer ptp; |
| 1580 | |
| 1581 | PTP_CNT_INIT(ptp); |
| 1582 | ptp.Code=PTP_OC_CANON_EndShootingMode; |
| 1583 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1584 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | /** |
| 1588 | * ptp_canon_viewfinderon: |
| 1589 | * params: PTPParams* |
| 1590 | * |
| 1591 | * Prior to start reading viewfinder images, one must call this operation. |
| 1592 | * Supposedly, this operation affects the value of the CANON_ViewfinderMode |
| 1593 | * property. |
| 1594 | * |
| 1595 | * Return values: Some PTP_RC_* code. |
| 1596 | * |
| 1597 | **/ |
| 1598 | uint16_t |
| 1599 | ptp_canon_viewfinderon (PTPParams* params) |
| 1600 | { |
| 1601 | PTPContainer ptp; |
| 1602 | |
| 1603 | PTP_CNT_INIT(ptp); |
| 1604 | ptp.Code=PTP_OC_CANON_ViewfinderOn; |
| 1605 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1606 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | /** |
| 1610 | * ptp_canon_viewfinderoff: |
| 1611 | * params: PTPParams* |
| 1612 | * |
| 1613 | * Before changing the shooting mode, or when one doesn't need to read |
| 1614 | * viewfinder images any more, one must call this operation. |
| 1615 | * Supposedly, this operation affects the value of the CANON_ViewfinderMode |
| 1616 | * property. |
| 1617 | * |
| 1618 | * Return values: Some PTP_RC_* code. |
| 1619 | * |
| 1620 | **/ |
| 1621 | uint16_t |
| 1622 | ptp_canon_viewfinderoff (PTPParams* params) |
| 1623 | { |
| 1624 | PTPContainer ptp; |
| 1625 | |
| 1626 | PTP_CNT_INIT(ptp); |
| 1627 | ptp.Code=PTP_OC_CANON_ViewfinderOff; |
| 1628 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1629 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1633 | * ptp_canon_aeafawb: |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1634 | * params: PTPParams* |
| 1635 | * uint32_t p1 - Yet unknown parameter, |
| 1636 | * value 7 works |
| 1637 | * |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1638 | * Called AeAfAwb (auto exposure, focus, white balance) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1639 | * |
| 1640 | * Return values: Some PTP_RC_* code. |
| 1641 | * |
| 1642 | **/ |
| 1643 | uint16_t |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1644 | ptp_canon_aeafawb (PTPParams* params, uint32_t p1) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1645 | { |
| 1646 | PTPContainer ptp; |
| 1647 | |
| 1648 | PTP_CNT_INIT(ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1649 | ptp.Code=PTP_OC_CANON_DoAeAfAwb; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1650 | ptp.Param1=p1; |
| 1651 | ptp.Nparam=1; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1652 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | /** |
| 1657 | * ptp_canon_checkevent: |
| 1658 | * params: PTPParams* |
| 1659 | * |
| 1660 | * The camera has a FIFO stack, in which it accumulates events. |
| 1661 | * Partially these events are communicated also via the USB interrupt pipe |
| 1662 | * according to the PTP USB specification, partially not. |
| 1663 | * This operation returns from the device a block of data, empty, |
| 1664 | * if the event stack is empty, or filled with an event's data otherwise. |
| 1665 | * The event is removed from the stack in the latter case. |
| 1666 | * The Remote Capture app sends this command to the camera all the time |
| 1667 | * of connection, filling with it the gaps between other operations. |
| 1668 | * |
| 1669 | * Return values: Some PTP_RC_* code. |
| 1670 | * Upon success : PTPUSBEventContainer* event - is filled with the event data |
| 1671 | * if any |
| 1672 | * int *isevent - returns 1 in case of event |
| 1673 | * or 0 otherwise |
| 1674 | **/ |
| 1675 | uint16_t |
| 1676 | ptp_canon_checkevent (PTPParams* params, PTPUSBEventContainer* event, int* isevent) |
| 1677 | { |
| 1678 | uint16_t ret; |
| 1679 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1680 | unsigned char *evdata = NULL; |
| 1681 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1682 | |
| 1683 | *isevent=0; |
| 1684 | PTP_CNT_INIT(ptp); |
| 1685 | ptp.Code=PTP_OC_CANON_CheckEvent; |
| 1686 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1687 | len=0; |
| 1688 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &evdata, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1689 | if (evdata!=NULL) { |
| 1690 | if (ret == PTP_RC_OK) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1691 | ptp_unpack_EC(params, evdata, event, len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1692 | *isevent=1; |
| 1693 | } |
| 1694 | free(evdata); |
| 1695 | } |
| 1696 | return ret; |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | /** |
| 1701 | * ptp_canon_focuslock: |
| 1702 | * |
| 1703 | * This operation locks the focus. It is followed by the CANON_GetChanges(?) |
| 1704 | * operation in the log. |
| 1705 | * It affects the CANON_MacroMode property. |
| 1706 | * |
| 1707 | * params: PTPParams* |
| 1708 | * |
| 1709 | * Return values: Some PTP_RC_* code. |
| 1710 | * |
| 1711 | **/ |
| 1712 | uint16_t |
| 1713 | ptp_canon_focuslock (PTPParams* params) |
| 1714 | { |
| 1715 | PTPContainer ptp; |
| 1716 | |
| 1717 | PTP_CNT_INIT(ptp); |
| 1718 | ptp.Code=PTP_OC_CANON_FocusLock; |
| 1719 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1720 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * ptp_canon_focusunlock: |
| 1725 | * |
| 1726 | * This operation unlocks the focus. It is followed by the CANON_GetChanges(?) |
| 1727 | * operation in the log. |
| 1728 | * It sets the CANON_MacroMode property value to 1 (where it occurs in the log). |
| 1729 | * |
| 1730 | * params: PTPParams* |
| 1731 | * |
| 1732 | * Return values: Some PTP_RC_* code. |
| 1733 | * |
| 1734 | **/ |
| 1735 | uint16_t |
| 1736 | ptp_canon_focusunlock (PTPParams* params) |
| 1737 | { |
| 1738 | PTPContainer ptp; |
| 1739 | |
| 1740 | PTP_CNT_INIT(ptp); |
| 1741 | ptp.Code=PTP_OC_CANON_FocusUnlock; |
| 1742 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1743 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * ptp_canon_initiatecaptureinmemory: |
| 1748 | * |
| 1749 | * This operation starts the image capture according to the current camera |
| 1750 | * settings. When the capture has happened, the camera emits a CaptureComplete |
| 1751 | * event via the interrupt pipe and pushes the CANON_RequestObjectTransfer, |
| 1752 | * CANON_DeviceInfoChanged and CaptureComplete events onto the event stack |
| 1753 | * (see operation CANON_CheckEvent). From the CANON_RequestObjectTransfer |
| 1754 | * event's parameter one can learn the just captured image's ObjectHandle. |
| 1755 | * The image is stored in the camera's own RAM. |
| 1756 | * On the next capture the image will be overwritten! |
| 1757 | * |
| 1758 | * params: PTPParams* |
| 1759 | * |
| 1760 | * Return values: Some PTP_RC_* code. |
| 1761 | * |
| 1762 | **/ |
| 1763 | uint16_t |
| 1764 | ptp_canon_initiatecaptureinmemory (PTPParams* params) |
| 1765 | { |
| 1766 | PTPContainer ptp; |
| 1767 | |
| 1768 | PTP_CNT_INIT(ptp); |
| 1769 | ptp.Code=PTP_OC_CANON_InitiateCaptureInMemory; |
| 1770 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1771 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 1772 | } |
| 1773 | |
| 1774 | uint16_t |
| 1775 | ptp_canon_9012 (PTPParams* params) |
| 1776 | { |
| 1777 | PTPContainer ptp; |
| 1778 | |
| 1779 | PTP_CNT_INIT(ptp); |
| 1780 | ptp.Code=0x9012; |
| 1781 | ptp.Nparam=0; |
| 1782 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * ptp_canon_getpartialobject: |
| 1787 | * |
| 1788 | * This operation is used to read from the device a data |
| 1789 | * block of an object from a specified offset. |
| 1790 | * |
| 1791 | * params: PTPParams* |
| 1792 | * uint32_t handle - the handle of the requested object |
| 1793 | * uint32_t offset - the offset in bytes from the beginning of the object |
| 1794 | * uint32_t size - the requested size of data block to read |
| 1795 | * uint32_t pos - 1 for the first block, 2 - for a block in the middle, |
| 1796 | * 3 - for the last block |
| 1797 | * |
| 1798 | * Return values: Some PTP_RC_* code. |
| 1799 | * char **block - the pointer to the block of data read |
| 1800 | * uint32_t* readnum - the number of bytes read |
| 1801 | * |
| 1802 | **/ |
| 1803 | uint16_t |
| 1804 | ptp_canon_getpartialobject (PTPParams* params, uint32_t handle, |
| 1805 | uint32_t offset, uint32_t size, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1806 | uint32_t pos, unsigned char** block, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1807 | uint32_t* readnum) |
| 1808 | { |
| 1809 | uint16_t ret; |
| 1810 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1811 | unsigned char *data=NULL; |
| 1812 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1813 | |
| 1814 | PTP_CNT_INIT(ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1815 | ptp.Code=PTP_OC_CANON_GetPartialObjectEx; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1816 | ptp.Param1=handle; |
| 1817 | ptp.Param2=offset; |
| 1818 | ptp.Param3=size; |
| 1819 | ptp.Param4=pos; |
| 1820 | ptp.Nparam=4; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1821 | len=0; |
| 1822 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1823 | if (ret==PTP_RC_OK) { |
| 1824 | *block=data; |
| 1825 | *readnum=ptp.Param1; |
| 1826 | } |
| 1827 | return ret; |
| 1828 | } |
| 1829 | |
| 1830 | /** |
| 1831 | * ptp_canon_getviewfinderimage: |
| 1832 | * |
| 1833 | * This operation can be used to read the image which is currently |
| 1834 | * in the camera's viewfinder. The image size is 320x240, format is JPEG. |
| 1835 | * Of course, prior to calling this operation, one must turn the viewfinder |
| 1836 | * on with the CANON_ViewfinderOn command. |
| 1837 | * Invoking this operation many times, one can get live video from the camera! |
| 1838 | * |
| 1839 | * params: PTPParams* |
| 1840 | * |
| 1841 | * Return values: Some PTP_RC_* code. |
| 1842 | * char **image - the pointer to the read image |
| 1843 | * unit32_t *size - the size of the image in bytes |
| 1844 | * |
| 1845 | **/ |
| 1846 | uint16_t |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1847 | ptp_canon_getviewfinderimage (PTPParams* params, unsigned char** image, uint32_t* size) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1848 | { |
| 1849 | uint16_t ret; |
| 1850 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1851 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1852 | |
| 1853 | PTP_CNT_INIT(ptp); |
| 1854 | ptp.Code=PTP_OC_CANON_GetViewfinderImage; |
| 1855 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1856 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, image, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1857 | if (ret==PTP_RC_OK) *size=ptp.Param1; |
| 1858 | return ret; |
| 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * ptp_canon_getchanges: |
| 1863 | * |
| 1864 | * This is an interesting operation, about the effect of which I am not sure. |
| 1865 | * This command is called every time when a device property has been changed |
| 1866 | * with the SetDevicePropValue operation, and after some other operations. |
| 1867 | * This operation reads the array of Device Properties which have been changed |
| 1868 | * by the previous operation. |
| 1869 | * Probably, this operation is even required to make those changes work. |
| 1870 | * |
| 1871 | * params: PTPParams* |
| 1872 | * |
| 1873 | * Return values: Some PTP_RC_* code. |
| 1874 | * uint16_t** props - the pointer to the array of changed properties |
| 1875 | * uint32_t* propnum - the number of elements in the *props array |
| 1876 | * |
| 1877 | **/ |
| 1878 | uint16_t |
| 1879 | ptp_canon_getchanges (PTPParams* params, uint16_t** props, uint32_t* propnum) |
| 1880 | { |
| 1881 | uint16_t ret; |
| 1882 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1883 | unsigned char* data=NULL; |
| 1884 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1885 | |
| 1886 | PTP_CNT_INIT(ptp); |
| 1887 | ptp.Code=PTP_OC_CANON_GetChanges; |
| 1888 | ptp.Nparam=0; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1889 | len=0; |
| 1890 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1891 | if (ret == PTP_RC_OK) |
| 1892 | *propnum=ptp_unpack_uint16_t_array(params,data,0,props); |
| 1893 | free(data); |
| 1894 | return ret; |
| 1895 | } |
| 1896 | |
| 1897 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1898 | * ptp_canon_getobjectinfo: |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1899 | * |
| 1900 | * This command reads a specified object's record in a device's filesystem, |
| 1901 | * or the records of all objects belonging to a specified folder (association). |
| 1902 | * |
| 1903 | * params: PTPParams* |
| 1904 | * uint32_t store - StorageID, |
| 1905 | * uint32_t p2 - Yet unknown (0 value works OK) |
| 1906 | * uint32_t parent - Parent Object Handle |
| 1907 | * # If Parent Object Handle is 0xffffffff, |
| 1908 | * # the Parent Object is the top level folder. |
| 1909 | * uint32_t handle - Object Handle |
| 1910 | * # If Object Handle is 0, the records of all objects |
| 1911 | * # belonging to the Parent Object are read. |
| 1912 | * # If Object Handle is not 0, only the record of this |
| 1913 | * # Object is read. |
| 1914 | * |
| 1915 | * Return values: Some PTP_RC_* code. |
| 1916 | * PTPCANONFolderEntry** entries - the pointer to the folder entry array |
| 1917 | * uint32_t* entnum - the number of elements of the array |
| 1918 | * |
| 1919 | **/ |
| 1920 | uint16_t |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1921 | ptp_canon_getobjectinfo (PTPParams* params, uint32_t store, uint32_t p2, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1922 | uint32_t parent, uint32_t handle, |
| 1923 | PTPCANONFolderEntry** entries, uint32_t* entnum) |
| 1924 | { |
| 1925 | uint16_t ret; |
| 1926 | PTPContainer ptp; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1927 | unsigned char *data = NULL; |
| 1928 | unsigned int len; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1929 | |
| 1930 | PTP_CNT_INIT(ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1931 | ptp.Code=PTP_OC_CANON_GetObjectInfoEx; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1932 | ptp.Param1=store; |
| 1933 | ptp.Param2=p2; |
| 1934 | ptp.Param3=parent; |
| 1935 | ptp.Param4=handle; |
| 1936 | ptp.Nparam=4; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1937 | len=0; |
| 1938 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &len); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 1939 | if (ret == PTP_RC_OK) { |
| 1940 | int i; |
| 1941 | *entnum=ptp.Param1; |
| 1942 | *entries=calloc(*entnum, sizeof(PTPCANONFolderEntry)); |
| 1943 | if (*entries!=NULL) { |
| 1944 | for(i=0; i<(*entnum); i++) |
| 1945 | ptp_unpack_Canon_FE(params, |
| 1946 | data+i*PTP_CANON_FolderEntryLen, |
| 1947 | &((*entries)[i]) ); |
| 1948 | } else { |
| 1949 | ret=PTP_ERROR_IO; /* Cannot allocate memory */ |
| 1950 | } |
| 1951 | } |
| 1952 | free(data); |
| 1953 | return ret; |
| 1954 | } |
| 1955 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1956 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1957 | * ptp_canon_get_objecthandle_by_name: |
Linus Walleij | 0468fe7 | 2006-09-13 11:49:52 +0000 | [diff] [blame] | 1958 | * |
| 1959 | * This command looks up the specified object on the camera. |
| 1960 | * |
| 1961 | * Format is "A:\\PATH". |
| 1962 | * |
| 1963 | * The 'A' is the VolumeLabel from GetStorageInfo, |
| 1964 | * my IXUS has "A" for the card and "V" for internal memory. |
| 1965 | * |
| 1966 | * params: PTPParams* |
| 1967 | * char* name - path name |
| 1968 | * |
| 1969 | * Return values: Some PTP_RC_* code. |
| 1970 | * uint32_t *oid - PTP object id. |
| 1971 | * |
| 1972 | **/ |
| 1973 | uint16_t |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1974 | ptp_canon_get_objecthandle_by_name (PTPParams* params, char* name, uint32_t* objectid) |
Linus Walleij | 0468fe7 | 2006-09-13 11:49:52 +0000 | [diff] [blame] | 1975 | { |
| 1976 | uint16_t ret; |
| 1977 | PTPContainer ptp; |
| 1978 | unsigned char *data = NULL; |
| 1979 | uint8_t len; |
| 1980 | |
| 1981 | PTP_CNT_INIT (ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1982 | ptp.Code=PTP_OC_CANON_GetObjectHandleByName; |
Linus Walleij | 0468fe7 | 2006-09-13 11:49:52 +0000 | [diff] [blame] | 1983 | ptp.Nparam=0; |
| 1984 | len=0; |
| 1985 | data = malloc (2*(strlen(name)+1)+2); |
| 1986 | memset (data, 0, 2*(strlen(name)+1)+2); |
| 1987 | ptp_pack_string (params, name, data, 0, &len); |
| 1988 | ret=ptp_transaction (params, &ptp, PTP_DP_SENDDATA, (len+1)*2+1, &data, NULL); |
| 1989 | free (data); |
| 1990 | *objectid = ptp.Param1; |
| 1991 | return ret; |
| 1992 | } |
| 1993 | |
| 1994 | /** |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 1995 | * ptp_canon_get_customize_data: |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 1996 | * |
| 1997 | * This command downloads the specified theme slot, including jpegs |
| 1998 | * and wav files. |
| 1999 | * |
| 2000 | * params: PTPParams* |
| 2001 | * uint32_t themenr - nr of theme |
| 2002 | * |
| 2003 | * Return values: Some PTP_RC_* code. |
| 2004 | * unsigned char **data - pointer to data pointer |
| 2005 | * unsigned int *size - size of data returned |
| 2006 | * |
| 2007 | **/ |
| 2008 | uint16_t |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 2009 | ptp_canon_get_customize_data (PTPParams* params, uint32_t themenr, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2010 | unsigned char **data, unsigned int *size) |
| 2011 | { |
| 2012 | PTPContainer ptp; |
| 2013 | |
| 2014 | *data = NULL; |
| 2015 | *size = 0; |
| 2016 | PTP_CNT_INIT(ptp); |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 2017 | ptp.Code = PTP_OC_CANON_GetCustomizeData; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2018 | ptp.Param1 = themenr; |
| 2019 | ptp.Nparam = 1; |
| 2020 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 2021 | } |
| 2022 | |
| 2023 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2024 | uint16_t |
| 2025 | ptp_nikon_curve_download (PTPParams* params, unsigned char **data, unsigned int *size) { |
| 2026 | PTPContainer ptp; |
| 2027 | *data = NULL; |
| 2028 | *size = 0; |
| 2029 | PTP_CNT_INIT(ptp); |
| 2030 | ptp.Code = PTP_OC_NIKON_CurveDownload; |
| 2031 | ptp.Nparam = 0; |
| 2032 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 2033 | } |
| 2034 | |
| 2035 | uint16_t |
| 2036 | ptp_nikon_getfileinfoinblock ( PTPParams* params, |
| 2037 | uint32_t p1, uint32_t p2, uint32_t p3, |
| 2038 | unsigned char **data, unsigned int *size |
| 2039 | ) { |
| 2040 | PTPContainer ptp; |
| 2041 | *data = NULL; |
| 2042 | *size = 0; |
| 2043 | PTP_CNT_INIT(ptp); |
| 2044 | ptp.Code = PTP_OC_NIKON_GetFileInfoInBlock; |
| 2045 | ptp.Nparam = 3; |
| 2046 | ptp.Param1 = p1; |
| 2047 | ptp.Param2 = p2; |
| 2048 | ptp.Param3 = p3; |
| 2049 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 2050 | } |
| 2051 | |
| 2052 | /** |
| 2053 | * ptp_nikon_setcontrolmode: |
| 2054 | * |
| 2055 | * This command can switch the camera to full PC control mode. |
| 2056 | * |
| 2057 | * params: PTPParams* |
| 2058 | * uint32_t mode - mode |
| 2059 | * |
| 2060 | * Return values: Some PTP_RC_* code. |
| 2061 | * |
| 2062 | **/ |
| 2063 | uint16_t |
| 2064 | ptp_nikon_setcontrolmode (PTPParams* params, uint32_t mode) |
| 2065 | { |
| 2066 | PTPContainer ptp; |
| 2067 | |
| 2068 | PTP_CNT_INIT(ptp); |
| 2069 | ptp.Code=PTP_OC_NIKON_SetControlMode; |
| 2070 | ptp.Param1=mode; |
| 2071 | ptp.Nparam=1; |
| 2072 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 2073 | } |
| 2074 | |
| 2075 | /** |
| 2076 | * ptp_nikon_capture: |
| 2077 | * |
| 2078 | * This command captures a picture on the Nikon. |
| 2079 | * |
| 2080 | * params: PTPParams* |
| 2081 | * uint32_t x - unknown parameter. seen to be -1. |
| 2082 | * |
| 2083 | * Return values: Some PTP_RC_* code. |
| 2084 | * |
| 2085 | **/ |
| 2086 | uint16_t |
| 2087 | ptp_nikon_capture (PTPParams* params, uint32_t x) |
| 2088 | { |
| 2089 | PTPContainer ptp; |
| 2090 | |
| 2091 | PTP_CNT_INIT(ptp); |
| 2092 | ptp.Code=PTP_OC_NIKON_Capture; |
| 2093 | ptp.Param1=x; |
| 2094 | ptp.Nparam=1; |
| 2095 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * ptp_nikon_check_event: |
| 2100 | * |
| 2101 | * This command checks the event queue on the Nikon. |
| 2102 | * |
| 2103 | * params: PTPParams* |
| 2104 | * PTPUSBEventContainer **event - list of usb events. |
| 2105 | * int *evtcnt - number of usb events in event structure. |
| 2106 | * |
| 2107 | * Return values: Some PTP_RC_* code. |
| 2108 | * |
| 2109 | **/ |
| 2110 | uint16_t |
| 2111 | ptp_nikon_check_event (PTPParams* params, PTPUSBEventContainer** event, int* evtcnt) |
| 2112 | { |
| 2113 | PTPContainer ptp; |
| 2114 | uint16_t ret; |
| 2115 | unsigned char *data = NULL; |
| 2116 | unsigned int size = 0; |
| 2117 | |
| 2118 | PTP_CNT_INIT(ptp); |
| 2119 | ptp.Code=PTP_OC_NIKON_CheckEvent; |
| 2120 | ptp.Nparam=0; |
| 2121 | *evtcnt = 0; |
| 2122 | ret = ptp_transaction (params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 2123 | if (ret == PTP_RC_OK) { |
| 2124 | ptp_unpack_Nikon_EC (params, data, size, event, evtcnt); |
| 2125 | free (data); |
| 2126 | } |
| 2127 | return ret; |
| 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * ptp_nikon_device_ready: |
| 2132 | * |
| 2133 | * This command checks if the device is ready. Used after |
| 2134 | * a capture. |
| 2135 | * |
| 2136 | * params: PTPParams* |
| 2137 | * |
| 2138 | * Return values: Some PTP_RC_* code. |
| 2139 | * |
| 2140 | **/ |
| 2141 | uint16_t |
| 2142 | ptp_nikon_device_ready (PTPParams* params) |
| 2143 | { |
| 2144 | PTPContainer ptp; |
| 2145 | |
| 2146 | PTP_CNT_INIT(ptp); |
| 2147 | ptp.Code=PTP_OC_NIKON_DeviceReady; |
| 2148 | ptp.Nparam=0; |
| 2149 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 2150 | } |
| 2151 | |
| 2152 | /** |
| 2153 | * ptp_nikon_getptpipinfo: |
| 2154 | * |
| 2155 | * This command gets the ptpip info data. |
| 2156 | * |
| 2157 | * params: PTPParams* |
| 2158 | * unsigned char *data - data |
| 2159 | * unsigned int size - size of returned data |
| 2160 | * |
| 2161 | * Return values: Some PTP_RC_* code. |
| 2162 | * |
| 2163 | **/ |
| 2164 | uint16_t |
| 2165 | ptp_nikon_getptpipinfo (PTPParams* params, unsigned char **data, unsigned int *size) |
| 2166 | { |
| 2167 | PTPContainer ptp; |
| 2168 | |
| 2169 | PTP_CNT_INIT(ptp); |
| 2170 | ptp.Code=PTP_OC_NIKON_GetDevicePTPIPInfo; |
| 2171 | ptp.Nparam=0; |
| 2172 | return ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, data, size); |
| 2173 | } |
| 2174 | |
| 2175 | /** |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2176 | * ptp_nikon_getwifiprofilelist: |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2177 | * |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2178 | * This command gets the wifi profile list. |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2179 | * |
| 2180 | * params: PTPParams* |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2181 | * |
| 2182 | * Return values: Some PTP_RC_* code. |
| 2183 | * |
| 2184 | **/ |
| 2185 | uint16_t |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2186 | ptp_nikon_getwifiprofilelist (PTPParams* params) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2187 | { |
| 2188 | PTPContainer ptp; |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2189 | unsigned char* data; |
| 2190 | unsigned int size; |
| 2191 | unsigned int pos; |
| 2192 | unsigned int profn; |
| 2193 | unsigned int n; |
| 2194 | char* buffer; |
| 2195 | uint8_t len; |
| 2196 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2197 | PTP_CNT_INIT(ptp); |
| 2198 | ptp.Code=PTP_OC_NIKON_GetProfileAllData; |
| 2199 | ptp.Nparam=0; |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2200 | size = 0; |
| 2201 | data = NULL; |
| 2202 | CHECK_PTP_RC(ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size)); |
| 2203 | |
| 2204 | if (size < 2) return PTP_RC_Undefined; /* FIXME: Add more precise error code */ |
| 2205 | |
| 2206 | params->wifi_profiles_version = data[0]; |
| 2207 | params->wifi_profiles_number = data[1]; |
| 2208 | if (params->wifi_profiles) |
| 2209 | free(params->wifi_profiles); |
| 2210 | |
| 2211 | params->wifi_profiles = malloc(params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile)); |
| 2212 | memset(params->wifi_profiles, 0, params->wifi_profiles_number*sizeof(PTPNIKONWifiProfile)); |
| 2213 | |
| 2214 | pos = 2; |
| 2215 | profn = 0; |
| 2216 | while (profn < params->wifi_profiles_number && pos < size) { |
| 2217 | if (pos+6 >= size) return PTP_RC_Undefined; |
| 2218 | params->wifi_profiles[profn].id = data[pos++]; |
| 2219 | params->wifi_profiles[profn].valid = data[pos++]; |
| 2220 | |
| 2221 | n = dtoh32a(&data[pos]); |
| 2222 | pos += 4; |
| 2223 | if (pos+n+4 >= size) return PTP_RC_Undefined; |
| 2224 | strncpy(params->wifi_profiles[profn].profile_name, (char*)&data[pos], n); |
| 2225 | params->wifi_profiles[profn].profile_name[16] = '\0'; |
| 2226 | pos += n; |
| 2227 | |
| 2228 | params->wifi_profiles[profn].display_order = data[pos++]; |
| 2229 | params->wifi_profiles[profn].device_type = data[pos++]; |
| 2230 | params->wifi_profiles[profn].icon_type = data[pos++]; |
| 2231 | |
| 2232 | buffer = ptp_unpack_string(params, data, pos, &len); |
| 2233 | strncpy(params->wifi_profiles[profn].creation_date, buffer, sizeof(params->wifi_profiles[profn].creation_date)); |
| 2234 | pos += (len*2+1); |
| 2235 | if (pos+1 >= size) return PTP_RC_Undefined; |
| 2236 | /* FIXME: check if it is really last usage date */ |
| 2237 | buffer = ptp_unpack_string(params, data, pos, &len); |
| 2238 | strncpy(params->wifi_profiles[profn].lastusage_date, buffer, sizeof(params->wifi_profiles[profn].lastusage_date)); |
| 2239 | pos += (len*2+1); |
| 2240 | if (pos+5 >= size) return PTP_RC_Undefined; |
| 2241 | |
| 2242 | n = dtoh32a(&data[pos]); |
| 2243 | pos += 4; |
| 2244 | if (pos+n >= size) return PTP_RC_Undefined; |
| 2245 | strncpy(params->wifi_profiles[profn].essid, (char*)&data[pos], n); |
| 2246 | params->wifi_profiles[profn].essid[32] = '\0'; |
| 2247 | pos += n; |
| 2248 | pos += 1; |
| 2249 | profn++; |
| 2250 | } |
| 2251 | |
| 2252 | #if 0 |
| 2253 | PTPNIKONWifiProfile test; |
| 2254 | memset(&test, 0, sizeof(PTPNIKONWifiProfile)); |
| 2255 | strcpy(test.profile_name, "MyTest"); |
| 2256 | test.icon_type = 1; |
| 2257 | strcpy(test.essid, "nikon"); |
| 2258 | test.ip_address = 10 + 11 << 16 + 11 << 24; |
| 2259 | test.subnet_mask = 24; |
| 2260 | test.access_mode = 1; |
| 2261 | test.wifi_channel = 1; |
| 2262 | test.key_nr = 1; |
| 2263 | |
| 2264 | ptp_nikon_writewifiprofile(params, &test); |
| 2265 | #endif |
| 2266 | |
| 2267 | return PTP_RC_OK; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /** |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2271 | * ptp_nikon_deletewifiprofile: |
| 2272 | * |
| 2273 | * This command deletes a wifi profile. |
| 2274 | * |
| 2275 | * params: PTPParams* |
| 2276 | * unsigned int profilenr - profile number |
| 2277 | * |
| 2278 | * Return values: Some PTP_RC_* code. |
| 2279 | * |
| 2280 | **/ |
| 2281 | uint16_t |
| 2282 | ptp_nikon_deletewifiprofile (PTPParams* params, uint32_t profilenr) |
| 2283 | { |
| 2284 | PTPContainer ptp; |
| 2285 | |
| 2286 | PTP_CNT_INIT(ptp); |
| 2287 | ptp.Code=PTP_OC_NIKON_DeleteProfile; |
| 2288 | ptp.Nparam=1; |
| 2289 | ptp.Param1=profilenr; |
| 2290 | return ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL); |
| 2291 | } |
| 2292 | |
| 2293 | /** |
| 2294 | * ptp_nikon_writewifiprofile: |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2295 | * |
| 2296 | * This command gets the ptpip info data. |
| 2297 | * |
| 2298 | * params: PTPParams* |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2299 | * unsigned int profilenr - profile number |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2300 | * unsigned char *data - data |
| 2301 | * unsigned int size - size of returned data |
| 2302 | * |
| 2303 | * Return values: Some PTP_RC_* code. |
| 2304 | * |
| 2305 | **/ |
| 2306 | uint16_t |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2307 | ptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* profile) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2308 | { |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 2309 | unsigned char guid[16]; |
| 2310 | |
| 2311 | PTPContainer ptp; |
| 2312 | unsigned char buffer[1024]; |
| 2313 | unsigned char* data = buffer; |
| 2314 | int size = 0; |
| 2315 | int i; |
| 2316 | uint8_t len; |
| 2317 | int profilenr = -1; |
| 2318 | |
| 2319 | ptp_nikon_getptpipguid(guid); |
| 2320 | |
| 2321 | if (!params->wifi_profiles) |
| 2322 | CHECK_PTP_RC(ptp_nikon_getwifiprofilelist(params)); |
| 2323 | |
| 2324 | for (i = 0; i < params->wifi_profiles_number; i++) { |
| 2325 | if (!params->wifi_profiles[i].valid) { |
| 2326 | profilenr = params->wifi_profiles[i].id; |
| 2327 | break; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | if (profilenr == -1) { |
| 2332 | /* No free profile! */ |
| 2333 | return PTP_RC_StoreFull; |
| 2334 | } |
| 2335 | |
| 2336 | memset(buffer, 0, 1024); |
| 2337 | |
| 2338 | buffer[0x00] = 0x64; /* Version */ |
| 2339 | |
| 2340 | /* Profile name */ |
| 2341 | htod32a(&buffer[0x01], 17); |
| 2342 | /* 16 as third parameter, so there will always be a null-byte in the end */ |
| 2343 | strncpy((char*)&buffer[0x05], profile->profile_name, 16); |
| 2344 | |
| 2345 | buffer[0x16] = 0x00; /* Display order */ |
| 2346 | buffer[0x17] = profile->device_type; |
| 2347 | buffer[0x18] = profile->icon_type; |
| 2348 | |
| 2349 | /* FIXME: Creation date: put a real date here */ |
| 2350 | ptp_pack_string(params, "19990909T090909", data, 0x19, &len); |
| 2351 | |
| 2352 | /* IP parameters */ |
| 2353 | *((unsigned int*)&buffer[0x3A]) = profile->ip_address; /* Do not reverse bytes */ |
| 2354 | buffer[0x3E] = profile->subnet_mask; |
| 2355 | *((unsigned int*)&buffer[0x3F]) = profile->gateway_address; /* Do not reverse bytes */ |
| 2356 | buffer[0x43] = profile->address_mode; |
| 2357 | |
| 2358 | /* Wifi parameters */ |
| 2359 | buffer[0x44] = profile->access_mode; |
| 2360 | buffer[0x45] = profile->wifi_channel; |
| 2361 | |
| 2362 | htod32a(&buffer[0x46], 33); /* essid */ |
| 2363 | /* 32 as third parameter, so there will always be a null-byte in the end */ |
| 2364 | strncpy((char*)&buffer[0x4A], profile->essid, 32); |
| 2365 | |
| 2366 | buffer[0x6B] = profile->authentification; |
| 2367 | buffer[0x6C] = profile->encryption; |
| 2368 | htod32a(&buffer[0x6D], 64); |
| 2369 | for (i = 0; i < 64; i++) { |
| 2370 | buffer[0x71+i] = profile->key[i]; |
| 2371 | } |
| 2372 | buffer[0xB1] = profile->key_nr; |
| 2373 | memcpy(&buffer[0xB2], guid, 16); |
| 2374 | |
| 2375 | switch(profile->encryption) { |
| 2376 | case 1: /* WEP 64bit */ |
| 2377 | htod16a(&buffer[0xC2], 5); /* (64-24)/8 = 5 */ |
| 2378 | break; |
| 2379 | case 2: /* WEP 128bit */ |
| 2380 | htod16a(&buffer[0xC2], 13); /* (128-24)/8 = 13 */ |
| 2381 | break; |
| 2382 | default: |
| 2383 | htod16a(&buffer[0xC2], 0); |
| 2384 | } |
| 2385 | size = 0xC4; |
| 2386 | |
| 2387 | PTP_CNT_INIT(ptp); |
| 2388 | ptp.Code=PTP_OC_NIKON_SendProfileData; |
| 2389 | ptp.Nparam=1; |
| 2390 | ptp.Param1=profilenr; |
| 2391 | return ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | /** |
| 2395 | * ptp_mtp_getobjectpropssupported: |
| 2396 | * |
| 2397 | * This command gets the object properties possible from the device. |
| 2398 | * |
| 2399 | * params: PTPParams* |
| 2400 | * uint ofc - object format code |
| 2401 | * unsigned int *propnum - number of elements in returned array |
| 2402 | * uint16_t *props - array of supported properties |
| 2403 | * |
| 2404 | * Return values: Some PTP_RC_* code. |
| 2405 | * |
| 2406 | **/ |
| 2407 | uint16_t |
| 2408 | ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc, |
| 2409 | uint32_t *propnum, uint16_t **props |
| 2410 | ) { |
| 2411 | PTPContainer ptp; |
| 2412 | uint16_t ret; |
| 2413 | unsigned char *data = NULL; |
| 2414 | unsigned int size = 0; |
| 2415 | |
| 2416 | PTP_CNT_INIT(ptp); |
| 2417 | ptp.Code=PTP_OC_MTP_GetObjectPropsSupported; |
| 2418 | ptp.Nparam = 1; |
| 2419 | ptp.Param1 = ofc; |
| 2420 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 2421 | if (ret == PTP_RC_OK) |
| 2422 | *propnum=ptp_unpack_uint16_t_array(params,data,0,props); |
| 2423 | free(data); |
| 2424 | return ret; |
| 2425 | } |
| 2426 | |
| 2427 | /** |
| 2428 | * ptp_mtp_getobjectpropdesc: |
| 2429 | * |
| 2430 | * This command gets the object property description. |
| 2431 | * |
| 2432 | * params: PTPParams* |
| 2433 | * uint16_t opc - object property code |
| 2434 | * uint16_t ofc - object format code |
| 2435 | * |
| 2436 | * Return values: Some PTP_RC_* code. |
| 2437 | * |
| 2438 | **/ |
| 2439 | uint16_t |
| 2440 | ptp_mtp_getobjectpropdesc ( |
| 2441 | PTPParams* params, uint16_t opc, uint16_t ofc, PTPObjectPropDesc *opd |
| 2442 | ) { |
| 2443 | PTPContainer ptp; |
| 2444 | uint16_t ret; |
| 2445 | unsigned char *data = NULL; |
| 2446 | unsigned int size = 0; |
| 2447 | |
| 2448 | PTP_CNT_INIT(ptp); |
| 2449 | ptp.Code=PTP_OC_MTP_GetObjectPropDesc; |
| 2450 | ptp.Nparam = 2; |
| 2451 | ptp.Param1 = opc; |
| 2452 | ptp.Param2 = ofc; |
| 2453 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 2454 | if (ret == PTP_RC_OK) |
| 2455 | ptp_unpack_OPD (params, data, opd, size); |
| 2456 | free(data); |
| 2457 | return ret; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * ptp_mtp_getobjectpropvalue: |
| 2462 | * |
| 2463 | * This command gets the object properties of an object handle. |
| 2464 | * |
| 2465 | * params: PTPParams* |
| 2466 | * uint32_t objectid - object format code |
| 2467 | * uint16_t opc - object prop code |
| 2468 | * |
| 2469 | * Return values: Some PTP_RC_* code. |
| 2470 | * |
| 2471 | **/ |
| 2472 | uint16_t |
| 2473 | ptp_mtp_getobjectpropvalue ( |
| 2474 | PTPParams* params, uint32_t oid, uint16_t opc, |
| 2475 | PTPPropertyValue *value, uint16_t datatype |
| 2476 | ) { |
| 2477 | PTPContainer ptp; |
| 2478 | uint16_t ret; |
| 2479 | unsigned char *data = NULL; |
| 2480 | unsigned int size = 0; |
| 2481 | int offset = 0; |
| 2482 | |
| 2483 | PTP_CNT_INIT(ptp); |
| 2484 | ptp.Code=PTP_OC_MTP_GetObjectPropValue; |
| 2485 | ptp.Nparam = 2; |
| 2486 | ptp.Param1 = oid; |
| 2487 | ptp.Param2 = opc; |
| 2488 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &data, &size); |
| 2489 | if (ret == PTP_RC_OK) |
| 2490 | ptp_unpack_DPV(params, data, &offset, size, value, datatype); |
| 2491 | free(data); |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * ptp_mtp_setobjectpropvalue: |
| 2497 | * |
| 2498 | * This command gets the object properties of an object handle. |
| 2499 | * |
| 2500 | * params: PTPParams* |
| 2501 | * uint32_t objectid - object format code |
| 2502 | * uint16_t opc - object prop code |
| 2503 | * |
| 2504 | * Return values: Some PTP_RC_* code. |
| 2505 | * |
| 2506 | **/ |
| 2507 | uint16_t |
| 2508 | ptp_mtp_setobjectpropvalue ( |
| 2509 | PTPParams* params, uint32_t oid, uint16_t opc, |
| 2510 | PTPPropertyValue *value, uint16_t datatype |
| 2511 | ) { |
| 2512 | PTPContainer ptp; |
| 2513 | uint16_t ret; |
| 2514 | unsigned char *data = NULL; |
| 2515 | unsigned int size ; |
| 2516 | |
| 2517 | PTP_CNT_INIT(ptp); |
| 2518 | ptp.Code=PTP_OC_MTP_SetObjectPropValue; |
| 2519 | ptp.Nparam = 2; |
| 2520 | ptp.Param1 = oid; |
| 2521 | ptp.Param2 = opc; |
| 2522 | size = ptp_pack_DPV(params, value, &data, datatype); |
Linus Walleij | f67bca9 | 2006-05-29 09:33:39 +0000 | [diff] [blame] | 2523 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, &data, NULL); |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2524 | free(data); |
| 2525 | return ret; |
| 2526 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2527 | |
Linus Walleij | f67bca9 | 2006-05-29 09:33:39 +0000 | [diff] [blame] | 2528 | uint16_t |
| 2529 | ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohArray, uint32_t* arraylen) |
| 2530 | { |
| 2531 | PTPContainer ptp; |
| 2532 | uint16_t ret; |
| 2533 | unsigned char* dpv=NULL; |
| 2534 | |
| 2535 | PTP_CNT_INIT(ptp); |
| 2536 | ptp.Code=PTP_OC_MTP_GetObjectReferences; |
| 2537 | ptp.Param1=handle; |
| 2538 | ptp.Nparam=1; |
| 2539 | ret=ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &dpv, NULL); |
| 2540 | if (ret == PTP_RC_OK) *arraylen = ptp_unpack_uint32_t_array(params, dpv, 0, ohArray); |
| 2541 | free(dpv); |
| 2542 | return ret; |
| 2543 | } |
| 2544 | |
| 2545 | uint16_t |
| 2546 | ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArray, uint32_t arraylen) |
| 2547 | { |
| 2548 | PTPContainer ptp; |
| 2549 | uint16_t ret; |
| 2550 | uint32_t size; |
| 2551 | unsigned char* dpv=NULL; |
| 2552 | |
| 2553 | PTP_CNT_INIT(ptp); |
| 2554 | ptp.Code = PTP_OC_MTP_SetObjectReferences; |
| 2555 | ptp.Param1 = handle; |
| 2556 | ptp.Nparam = 1; |
| 2557 | size = ptp_pack_uint32_t_array(params, ohArray, arraylen, &dpv); |
| 2558 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, size, (unsigned char **)&dpv, NULL); |
| 2559 | free(dpv); |
| 2560 | return ret; |
| 2561 | } |
| 2562 | |
Linus Walleij | 99310d4 | 2006-11-01 08:29:39 +0000 | [diff] [blame] | 2563 | uint16_t |
Linus Walleij | 3fcfea5 | 2006-11-13 07:07:36 +0000 | [diff] [blame] | 2564 | ptp_mtp_getobjectproplist (PTPParams* params, uint32_t handle, MTPPropList **proplist) |
| 2565 | { |
| 2566 | uint16_t ret; |
| 2567 | PTPContainer ptp; |
Linus Walleij | 3fcfea5 | 2006-11-13 07:07:36 +0000 | [diff] [blame] | 2568 | unsigned char* opldata = NULL; |
| 2569 | unsigned int oplsize; |
| 2570 | |
| 2571 | PTP_CNT_INIT(ptp); |
| 2572 | ptp.Code = PTP_OC_MTP_GetObjPropList; |
| 2573 | ptp.Param1 = handle; |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 2574 | ptp.Param2 = 0x00000000U; /* 0x00000000U should be "all formats" */ |
| 2575 | ptp.Param3 = 0xFFFFFFFFU; /* 0xFFFFFFFFU should be "all properties" */ |
Linus Walleij | 3fcfea5 | 2006-11-13 07:07:36 +0000 | [diff] [blame] | 2576 | ptp.Param4 = 0x00000000U; |
| 2577 | ptp.Param5 = 0x00000000U; |
| 2578 | ptp.Nparam = 5; |
Richard Low | 8d82d2f | 2006-11-16 20:37:43 +0000 | [diff] [blame] | 2579 | ret = ptp_transaction(params, &ptp, PTP_DP_GETDATA, 0, &opldata, &oplsize); |
| 2580 | if (ret == PTP_RC_OK) ptp_unpack_OPL(params, opldata, proplist, oplsize); |
Linus Walleij | 277cd53 | 2006-11-20 14:57:46 +0000 | [diff] [blame^] | 2581 | if (opldata != NULL) |
| 2582 | free(opldata); |
Linus Walleij | 3fcfea5 | 2006-11-13 07:07:36 +0000 | [diff] [blame] | 2583 | return ret; |
Linus Walleij | 3fcfea5 | 2006-11-13 07:07:36 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | uint16_t |
Linus Walleij | 99310d4 | 2006-11-01 08:29:39 +0000 | [diff] [blame] | 2587 | ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle, |
| 2588 | uint16_t objecttype, uint64_t objectsize, MTPPropList *proplist) |
| 2589 | { |
| 2590 | uint16_t ret; |
| 2591 | PTPContainer ptp; |
| 2592 | int old_split_header_data; |
| 2593 | unsigned char* opldata=NULL; |
| 2594 | uint32_t oplsize; |
| 2595 | |
| 2596 | PTP_CNT_INIT(ptp); |
| 2597 | ptp.Code = PTP_OC_MTP_SendObjectPropList; |
| 2598 | ptp.Param1 = *store; |
| 2599 | ptp.Param2 = *parenthandle; |
| 2600 | ptp.Param3 = (uint32_t) objecttype; |
| 2601 | ptp.Param4 = (uint32_t) (objectsize >> 32); |
| 2602 | ptp.Param5 = (uint32_t) (objectsize & 0xffffffffU); |
| 2603 | ptp.Nparam = 5; |
| 2604 | |
| 2605 | /* Temporary disable split headers */ |
| 2606 | old_split_header_data = params->split_header_data; |
| 2607 | params->split_header_data = 0; |
| 2608 | |
| 2609 | /* Set object handle to 0 for a new object */ |
| 2610 | oplsize = ptp_pack_OPL(params,proplist,&opldata,*handle); |
| 2611 | ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL); |
| 2612 | free(opldata); |
| 2613 | *store = ptp.Param1; |
| 2614 | *parenthandle = ptp.Param2; |
| 2615 | *handle = ptp.Param3; |
| 2616 | |
| 2617 | /* Restore split headers */ |
| 2618 | params->split_header_data = old_split_header_data; |
| 2619 | |
| 2620 | return ret; |
| 2621 | } |
| 2622 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2623 | /* Non PTP protocol functions */ |
| 2624 | /* devinfo testing functions */ |
| 2625 | |
| 2626 | int |
| 2627 | ptp_operation_issupported(PTPParams* params, uint16_t operation) |
| 2628 | { |
| 2629 | int i=0; |
| 2630 | |
| 2631 | for (;i<params->deviceinfo.OperationsSupported_len;i++) { |
| 2632 | if (params->deviceinfo.OperationsSupported[i]==operation) |
| 2633 | return 1; |
| 2634 | } |
| 2635 | return 0; |
| 2636 | } |
| 2637 | |
| 2638 | |
| 2639 | int |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2640 | ptp_event_issupported(PTPParams* params, uint16_t event) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2641 | { |
| 2642 | int i=0; |
| 2643 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2644 | for (;i<params->deviceinfo.EventsSupported_len;i++) { |
| 2645 | if (params->deviceinfo.EventsSupported[i]==event) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2646 | return 1; |
| 2647 | } |
| 2648 | return 0; |
| 2649 | } |
| 2650 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2651 | |
| 2652 | int |
| 2653 | ptp_property_issupported(PTPParams* params, uint16_t property) |
| 2654 | { |
| 2655 | int i=0; |
| 2656 | |
| 2657 | for (;i<params->deviceinfo.DevicePropertiesSupported_len;i++) |
| 2658 | if (params->deviceinfo.DevicePropertiesSupported[i]==property) |
| 2659 | return 1; |
| 2660 | return 0; |
| 2661 | } |
| 2662 | |
| 2663 | /* ptp structures freeing functions */ |
| 2664 | void |
| 2665 | ptp_free_devicepropvalue(uint16_t dt, PTPPropertyValue* dpd) { |
| 2666 | switch (dt) { |
| 2667 | case PTP_DTC_INT8: case PTP_DTC_UINT8: |
| 2668 | case PTP_DTC_UINT16: case PTP_DTC_INT16: |
| 2669 | case PTP_DTC_UINT32: case PTP_DTC_INT32: |
| 2670 | case PTP_DTC_UINT64: case PTP_DTC_INT64: |
| 2671 | case PTP_DTC_UINT128: case PTP_DTC_INT128: |
| 2672 | /* Nothing to free */ |
| 2673 | break; |
| 2674 | case PTP_DTC_AINT8: case PTP_DTC_AUINT8: |
| 2675 | case PTP_DTC_AUINT16: case PTP_DTC_AINT16: |
| 2676 | case PTP_DTC_AUINT32: case PTP_DTC_AINT32: |
| 2677 | case PTP_DTC_AUINT64: case PTP_DTC_AINT64: |
| 2678 | case PTP_DTC_AUINT128: case PTP_DTC_AINT128: |
| 2679 | if (dpd->a.v) |
| 2680 | free(dpd->a.v); |
| 2681 | break; |
| 2682 | case PTP_DTC_STR: |
| 2683 | if (dpd->str) |
| 2684 | free(dpd->str); |
| 2685 | break; |
| 2686 | } |
| 2687 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2688 | |
| 2689 | void |
| 2690 | ptp_free_devicepropdesc(PTPDevicePropDesc* dpd) |
| 2691 | { |
| 2692 | uint16_t i; |
| 2693 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2694 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FactoryDefaultValue); |
| 2695 | ptp_free_devicepropvalue (dpd->DataType, &dpd->CurrentValue); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2696 | switch (dpd->FormFlag) { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2697 | case PTP_DPFF_Range: |
| 2698 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MinimumValue); |
| 2699 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.MaximumValue); |
| 2700 | ptp_free_devicepropvalue (dpd->DataType, &dpd->FORM.Range.StepSize); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2701 | break; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2702 | case PTP_DPFF_Enumeration: |
| 2703 | if (dpd->FORM.Enum.SupportedValue) { |
| 2704 | for (i=0;i<dpd->FORM.Enum.NumberOfValues;i++) |
| 2705 | ptp_free_devicepropvalue (dpd->DataType, dpd->FORM.Enum.SupportedValue+i); |
| 2706 | free (dpd->FORM.Enum.SupportedValue); |
| 2707 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2711 | void |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2712 | ptp_free_objectpropdesc(PTPObjectPropDesc* opd) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2713 | { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2714 | uint16_t i; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2715 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2716 | ptp_free_devicepropvalue (opd->DataType, &opd->FactoryDefaultValue); |
| 2717 | switch (opd->FormFlag) { |
| 2718 | case PTP_OPFF_None: |
| 2719 | break; |
| 2720 | case PTP_OPFF_Range: |
| 2721 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MinimumValue); |
| 2722 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.MaximumValue); |
| 2723 | ptp_free_devicepropvalue (opd->DataType, &opd->FORM.Range.StepSize); |
| 2724 | break; |
| 2725 | case PTP_OPFF_Enumeration: |
| 2726 | if (opd->FORM.Enum.SupportedValue) { |
| 2727 | for (i=0;i<opd->FORM.Enum.NumberOfValues;i++) |
| 2728 | ptp_free_devicepropvalue (opd->DataType, opd->FORM.Enum.SupportedValue+i); |
| 2729 | free (opd->FORM.Enum.SupportedValue); |
| 2730 | } |
| 2731 | default: |
| 2732 | fprintf (stderr, "Unknown OPFF type %d\n", opd->FormFlag); |
| 2733 | break; |
| 2734 | } |
| 2735 | } |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2736 | |
| 2737 | void |
| 2738 | ptp_perror(PTPParams* params, uint16_t error) { |
| 2739 | |
| 2740 | int i; |
| 2741 | /* PTP error descriptions */ |
| 2742 | static struct { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2743 | short n; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2744 | const char *txt; |
| 2745 | } ptp_errors[] = { |
| 2746 | {PTP_RC_Undefined, N_("PTP: Undefined Error")}, |
| 2747 | {PTP_RC_OK, N_("PTP: OK!")}, |
| 2748 | {PTP_RC_GeneralError, N_("PTP: General Error")}, |
| 2749 | {PTP_RC_SessionNotOpen, N_("PTP: Session Not Open")}, |
| 2750 | {PTP_RC_InvalidTransactionID, N_("PTP: Invalid Transaction ID")}, |
| 2751 | {PTP_RC_OperationNotSupported, N_("PTP: Operation Not Supported")}, |
| 2752 | {PTP_RC_ParameterNotSupported, N_("PTP: Parameter Not Supported")}, |
| 2753 | {PTP_RC_IncompleteTransfer, N_("PTP: Incomplete Transfer")}, |
| 2754 | {PTP_RC_InvalidStorageId, N_("PTP: Invalid Storage ID")}, |
| 2755 | {PTP_RC_InvalidObjectHandle, N_("PTP: Invalid Object Handle")}, |
| 2756 | {PTP_RC_DevicePropNotSupported, N_("PTP: Device Prop Not Supported")}, |
| 2757 | {PTP_RC_InvalidObjectFormatCode, N_("PTP: Invalid Object Format Code")}, |
| 2758 | {PTP_RC_StoreFull, N_("PTP: Store Full")}, |
| 2759 | {PTP_RC_ObjectWriteProtected, N_("PTP: Object Write Protected")}, |
| 2760 | {PTP_RC_StoreReadOnly, N_("PTP: Store Read Only")}, |
| 2761 | {PTP_RC_AccessDenied, N_("PTP: Access Denied")}, |
| 2762 | {PTP_RC_NoThumbnailPresent, N_("PTP: No Thumbnail Present")}, |
| 2763 | {PTP_RC_SelfTestFailed, N_("PTP: Self Test Failed")}, |
| 2764 | {PTP_RC_PartialDeletion, N_("PTP: Partial Deletion")}, |
| 2765 | {PTP_RC_StoreNotAvailable, N_("PTP: Store Not Available")}, |
| 2766 | {PTP_RC_SpecificationByFormatUnsupported, |
| 2767 | N_("PTP: Specification By Format Unsupported")}, |
| 2768 | {PTP_RC_NoValidObjectInfo, N_("PTP: No Valid Object Info")}, |
| 2769 | {PTP_RC_InvalidCodeFormat, N_("PTP: Invalid Code Format")}, |
| 2770 | {PTP_RC_UnknownVendorCode, N_("PTP: Unknown Vendor Code")}, |
| 2771 | {PTP_RC_CaptureAlreadyTerminated, |
| 2772 | N_("PTP: Capture Already Terminated")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2773 | {PTP_RC_DeviceBusy, N_("PTP: Device Busy")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2774 | {PTP_RC_InvalidParentObject, N_("PTP: Invalid Parent Object")}, |
| 2775 | {PTP_RC_InvalidDevicePropFormat, N_("PTP: Invalid Device Prop Format")}, |
| 2776 | {PTP_RC_InvalidDevicePropValue, N_("PTP: Invalid Device Prop Value")}, |
| 2777 | {PTP_RC_InvalidParameter, N_("PTP: Invalid Parameter")}, |
| 2778 | {PTP_RC_SessionAlreadyOpened, N_("PTP: Session Already Opened")}, |
| 2779 | {PTP_RC_TransactionCanceled, N_("PTP: Transaction Canceled")}, |
| 2780 | {PTP_RC_SpecificationOfDestinationUnsupported, |
| 2781 | N_("PTP: Specification Of Destination Unsupported")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2782 | {PTP_RC_EK_FilenameRequired, N_("PTP: EK Filename Required")}, |
| 2783 | {PTP_RC_EK_FilenameConflicts, N_("PTP: EK Filename Conflicts")}, |
| 2784 | {PTP_RC_EK_FilenameInvalid, N_("PTP: EK Filename Invalid")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2785 | |
| 2786 | {PTP_ERROR_IO, N_("PTP: I/O error")}, |
| 2787 | {PTP_ERROR_BADPARAM, N_("PTP: Error: bad parameter")}, |
| 2788 | {PTP_ERROR_DATA_EXPECTED, N_("PTP: Protocol error, data expected")}, |
| 2789 | {PTP_ERROR_RESP_EXPECTED, N_("PTP: Protocol error, response expected")}, |
| 2790 | {0, NULL} |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2791 | }; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2792 | |
| 2793 | for (i=0; ptp_errors[i].txt!=NULL; i++) |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2794 | if (ptp_errors[i].n == error) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2795 | ptp_error(params, ptp_errors[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2798 | const char* |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2799 | ptp_get_property_description(PTPParams* params, uint16_t dpc) |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2800 | { |
| 2801 | int i; |
Linus Walleij | a823a70 | 2006-08-27 21:27:46 +0000 | [diff] [blame] | 2802 | /* Device Property descriptions */ |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2803 | struct { |
| 2804 | uint16_t dpc; |
| 2805 | const char *txt; |
| 2806 | } ptp_device_properties[] = { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2807 | {PTP_DPC_Undefined, N_("Undefined PTP Property")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2808 | {PTP_DPC_BatteryLevel, N_("Battery Level")}, |
| 2809 | {PTP_DPC_FunctionalMode, N_("Functional Mode")}, |
| 2810 | {PTP_DPC_ImageSize, N_("Image Size")}, |
| 2811 | {PTP_DPC_CompressionSetting, N_("Compression Setting")}, |
| 2812 | {PTP_DPC_WhiteBalance, N_("White Balance")}, |
| 2813 | {PTP_DPC_RGBGain, N_("RGB Gain")}, |
| 2814 | {PTP_DPC_FNumber, N_("F-Number")}, |
| 2815 | {PTP_DPC_FocalLength, N_("Focal Length")}, |
| 2816 | {PTP_DPC_FocusDistance, N_("Focus Distance")}, |
| 2817 | {PTP_DPC_FocusMode, N_("Focus Mode")}, |
| 2818 | {PTP_DPC_ExposureMeteringMode, N_("Exposure Metering Mode")}, |
| 2819 | {PTP_DPC_FlashMode, N_("Flash Mode")}, |
| 2820 | {PTP_DPC_ExposureTime, N_("Exposure Time")}, |
| 2821 | {PTP_DPC_ExposureProgramMode, N_("Exposure Program Mode")}, |
| 2822 | {PTP_DPC_ExposureIndex, |
| 2823 | N_("Exposure Index (film speed ISO)")}, |
| 2824 | {PTP_DPC_ExposureBiasCompensation, |
| 2825 | N_("Exposure Bias Compensation")}, |
| 2826 | {PTP_DPC_DateTime, N_("Date Time")}, |
| 2827 | {PTP_DPC_CaptureDelay, N_("Pre-Capture Delay")}, |
| 2828 | {PTP_DPC_StillCaptureMode, N_("Still Capture Mode")}, |
| 2829 | {PTP_DPC_Contrast, N_("Contrast")}, |
| 2830 | {PTP_DPC_Sharpness, N_("Sharpness")}, |
| 2831 | {PTP_DPC_DigitalZoom, N_("Digital Zoom")}, |
| 2832 | {PTP_DPC_EffectMode, N_("Effect Mode")}, |
| 2833 | {PTP_DPC_BurstNumber, N_("Burst Number")}, |
| 2834 | {PTP_DPC_BurstInterval, N_("Burst Interval")}, |
| 2835 | {PTP_DPC_TimelapseNumber, N_("Timelapse Number")}, |
| 2836 | {PTP_DPC_TimelapseInterval, N_("Timelapse Interval")}, |
| 2837 | {PTP_DPC_FocusMeteringMode, N_("Focus Metering Mode")}, |
| 2838 | {PTP_DPC_UploadURL, N_("Upload URL")}, |
| 2839 | {PTP_DPC_Artist, N_("Artist")}, |
| 2840 | {PTP_DPC_CopyrightInfo, N_("Copyright Info")}, |
| 2841 | {0,NULL} |
| 2842 | }; |
| 2843 | struct { |
| 2844 | uint16_t dpc; |
| 2845 | const char *txt; |
| 2846 | } ptp_device_properties_EK[] = { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2847 | {PTP_DPC_EK_ColorTemperature, N_("Color Temperature")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2848 | {PTP_DPC_EK_DateTimeStampFormat, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2849 | N_("Date Time Stamp Format")}, |
| 2850 | {PTP_DPC_EK_BeepMode, N_("Beep Mode")}, |
| 2851 | {PTP_DPC_EK_VideoOut, N_("Video Out")}, |
| 2852 | {PTP_DPC_EK_PowerSaving, N_("Power Saving")}, |
| 2853 | {PTP_DPC_EK_UI_Language, N_("UI Language")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2854 | {0,NULL} |
| 2855 | }; |
| 2856 | |
| 2857 | struct { |
| 2858 | uint16_t dpc; |
| 2859 | const char *txt; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2860 | } ptp_device_properties_Canon[] = { |
| 2861 | {PTP_DPC_CANON_BeepMode, N_("Beep Mode")}, |
| 2862 | {PTP_DPC_CANON_ViewfinderMode, N_("Viewfinder Mode")}, |
| 2863 | {PTP_DPC_CANON_ImageQuality, N_("Image Quality")}, |
| 2864 | {PTP_DPC_CANON_ImageSize, N_("Image Size")}, |
| 2865 | {PTP_DPC_CANON_FlashMode, N_("Flash Mode")}, |
| 2866 | {PTP_DPC_CANON_ShootingMode, N_("Shooting Mode")}, |
| 2867 | {PTP_DPC_CANON_MeteringMode, N_("Metering Mode")}, |
| 2868 | {PTP_DPC_CANON_AFDistance, N_("AF Distance")}, |
| 2869 | {PTP_DPC_CANON_FocusingPoint, N_("Focusing Point")}, |
| 2870 | {PTP_DPC_CANON_WhiteBalance, N_("White Balance")}, |
| 2871 | {PTP_DPC_CANON_ISOSpeed, N_("ISO Speed")}, |
| 2872 | {PTP_DPC_CANON_Aperture, N_("Aperture")}, |
| 2873 | {PTP_DPC_CANON_ShutterSpeed, N_("ShutterSpeed")}, |
| 2874 | {PTP_DPC_CANON_ExpCompensation, N_("Exposure Compensation")}, |
| 2875 | {PTP_DPC_CANON_Zoom, N_("Zoom")}, |
| 2876 | {PTP_DPC_CANON_SizeQualityMode, N_("Size Quality Mode")}, |
| 2877 | {PTP_DPC_CANON_FirmwareVersion, N_("Firmware Version")}, |
| 2878 | {PTP_DPC_CANON_CameraModel, N_("Camera Model")}, |
| 2879 | {PTP_DPC_CANON_CameraOwner, N_("Camera Owner")}, |
| 2880 | {PTP_DPC_CANON_UnixTime, N_("UNIX Time")}, |
| 2881 | {PTP_DPC_CANON_DZoomMagnification, N_("Digital Zoom Magnification")}, |
| 2882 | {PTP_DPC_CANON_PhotoEffect, N_("Photo Effect")}, |
| 2883 | {PTP_DPC_CANON_AssistLight, N_("Assist Light")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2884 | {0,NULL} |
| 2885 | }; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2886 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 2887 | struct { |
| 2888 | uint16_t dpc; |
| 2889 | const char *txt; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2890 | } ptp_device_properties_Nikon[] = { |
| 2891 | {PTP_DPC_NIKON_WhiteBalanceAutoBias, /* 0xD017 */ |
| 2892 | N_("Auto White Balance Bias")}, |
| 2893 | {PTP_DPC_NIKON_WhiteBalanceTungstenBias, /* 0xD018 */ |
| 2894 | N_("Tungsten White Balance Bias")}, |
Linus Walleij | 4f40d11 | 2006-09-21 07:44:53 +0000 | [diff] [blame] | 2895 | {PTP_DPC_NIKON_WhiteBalanceFluorescentBias, /* 0xD019 */ |
| 2896 | N_("Fluorescent White Balance Bias")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2897 | {PTP_DPC_NIKON_WhiteBalanceDaylightBias, /* 0xD01a */ |
| 2898 | N_("Daylight White Balance Bias")}, |
| 2899 | {PTP_DPC_NIKON_WhiteBalanceFlashBias, /* 0xD01b */ |
| 2900 | N_("Flash White Balance Bias")}, |
| 2901 | {PTP_DPC_NIKON_WhiteBalanceCloudyBias, /* 0xD01c */ |
| 2902 | N_("Cloudy White Balance Bias")}, |
| 2903 | {PTP_DPC_NIKON_WhiteBalanceShadeBias, /* 0xD01d */ |
| 2904 | N_("Shady White Balance Bias")}, |
| 2905 | {PTP_DPC_NIKON_WhiteBalanceColorTemperature, /* 0xD01e */ |
| 2906 | N_("White Balance Colour Temperature")}, |
| 2907 | {PTP_DPC_NIKON_ImageSharpening, /* 0xD02a */ |
| 2908 | N_("Sharpening")}, |
| 2909 | {PTP_DPC_NIKON_ToneCompensation, /* 0xD02b */ |
| 2910 | N_("Tone Compensation")}, |
| 2911 | {PTP_DPC_NIKON_ColorModel, /* 0xD02c */ |
| 2912 | N_("Color Model")}, |
| 2913 | {PTP_DPC_NIKON_HueAdjustment, /* 0xD02d */ |
| 2914 | N_("Hue Adjustment")}, |
| 2915 | {PTP_DPC_NIKON_NonCPULensDataFocalLength, /* 0xD02e */ |
| 2916 | N_("Lens Focal Length (Non CPU)")}, |
| 2917 | {PTP_DPC_NIKON_NonCPULensDataMaximumAperture, /* 0xD02f */ |
| 2918 | N_("Lens Max. Aperture (Non CPU)")}, |
| 2919 | {PTP_DPC_NIKON_CSMMenuBankSelect, /* 0xD040 */ |
| 2920 | "PTP_DPC_NIKON_CSMMenuBankSelect"}, |
| 2921 | {PTP_DPC_NIKON_MenuBankNameA, /* 0xD041 */ |
| 2922 | "PTP_DPC_NIKON_MenuBankNameA"}, |
| 2923 | {PTP_DPC_NIKON_MenuBankNameB, /* 0xD042 */ |
| 2924 | "PTP_DPC_NIKON_MenuBankNameB"}, |
| 2925 | {PTP_DPC_NIKON_MenuBankNameC, /* 0xD043 */ |
| 2926 | "PTP_DPC_NIKON_MenuBankNameC"}, |
| 2927 | {PTP_DPC_NIKON_MenuBankNameD, /* 0xD044 */ |
| 2928 | "PTP_DPC_NIKON_MenuBankNameD"}, |
| 2929 | {PTP_DPC_NIKON_A1AFCModePriority, /* 0xD048 */ |
| 2930 | "PTP_DPC_NIKON_A1AFCModePriority"}, |
| 2931 | {PTP_DPC_NIKON_A2AFSModePriority, /* 0xD049 */ |
| 2932 | "PTP_DPC_NIKON_A2AFSModePriority"}, |
| 2933 | {PTP_DPC_NIKON_A3GroupDynamicAF, /* 0xD04a */ |
| 2934 | "PTP_DPC_NIKON_A3GroupDynamicAF"}, |
| 2935 | {PTP_DPC_NIKON_A4AFActivation, /* 0xD04b */ |
| 2936 | "PTP_DPC_NIKON_A4AFActivation"}, |
| 2937 | {PTP_DPC_NIKON_A5FocusAreaIllumManualFocus, /* 0xD04c */ |
| 2938 | "PTP_DPC_NIKON_A5FocusAreaIllumManualFocus"}, |
| 2939 | {PTP_DPC_NIKON_FocusAreaIllumContinuous, /* 0xD04d */ |
| 2940 | "PTP_DPC_NIKON_FocusAreaIllumContinuous"}, |
| 2941 | {PTP_DPC_NIKON_FocusAreaIllumWhenSelected, /* 0xD04e */ |
| 2942 | "PTP_DPC_NIKON_FocusAreaIllumWhenSelected"}, |
| 2943 | {PTP_DPC_NIKON_FocusAreaWrap, /* 0xD04f */ |
| 2944 | N_("Focus Area Wrap")}, |
| 2945 | {PTP_DPC_NIKON_A7VerticalAFON, /* 0xD050 */ |
| 2946 | N_("Vertical AF On")}, |
| 2947 | {PTP_DPC_NIKON_ISOAuto, /* 0xD054 */ |
| 2948 | N_("Auto ISO")}, |
| 2949 | {PTP_DPC_NIKON_B2ISOStep, /* 0xD055 */ |
| 2950 | N_("ISO Step")}, |
| 2951 | {PTP_DPC_NIKON_EVStep, /* 0xD056 */ |
| 2952 | N_("Exposure Step")}, |
| 2953 | {PTP_DPC_NIKON_B4ExposureCompEv, /* 0xD057 */ |
| 2954 | N_("Exposure Compensation (EV)")}, |
| 2955 | {PTP_DPC_NIKON_ExposureCompensation, /* 0xD058 */ |
| 2956 | N_("Exposure Compensation")}, |
| 2957 | {PTP_DPC_NIKON_CenterWeightArea, /* 0xD059 */ |
| 2958 | N_("Centre Weight Area")}, |
| 2959 | {PTP_DPC_NIKON_AELockMode, /* 0xD05e */ |
| 2960 | N_("Exposure Lock")}, |
| 2961 | {PTP_DPC_NIKON_AELAFLMode, /* 0xD05f */ |
| 2962 | N_("Focus Lock")}, |
| 2963 | {PTP_DPC_NIKON_MeterOff, /* 0xD062 */ |
| 2964 | N_("Auto Meter Off Time")}, |
| 2965 | {PTP_DPC_NIKON_SelfTimer, /* 0xD063 */ |
| 2966 | N_("Self Timer Delay")}, |
| 2967 | {PTP_DPC_NIKON_MonitorOff, /* 0xD064 */ |
| 2968 | N_("LCD Off Time")}, |
| 2969 | {PTP_DPC_NIKON_D1ShootingSpeed, /* 0xD068 */ |
| 2970 | N_("Shooting Speed")}, |
| 2971 | {PTP_DPC_NIKON_D2MaximumShots, /* 0xD069 */ |
| 2972 | N_("Max. Shots")}, |
| 2973 | {PTP_DPC_NIKON_D3ExpDelayMode, /* 0xD06a */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame] | 2974 | "PTP_DPC_NIKON_D3ExpDelayMode"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2975 | {PTP_DPC_NIKON_LongExposureNoiseReduction, /* 0xD06b */ |
| 2976 | N_("Long Exposure Noise Reduction")}, |
| 2977 | {PTP_DPC_NIKON_FileNumberSequence, /* 0xD06c */ |
| 2978 | N_("File Number Sequencing")}, |
| 2979 | {PTP_DPC_NIKON_D6ControlPanelFinderRearControl, /* 0xD06d */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame] | 2980 | "PTP_DPC_NIKON_D6ControlPanelFinderRearControl"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2981 | {PTP_DPC_NIKON_ControlPanelFinderViewfinder, /* 0xD06e */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame] | 2982 | "PTP_DPC_NIKON_ControlPanelFinderViewfinder"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2983 | {PTP_DPC_NIKON_D7Illumination, /* 0xD06f */ |
Linus Walleij | d208f9c | 2006-04-27 14:16:06 +0000 | [diff] [blame] | 2984 | "PTP_DPC_NIKON_D7Illumination"}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 2985 | {PTP_DPC_NIKON_E1FlashSyncSpeed, /* 0xD074 */ |
| 2986 | N_("Flash Sync. Speed")}, |
| 2987 | {PTP_DPC_NIKON_FlashShutterSpeed, /* 0xD075 */ |
| 2988 | N_("Flash Shutter Speed")}, |
| 2989 | {PTP_DPC_NIKON_E3AAFlashMode, /* 0xD076 */ |
| 2990 | N_("Flash Mode")}, |
| 2991 | {PTP_DPC_NIKON_E4ModelingFlash, /* 0xD077 */ |
| 2992 | N_("Modeling Flash")}, |
| 2993 | {PTP_DPC_NIKON_BracketSet, /* 0xD078 */ |
| 2994 | N_("Bracket Set")}, |
| 2995 | {PTP_DPC_NIKON_E6ManualModeBracketing, /* 0xD079 */ |
| 2996 | N_("Manual Mode Bracketing")}, |
| 2997 | {PTP_DPC_NIKON_BracketOrder, /* 0xD07a */ |
| 2998 | N_("Bracket Order")}, |
| 2999 | {PTP_DPC_NIKON_E8AutoBracketSelection, /* 0xD07b */ |
| 3000 | N_("Auto Bracket Selection")}, |
| 3001 | {PTP_DPC_NIKON_F1CenterButtonShootingMode, /* 0xD080 */ |
| 3002 | N_("Center Button Shooting Mode")}, |
| 3003 | {PTP_DPC_NIKON_CenterButtonPlaybackMode, /* 0xD081 */ |
| 3004 | N_("Center Button Playback Mode")}, |
| 3005 | {PTP_DPC_NIKON_F2Multiselector, /* 0xD082 */ |
| 3006 | N_("Multiselector")}, |
| 3007 | {PTP_DPC_NIKON_F3PhotoInfoPlayback, /* 0xD083 */ |
| 3008 | N_("Photo Info. Playback")}, |
| 3009 | {PTP_DPC_NIKON_F4AssignFuncButton, /* 0xD084 */ |
| 3010 | N_("Assign Func. Button")}, |
| 3011 | {PTP_DPC_NIKON_F5CustomizeCommDials, /* 0xD085 */ |
| 3012 | N_("Customise Command Dials")}, |
| 3013 | {PTP_DPC_NIKON_ReverseCommandDial, /* 0xD086 */ |
| 3014 | N_("Reverse Command Dial")}, |
| 3015 | {PTP_DPC_NIKON_ApertureSetting, /* 0xD087 */ |
| 3016 | N_("Aperture Setting")}, |
| 3017 | {PTP_DPC_NIKON_MenusAndPlayback, /* 0xD088 */ |
| 3018 | N_("Menus and Playback")}, |
| 3019 | {PTP_DPC_NIKON_F6ButtonsAndDials, /* 0xD089 */ |
| 3020 | N_("Buttons and Dials")}, |
| 3021 | {PTP_DPC_NIKON_NoCFCard, /* 0xD08a */ |
| 3022 | N_("No CF Card Release")}, |
| 3023 | {PTP_DPC_NIKON_ImageRotation, /* 0xD092 */ |
| 3024 | N_("Image Rotation")}, |
| 3025 | {PTP_DPC_NIKON_Bracketing, /* 0xD0c0 */ |
| 3026 | N_("Exposure Bracketing")}, |
| 3027 | {PTP_DPC_NIKON_ExposureBracketingIntervalDist, /* 0xD0c1 */ |
| 3028 | N_("Exposure Bracketing Distance")}, |
| 3029 | {PTP_DPC_NIKON_BracketingProgram, /* 0xD0c2 */ |
| 3030 | N_("Exposure Bracketing Number")}, |
| 3031 | {PTP_DPC_NIKON_AutofocusLCDTopMode2, /* 0xD107 */ |
| 3032 | N_("AF LCD Top Mode 2")}, |
| 3033 | {PTP_DPC_NIKON_AutofocusArea, /* 0xD108 */ |
| 3034 | N_("Active AF Sensor")}, |
| 3035 | {PTP_DPC_NIKON_LightMeter, /* 0xD10a */ |
| 3036 | N_("Exposure Meter")}, |
| 3037 | {PTP_DPC_NIKON_ExposureApertureLock, /* 0xD111 */ |
| 3038 | N_("Exposure Aperture Lock")}, |
| 3039 | {PTP_DPC_NIKON_MaximumShots, /* 0xD103 */ |
| 3040 | N_("Maximum Shots")}, |
| 3041 | {PTP_DPC_NIKON_OptimizeImage, /* 0xD140 */ |
| 3042 | N_("Optimize Image")}, |
| 3043 | {PTP_DPC_NIKON_Saturation, /* 0xD142 */ |
| 3044 | N_("Saturation")}, |
| 3045 | {PTP_DPC_NIKON_CSMMenu, /* 0xD180 */ |
| 3046 | N_("CSM Menu")}, |
| 3047 | {PTP_DPC_NIKON_BeepOff, |
| 3048 | N_("AF Beep Mode")}, |
| 3049 | {PTP_DPC_NIKON_AutofocusMode, |
| 3050 | N_("Autofocus Mode")}, |
| 3051 | {PTP_DPC_NIKON_AFAssist, |
| 3052 | N_("AF Assist Lamp")}, |
| 3053 | {PTP_DPC_NIKON_PADVPMode, |
| 3054 | N_("Auto ISO P/A/DVP Setting")}, |
| 3055 | {PTP_DPC_NIKON_ImageReview, |
| 3056 | N_("Image Review")}, |
| 3057 | {PTP_DPC_NIKON_GridDisplay, |
| 3058 | N_("Viewfinder Grid Display")}, |
| 3059 | {PTP_DPC_NIKON_AFAreaIllumination, |
| 3060 | N_("AF Area Illumination")}, |
| 3061 | {PTP_DPC_NIKON_FlashMode, |
| 3062 | N_("Flash Mode")}, |
| 3063 | {PTP_DPC_NIKON_FlashModeManualPower, |
| 3064 | N_("Flash Mode Manual Power")}, |
| 3065 | {PTP_DPC_NIKON_FlashSign, |
| 3066 | N_("Flash Sign")}, |
| 3067 | {PTP_DPC_NIKON_FlashExposureCompensation, |
| 3068 | N_("Flash Exposure Compensation")}, |
| 3069 | {PTP_DPC_NIKON_RemoteTimeout, |
| 3070 | N_("Remote Timeout")}, |
| 3071 | {PTP_DPC_NIKON_ImageCommentString, |
| 3072 | N_("Image Comment String")}, |
| 3073 | {PTP_DPC_NIKON_FlashOpen, |
| 3074 | N_("Flash Open")}, |
| 3075 | {PTP_DPC_NIKON_FlashCharged, |
| 3076 | N_("Flash Charged")}, |
| 3077 | {PTP_DPC_NIKON_LensID, |
| 3078 | N_("Lens ID")}, |
| 3079 | {PTP_DPC_NIKON_FocalLengthMin, |
| 3080 | N_("Min. Focal Length")}, |
| 3081 | {PTP_DPC_NIKON_FocalLengthMax, |
| 3082 | N_("Max. Focal Length")}, |
| 3083 | {PTP_DPC_NIKON_MaxApAtMinFocalLength, |
| 3084 | N_("Max. Aperture at Min. Focal Length")}, |
| 3085 | {PTP_DPC_NIKON_MaxApAtMaxFocalLength, |
| 3086 | N_("Max. Aperture at Max. Focal Length")}, |
| 3087 | {PTP_DPC_NIKON_LowLight, |
| 3088 | N_("Low Light")}, |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 3089 | {0,NULL} |
| 3090 | }; |
Linus Walleij | 545c779 | 2006-06-13 15:22:30 +0000 | [diff] [blame] | 3091 | struct { |
| 3092 | uint16_t dpc; |
| 3093 | const char *txt; |
| 3094 | } ptp_device_properties_MTP[] = { |
| 3095 | {PTP_DPC_MTP_SecureTime, N_("Secure Time")}, |
| 3096 | {PTP_DPC_MTP_DeviceCertificate, N_("Device Certificate")}, |
| 3097 | {PTP_DPC_MTP_SynchronizationPartner, |
| 3098 | N_("Synchronization Partner")}, |
| 3099 | {PTP_DPC_MTP_DeviceFriendlyName, |
| 3100 | N_("Device Friendly Name")}, |
| 3101 | {PTP_DPC_MTP_VolumeLevel, N_("Volume Level")}, |
| 3102 | {PTP_DPC_MTP_DeviceIcon, N_("Device Icon")}, |
| 3103 | {PTP_DPC_MTP_PlaybackRate, N_("Playback Rate")}, |
| 3104 | {PTP_DPC_MTP_PlaybackObject, N_("Playback Object")}, |
| 3105 | {PTP_DPC_MTP_PlaybackContainerIndex, |
| 3106 | N_("Playback Container Index")}, |
| 3107 | {PTP_DPC_MTP_PlaybackPosition, N_("Playback Position")}, |
| 3108 | {0,NULL} |
| 3109 | }; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 3110 | |
| 3111 | for (i=0; ptp_device_properties[i].txt!=NULL; i++) |
| 3112 | if (ptp_device_properties[i].dpc==dpc) |
| 3113 | return (ptp_device_properties[i].txt); |
| 3114 | |
Linus Walleij | 545c779 | 2006-06-13 15:22:30 +0000 | [diff] [blame] | 3115 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT) |
| 3116 | for (i=0; ptp_device_properties_MTP[i].txt!=NULL; i++) |
| 3117 | if (ptp_device_properties_MTP[i].dpc==dpc) |
| 3118 | return (ptp_device_properties_MTP[i].txt); |
| 3119 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3120 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_EASTMAN_KODAK) |
| 3121 | for (i=0; ptp_device_properties_EK[i].txt!=NULL; i++) |
| 3122 | if (ptp_device_properties_EK[i].dpc==dpc) |
| 3123 | return (ptp_device_properties_EK[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 3124 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3125 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_CANON) |
| 3126 | for (i=0; ptp_device_properties_Canon[i].txt!=NULL; i++) |
| 3127 | if (ptp_device_properties_Canon[i].dpc==dpc) |
| 3128 | return (ptp_device_properties_Canon[i].txt); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 3129 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3130 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON) |
| 3131 | for (i=0; ptp_device_properties_Nikon[i].txt!=NULL; i++) |
| 3132 | if (ptp_device_properties_Nikon[i].dpc==dpc) |
| 3133 | return (ptp_device_properties_Nikon[i].txt); |
| 3134 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 3135 | return NULL; |
| 3136 | } |
| 3137 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3138 | static int64_t |
| 3139 | _value_to_num(PTPPropertyValue *data, uint16_t dt) { |
| 3140 | if (dt == PTP_DTC_STR) { |
| 3141 | if (!data->str) |
| 3142 | return 0; |
| 3143 | return atol(data->str); |
| 3144 | } |
| 3145 | if (dt & PTP_DTC_ARRAY_MASK) { |
| 3146 | return 0; |
| 3147 | } else { |
| 3148 | switch (dt) { |
| 3149 | case PTP_DTC_UNDEF: |
| 3150 | return 0; |
| 3151 | case PTP_DTC_INT8: |
| 3152 | return data->i8; |
| 3153 | case PTP_DTC_UINT8: |
| 3154 | return data->u8; |
| 3155 | case PTP_DTC_INT16: |
| 3156 | return data->i16; |
| 3157 | case PTP_DTC_UINT16: |
| 3158 | return data->u16; |
| 3159 | case PTP_DTC_INT32: |
| 3160 | return data->i32; |
| 3161 | case PTP_DTC_UINT32: |
| 3162 | return data->u32; |
| 3163 | /* |
| 3164 | PTP_DTC_INT64 |
| 3165 | PTP_DTC_UINT64 |
| 3166 | PTP_DTC_INT128 |
| 3167 | PTP_DTC_UINT128 |
| 3168 | */ |
| 3169 | default: |
| 3170 | return 0; |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | return 0; |
| 3175 | } |
| 3176 | |
| 3177 | #define PTP_VAL_BOOL(dpc) {dpc, 0, N_("Off")}, {dpc, 1, N_("On")} |
| 3178 | #define PTP_VAL_RBOOL(dpc) {dpc, 0, N_("On")}, {dpc, 1, N_("Off")} |
| 3179 | #define PTP_VAL_YN(dpc) {dpc, 0, N_("No")}, {dpc, 1, N_("Yes")} |
| 3180 | |
| 3181 | int |
| 3182 | ptp_render_property_value(PTPParams* params, uint16_t dpc, |
| 3183 | PTPDevicePropDesc *dpd, int length, char *out) |
| 3184 | { |
| 3185 | int i; |
| 3186 | |
| 3187 | struct { |
| 3188 | uint16_t dpc; |
| 3189 | double coef; |
| 3190 | double bias; |
| 3191 | const char *format; |
| 3192 | } ptp_value_trans[] = { |
| 3193 | {PTP_DPC_ExposureIndex, 1.0, 0.0, "ISO %.0f"}, |
| 3194 | {0, 0.0, 0.0, NULL} |
| 3195 | }; |
| 3196 | |
| 3197 | struct { |
| 3198 | uint16_t dpc; |
| 3199 | double coef; |
| 3200 | double bias; |
| 3201 | const char *format; |
| 3202 | } ptp_value_trans_Nikon[] = { |
| 3203 | {PTP_DPC_BatteryLevel, 1.0, 0.0, "%.0f%%"}, |
| 3204 | {PTP_DPC_FNumber, 0.01, 0.0, "f/%.2g"}, |
| 3205 | {PTP_DPC_FocalLength, 0.01, 0.0, "%.0f mm"}, |
| 3206 | {PTP_DPC_ExposureTime, 0.00001, 0.0, "%.2g sec"}, |
| 3207 | {PTP_DPC_ExposureBiasCompensation, 0.001, 0.0, N_("%.1f stops")}, |
| 3208 | {PTP_DPC_NIKON_LightMeter, 0.08333, 0.0, N_("%.1f stops")}, |
| 3209 | {PTP_DPC_NIKON_FlashExposureCompensation, 0.16666, 0.0, N_("%.1f stops")}, |
| 3210 | {PTP_DPC_NIKON_CenterWeightArea, 2.0, 6.0, N_("%.0f mm")}, |
| 3211 | {PTP_DPC_NIKON_FocalLengthMin, 0.01, 0.0, "%.0f mm"}, |
| 3212 | {PTP_DPC_NIKON_FocalLengthMax, 0.01, 0.0, "%.0f mm"}, |
| 3213 | {PTP_DPC_NIKON_MaxApAtMinFocalLength, 0.01, 0.0, "f/%.2g"}, |
| 3214 | {PTP_DPC_NIKON_MaxApAtMaxFocalLength, 0.01, 0.0, "f/%.2g"}, |
| 3215 | {0, 0.0, 0.0, NULL} |
| 3216 | }; |
| 3217 | |
| 3218 | struct { |
| 3219 | uint16_t dpc; |
| 3220 | int64_t key; |
| 3221 | char *value; |
| 3222 | } ptp_value_list_Nikon[] = { |
| 3223 | {PTP_DPC_CompressionSetting, 0, N_("JPEG Basic")}, |
| 3224 | {PTP_DPC_CompressionSetting, 1, N_("JPEG Norm")}, |
| 3225 | {PTP_DPC_CompressionSetting, 2, N_("JPEG Fine")}, |
| 3226 | {PTP_DPC_CompressionSetting, 4, N_("RAW")}, |
| 3227 | {PTP_DPC_CompressionSetting, 5, N_("RAW + JPEG Basic")}, |
| 3228 | {PTP_DPC_WhiteBalance, 2, N_("Auto")}, |
| 3229 | {PTP_DPC_WhiteBalance, 6, N_("Incandescent")}, |
| 3230 | {PTP_DPC_WhiteBalance, 5, N_("Fluorescent")}, |
| 3231 | {PTP_DPC_WhiteBalance, 4, N_("Daylight")}, |
| 3232 | {PTP_DPC_WhiteBalance, 7, N_("Flash")}, |
| 3233 | {PTP_DPC_WhiteBalance, 32784, N_("Cloudy")}, |
| 3234 | {PTP_DPC_WhiteBalance, 32785, N_("Shade")}, |
| 3235 | {PTP_DPC_WhiteBalance, 32787, N_("Preset")}, |
| 3236 | {PTP_DPC_FlashMode, 32784, N_("Default")}, |
| 3237 | {PTP_DPC_FlashMode, 4, N_("Red-eye Reduction")}, |
| 3238 | {PTP_DPC_FlashMode, 32787, N_("Red-eye Reduction + Slow Sync")}, |
| 3239 | {PTP_DPC_FlashMode, 32785, N_("Slow Sync")}, |
| 3240 | {PTP_DPC_FlashMode, 32785, N_("Rear Curtain Sync + Slow Sync")}, |
| 3241 | {PTP_DPC_FocusMeteringMode, 2, N_("Dynamic Area")}, |
| 3242 | {PTP_DPC_FocusMeteringMode, 32784, N_("Single Area")}, |
| 3243 | {PTP_DPC_FocusMeteringMode, 32785, N_("Closest Subject")}, |
| 3244 | {PTP_DPC_FocusMode, 1, N_("Manual Focus")}, |
| 3245 | {PTP_DPC_FocusMode, 32784, "AF-S"}, |
| 3246 | {PTP_DPC_FocusMode, 32785, "AF-C"}, |
| 3247 | PTP_VAL_BOOL(PTP_DPC_NIKON_ISOAuto), |
| 3248 | PTP_VAL_BOOL(PTP_DPC_NIKON_ExposureCompensation), |
| 3249 | PTP_VAL_BOOL(PTP_DPC_NIKON_AELockMode), |
| 3250 | {PTP_DPC_NIKON_AELAFLMode, 0, N_("AE/AF Lock")}, |
| 3251 | {PTP_DPC_NIKON_AELAFLMode, 1, N_("AF Lock only")}, |
| 3252 | {PTP_DPC_NIKON_AELAFLMode, 2, N_("AE Lock only")}, |
| 3253 | {PTP_DPC_NIKON_AELAFLMode, 3, N_("AF Lock Hold")}, |
| 3254 | {PTP_DPC_NIKON_AELAFLMode, 4, N_("AF On")}, |
| 3255 | {PTP_DPC_NIKON_AELAFLMode, 5, N_("Flash Lock")}, |
| 3256 | {PTP_DPC_ExposureMeteringMode, 2, N_("Center Weighted")}, |
| 3257 | {PTP_DPC_ExposureMeteringMode, 3, N_("Matrix")}, |
| 3258 | {PTP_DPC_ExposureMeteringMode, 4, N_("Spot")}, |
| 3259 | {PTP_DPC_ExposureProgramMode, 1, "M"}, |
| 3260 | {PTP_DPC_ExposureProgramMode, 3, "A"}, |
| 3261 | {PTP_DPC_ExposureProgramMode, 4, "S"}, |
| 3262 | {PTP_DPC_ExposureProgramMode, 2, "P"}, |
| 3263 | {PTP_DPC_ExposureProgramMode, 32784, N_("Auto")}, |
| 3264 | {PTP_DPC_ExposureProgramMode, 32785, N_("Portrait")}, |
| 3265 | {PTP_DPC_ExposureProgramMode, 32786, N_("Landscape")}, |
| 3266 | {PTP_DPC_ExposureProgramMode, 32787, N_("Macro")}, |
| 3267 | {PTP_DPC_ExposureProgramMode, 32788, N_("Sports")}, |
| 3268 | {PTP_DPC_ExposureProgramMode, 32790, N_("Night Landscape")}, |
| 3269 | {PTP_DPC_ExposureProgramMode, 32789, N_("Night Portrait")}, |
| 3270 | {PTP_DPC_StillCaptureMode, 1, N_("Single Shot")}, |
| 3271 | {PTP_DPC_StillCaptureMode, 2, N_("Power Wind")}, |
| 3272 | {PTP_DPC_StillCaptureMode, 32785, N_("Timer")}, |
| 3273 | {PTP_DPC_StillCaptureMode, 32787, N_("Remote")}, |
| 3274 | {PTP_DPC_StillCaptureMode, 32788, N_("Timer + Remote")}, |
| 3275 | PTP_VAL_BOOL(PTP_DPC_NIKON_AutofocusMode), |
| 3276 | PTP_VAL_RBOOL(PTP_DPC_NIKON_AFAssist), |
| 3277 | PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageReview), |
| 3278 | PTP_VAL_BOOL(PTP_DPC_NIKON_GridDisplay), |
| 3279 | {PTP_DPC_NIKON_AFAreaIllumination, 0, N_("Auto")}, |
| 3280 | {PTP_DPC_NIKON_AFAreaIllumination, 1, N_("Off")}, |
| 3281 | {PTP_DPC_NIKON_AFAreaIllumination, 2, N_("On")}, |
| 3282 | {PTP_DPC_NIKON_ColorModel, 0, "sRGB"}, |
| 3283 | {PTP_DPC_NIKON_ColorModel, 1, "AdobeRGB"}, |
| 3284 | {PTP_DPC_NIKON_ColorModel, 2, "sRGB"}, |
| 3285 | {PTP_DPC_NIKON_FlashMode, 0, "iTTL"}, |
| 3286 | {PTP_DPC_NIKON_FlashMode, 1, N_("Manual")}, |
| 3287 | {PTP_DPC_NIKON_FlashMode, 2, N_("Commander")}, |
| 3288 | {PTP_DPC_NIKON_FlashModeManualPower, 0, N_("Full")}, |
| 3289 | {PTP_DPC_NIKON_FlashModeManualPower, 1, "1/2"}, |
| 3290 | {PTP_DPC_NIKON_FlashModeManualPower, 2, "1/4"}, |
| 3291 | {PTP_DPC_NIKON_FlashModeManualPower, 3, "1/8"}, |
| 3292 | {PTP_DPC_NIKON_FlashModeManualPower, 4, "1/16"}, |
| 3293 | PTP_VAL_RBOOL(PTP_DPC_NIKON_FlashSign), |
| 3294 | {PTP_DPC_NIKON_RemoteTimeout, 0, N_("1 min")}, |
| 3295 | {PTP_DPC_NIKON_RemoteTimeout, 1, N_("5 mins")}, |
| 3296 | {PTP_DPC_NIKON_RemoteTimeout, 2, N_("10 mins")}, |
| 3297 | {PTP_DPC_NIKON_RemoteTimeout, 3, N_("15 mins")}, |
| 3298 | PTP_VAL_YN(PTP_DPC_NIKON_FlashOpen), |
| 3299 | PTP_VAL_YN(PTP_DPC_NIKON_FlashCharged), |
| 3300 | PTP_VAL_BOOL(PTP_DPC_NIKON_LongExposureNoiseReduction), |
| 3301 | PTP_VAL_BOOL(PTP_DPC_NIKON_FileNumberSequence), |
| 3302 | PTP_VAL_BOOL(PTP_DPC_NIKON_ReverseCommandDial), |
| 3303 | PTP_VAL_RBOOL(PTP_DPC_NIKON_NoCFCard), |
| 3304 | PTP_VAL_RBOOL(PTP_DPC_NIKON_ImageRotation), |
| 3305 | PTP_VAL_BOOL(PTP_DPC_NIKON_Bracketing), |
| 3306 | {PTP_DPC_NIKON_AutofocusArea, 0, N_("Centre")}, |
| 3307 | {PTP_DPC_NIKON_AutofocusArea, 1, N_("Top")}, |
| 3308 | {PTP_DPC_NIKON_AutofocusArea, 2, N_("Bottom")}, |
| 3309 | {PTP_DPC_NIKON_AutofocusArea, 3, N_("Left")}, |
| 3310 | {PTP_DPC_NIKON_AutofocusArea, 4, N_("Right")}, |
| 3311 | {PTP_DPC_NIKON_OptimizeImage, 0, N_("Normal")}, |
| 3312 | {PTP_DPC_NIKON_OptimizeImage, 1, N_("Vivid")}, |
| 3313 | {PTP_DPC_NIKON_OptimizeImage, 2, N_("Sharper")}, |
| 3314 | {PTP_DPC_NIKON_OptimizeImage, 3, N_("Softer")}, |
| 3315 | {PTP_DPC_NIKON_OptimizeImage, 4, N_("Direct Print")}, |
| 3316 | {PTP_DPC_NIKON_OptimizeImage, 5, N_("Portrait")}, |
| 3317 | {PTP_DPC_NIKON_OptimizeImage, 6, N_("Landscape")}, |
| 3318 | {PTP_DPC_NIKON_OptimizeImage, 7, N_("Custom")}, |
| 3319 | |
| 3320 | {PTP_DPC_NIKON_ImageSharpening, 0, N_("Auto")}, |
| 3321 | {PTP_DPC_NIKON_ImageSharpening, 1, N_("Normal")}, |
| 3322 | {PTP_DPC_NIKON_ImageSharpening, 2, N_("Low")}, |
| 3323 | {PTP_DPC_NIKON_ImageSharpening, 3, N_("Medium Low")}, |
| 3324 | {PTP_DPC_NIKON_ImageSharpening, 4, N_("Medium high")}, |
| 3325 | {PTP_DPC_NIKON_ImageSharpening, 5, N_("High")}, |
| 3326 | {PTP_DPC_NIKON_ImageSharpening, 6, N_("None")}, |
| 3327 | |
| 3328 | {PTP_DPC_NIKON_ToneCompensation, 0, N_("Auto")}, |
| 3329 | {PTP_DPC_NIKON_ToneCompensation, 1, N_("Normal")}, |
| 3330 | {PTP_DPC_NIKON_ToneCompensation, 2, N_("Low contrast")}, |
| 3331 | {PTP_DPC_NIKON_ToneCompensation, 3, N_("Medium low")}, |
| 3332 | {PTP_DPC_NIKON_ToneCompensation, 4, N_("Medium high")}, |
| 3333 | {PTP_DPC_NIKON_ToneCompensation, 5, N_("High control")}, |
| 3334 | {PTP_DPC_NIKON_ToneCompensation, 6, N_("Custom")}, |
| 3335 | |
| 3336 | {PTP_DPC_NIKON_Saturation, 0, N_("Normal")}, |
| 3337 | {PTP_DPC_NIKON_Saturation, 1, N_("Moderate")}, |
| 3338 | {PTP_DPC_NIKON_Saturation, 2, N_("Enhanced")}, |
| 3339 | |
| 3340 | {PTP_DPC_NIKON_LensID, 0, N_("Unknown")}, |
| 3341 | {PTP_DPC_NIKON_LensID, 38, "Sigma 70-300mm 1:4-5.6 D APO Macro"}, |
| 3342 | {PTP_DPC_NIKON_LensID, 83, "AF Nikkor 80-200mm 1:2.8 D ED"}, |
| 3343 | {PTP_DPC_NIKON_LensID, 118, "AF Nikkor 50mm 1:1.8 D"}, |
| 3344 | {PTP_DPC_NIKON_LensID, 127, "AF-S Nikkor 18-70mm 1:3.5-4.5G ED DX"}, |
| 3345 | PTP_VAL_YN(PTP_DPC_NIKON_LowLight), |
| 3346 | PTP_VAL_YN(PTP_DPC_NIKON_CSMMenu), |
| 3347 | PTP_VAL_RBOOL(PTP_DPC_NIKON_BeepOff), |
| 3348 | {0, 0, NULL} |
| 3349 | }; |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3350 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_NIKON) { |
| 3351 | int64_t kval; |
| 3352 | |
| 3353 | for (i=0; ptp_value_trans[i].dpc!=0; i++) |
| 3354 | if (ptp_value_trans[i].dpc==dpc) { |
| 3355 | double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 3356 | |
| 3357 | return snprintf(out, length, |
| 3358 | _(ptp_value_trans[i].format), |
| 3359 | value * ptp_value_trans[i].coef + |
| 3360 | ptp_value_trans[i].bias); |
| 3361 | } |
| 3362 | |
| 3363 | for (i=0; ptp_value_trans_Nikon[i].dpc!=0; i++) |
| 3364 | if (ptp_value_trans_Nikon[i].dpc==dpc) { |
| 3365 | double value = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 3366 | |
| 3367 | return snprintf(out, length, |
| 3368 | _(ptp_value_trans_Nikon[i].format), |
| 3369 | value * ptp_value_trans_Nikon[i].coef + |
| 3370 | ptp_value_trans_Nikon[i].bias); |
| 3371 | } |
| 3372 | |
| 3373 | kval = _value_to_num(&(dpd->CurrentValue), dpd->DataType); |
| 3374 | |
| 3375 | for (i=0; ptp_value_list_Nikon[i].dpc!=0; i++) |
| 3376 | if (ptp_value_list_Nikon[i].dpc==dpc && |
| 3377 | ptp_value_list_Nikon[i].key==kval) |
| 3378 | return snprintf(out, length, "%s", |
| 3379 | _(ptp_value_list_Nikon[i].value)); |
| 3380 | } |
| 3381 | if (params->deviceinfo.VendorExtensionID==PTP_VENDOR_MICROSOFT) { |
| 3382 | switch (dpc) { |
Linus Walleij | 545c779 | 2006-06-13 15:22:30 +0000 | [diff] [blame] | 3383 | case PTP_DPC_MTP_SynchronizationPartner: |
| 3384 | case PTP_DPC_MTP_DeviceFriendlyName: |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3385 | return snprintf(out, length, "%s", dpd->CurrentValue.str); |
Linus Walleij | 545c779 | 2006-06-13 15:22:30 +0000 | [diff] [blame] | 3386 | case PTP_DPC_MTP_SecureTime: |
| 3387 | case PTP_DPC_MTP_DeviceCertificate: { |
Linus Walleij | a823a70 | 2006-08-27 21:27:46 +0000 | [diff] [blame] | 3388 | /* FIXME: Convert to use unicode demux functions */ |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3389 | for (i=0;(i<dpd->CurrentValue.a.count) && (i<length);i++) |
| 3390 | out[i] = dpd->CurrentValue.a.v[i].u16; |
| 3391 | if ( dpd->CurrentValue.a.count && |
| 3392 | (dpd->CurrentValue.a.count < length)) { |
| 3393 | out[dpd->CurrentValue.a.count-1] = 0; |
| 3394 | return dpd->CurrentValue.a.count-1; |
| 3395 | } else { |
| 3396 | out[length-1] = 0; |
| 3397 | return length; |
| 3398 | } |
| 3399 | break; |
| 3400 | } |
| 3401 | default: |
| 3402 | break; |
| 3403 | } |
| 3404 | } |
| 3405 | |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
| 3409 | struct { |
| 3410 | uint16_t ofc; |
| 3411 | const char *format; |
| 3412 | } ptp_ofc_trans[] = { |
| 3413 | {PTP_OFC_Undefined,"Undefined Type"}, |
| 3414 | {PTP_OFC_Association,"Association/Directory"}, |
| 3415 | {PTP_OFC_Script,"Script"}, |
| 3416 | {PTP_OFC_Executable,"Executable"}, |
| 3417 | {PTP_OFC_Text,"Text"}, |
| 3418 | {PTP_OFC_HTML,"HTML"}, |
| 3419 | {PTP_OFC_DPOF,"DPOF"}, |
| 3420 | {PTP_OFC_AIFF,"AIFF"}, |
| 3421 | {PTP_OFC_WAV,"MS Wave"}, |
| 3422 | {PTP_OFC_MP3,"MP3"}, |
| 3423 | {PTP_OFC_AVI,"MS AVI"}, |
| 3424 | {PTP_OFC_MPEG,"MPEG"}, |
| 3425 | {PTP_OFC_ASF,"ASF"}, |
| 3426 | {PTP_OFC_QT,"Apple Quicktime"}, |
| 3427 | {PTP_OFC_EXIF_JPEG,"JPEG"}, |
| 3428 | {PTP_OFC_TIFF_EP,"TIFF EP"}, |
| 3429 | {PTP_OFC_FlashPix,"FlashPix"}, |
| 3430 | {PTP_OFC_BMP,"BMP"}, |
| 3431 | {PTP_OFC_CIFF,"CIFF"}, |
| 3432 | {PTP_OFC_GIF,"GIF"}, |
| 3433 | {PTP_OFC_JFIF,"JFIF"}, |
| 3434 | {PTP_OFC_PCD,"PCD"}, |
| 3435 | {PTP_OFC_PICT,"PICT"}, |
| 3436 | {PTP_OFC_PNG,"PNG"}, |
| 3437 | {PTP_OFC_TIFF,"TIFF"}, |
| 3438 | {PTP_OFC_TIFF_IT,"TIFF_IT"}, |
| 3439 | {PTP_OFC_JP2,"JP2"}, |
| 3440 | {PTP_OFC_JPX,"JPX"}, |
| 3441 | }; |
| 3442 | |
| 3443 | struct { |
| 3444 | uint16_t ofc; |
| 3445 | const char *format; |
| 3446 | } ptp_ofc_mtp_trans[] = { |
| 3447 | {PTP_OFC_MTP_Firmware,N_("Firmware")}, |
| 3448 | {PTP_OFC_MTP_WindowsImageFormat,N_("WindowsImageFormat")}, |
| 3449 | {PTP_OFC_MTP_UndefinedAudio,N_("Undefined Audio")}, |
| 3450 | {PTP_OFC_MTP_WMA,"WMA"}, |
| 3451 | {PTP_OFC_MTP_OGG,"OGG"}, |
Linus Walleij | aa4b075 | 2006-07-26 22:21:04 +0000 | [diff] [blame] | 3452 | {PTP_OFC_MTP_AudibleCodec,N_("Audible.com Codec")}, |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3453 | {PTP_OFC_MTP_UndefinedVideo,N_("Undefined Video")}, |
| 3454 | {PTP_OFC_MTP_WMV,"WMV"}, |
| 3455 | {PTP_OFC_MTP_MP4,"MP4"}, |
| 3456 | {PTP_OFC_MTP_UndefinedCollection,N_("Undefined Collection")}, |
| 3457 | {PTP_OFC_MTP_AbstractMultimediaAlbum,N_("Abstract Multimedia Album")}, |
| 3458 | {PTP_OFC_MTP_AbstractImageAlbum,N_("Abstract Image Album")}, |
| 3459 | {PTP_OFC_MTP_AbstractAudioAlbum,N_("Abstract Audio Album")}, |
| 3460 | {PTP_OFC_MTP_AbstractVideoAlbum,N_("Abstract Video Album")}, |
| 3461 | {PTP_OFC_MTP_AbstractAudioVideoPlaylist,N_("Abstract Audio Video Playlist")}, |
| 3462 | {PTP_OFC_MTP_AbstractContactGroup,N_("Abstract Contact Group")}, |
| 3463 | {PTP_OFC_MTP_AbstractMessageFolder,N_("Abstract Message Folder")}, |
| 3464 | {PTP_OFC_MTP_AbstractChapteredProduction,N_("Abstract Chaptered Production")}, |
| 3465 | {PTP_OFC_MTP_WPLPlaylist,N_("WPL Playlist")}, |
| 3466 | {PTP_OFC_MTP_M3UPlaylist,N_("M3U Playlist")}, |
| 3467 | {PTP_OFC_MTP_MPLPlaylist,N_("MPL Playlist")}, |
| 3468 | {PTP_OFC_MTP_ASXPlaylist,N_("ASX Playlist")}, |
| 3469 | {PTP_OFC_MTP_PLSPlaylist,N_("PLS Playlist")}, |
| 3470 | {PTP_OFC_MTP_UndefinedDocument,N_("UndefinedDocument")}, |
| 3471 | {PTP_OFC_MTP_AbstractDocument,N_("AbstractDocument")}, |
| 3472 | {PTP_OFC_MTP_UndefinedMessage,N_("UndefinedMessage")}, |
| 3473 | {PTP_OFC_MTP_AbstractMessage,N_("AbstractMessage")}, |
| 3474 | {PTP_OFC_MTP_UndefinedContact,N_("UndefinedContact")}, |
| 3475 | {PTP_OFC_MTP_AbstractContact,N_("AbstractContact")}, |
| 3476 | {PTP_OFC_MTP_vCard2,N_("vCard2")}, |
| 3477 | {PTP_OFC_MTP_vCard3,N_("vCard3")}, |
| 3478 | {PTP_OFC_MTP_UndefinedCalendarItem,N_("UndefinedCalendarItem")}, |
| 3479 | {PTP_OFC_MTP_AbstractCalendarItem,N_("AbstractCalendarItem")}, |
| 3480 | {PTP_OFC_MTP_vCalendar1,N_("vCalendar1")}, |
| 3481 | {PTP_OFC_MTP_vCalendar2,N_("vCalendar2")}, |
| 3482 | {PTP_OFC_MTP_UndefinedWindowsExecutable,N_("Undefined Windows Executable")}, |
| 3483 | }; |
| 3484 | |
| 3485 | int |
| 3486 | ptp_render_ofc(PTPParams* params, uint16_t ofc, int spaceleft, char *txt) |
| 3487 | { |
| 3488 | int i; |
| 3489 | |
| 3490 | if (!(ofc & 0x8000)) { |
| 3491 | for (i=0;i<sizeof(ptp_ofc_trans)/sizeof(ptp_ofc_trans[0]);i++) |
| 3492 | if (ofc == ptp_ofc_trans[i].ofc) |
| 3493 | return snprintf(txt, spaceleft,_(ptp_ofc_trans[i].format)); |
| 3494 | } else { |
| 3495 | switch (params->deviceinfo.VendorExtensionID) { |
| 3496 | case PTP_VENDOR_EASTMAN_KODAK: |
| 3497 | switch (ofc) { |
| 3498 | case PTP_OFC_EK_M3U: |
| 3499 | return snprintf (txt, spaceleft,_("M3U")); |
| 3500 | default: |
| 3501 | break; |
| 3502 | } |
| 3503 | break; |
| 3504 | case PTP_VENDOR_MICROSOFT: |
| 3505 | for (i=0;i<sizeof(ptp_ofc_mtp_trans)/sizeof(ptp_ofc_mtp_trans[0]);i++) |
| 3506 | if (ofc == ptp_ofc_mtp_trans[i].ofc) |
| 3507 | return snprintf(txt, spaceleft,_(ptp_ofc_mtp_trans[i].format)); |
| 3508 | break; |
| 3509 | default:break; |
| 3510 | } |
| 3511 | } |
| 3512 | return snprintf (txt, spaceleft,_("Unknown(%04x)"), ofc); |
| 3513 | } |
| 3514 | |
| 3515 | struct { |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 3516 | uint16_t opcode; |
| 3517 | const char *name; |
| 3518 | } ptp_opcode_trans[] = { |
| 3519 | {PTP_OC_Undefined,N_("Undefined")}, |
| 3520 | {PTP_OC_GetDeviceInfo,N_("get device info")}, |
| 3521 | {PTP_OC_OpenSession,N_("Open session")}, |
| 3522 | {PTP_OC_CloseSession,N_("Close session")}, |
| 3523 | {PTP_OC_GetStorageIDs,N_("Get storage IDs")}, |
| 3524 | {PTP_OC_GetStorageInfo,N_("Get storage info")}, |
| 3525 | {PTP_OC_GetNumObjects,N_("Get number of objects")}, |
| 3526 | {PTP_OC_GetObjectHandles,N_("Get object handles")}, |
| 3527 | {PTP_OC_GetObjectInfo,N_("Get object info")}, |
| 3528 | {PTP_OC_GetObject,N_("Get object")}, |
| 3529 | {PTP_OC_GetThumb,N_("Get thumbnail")}, |
| 3530 | {PTP_OC_DeleteObject,N_("Delete object")}, |
| 3531 | {PTP_OC_SendObjectInfo,N_("Send object info")}, |
| 3532 | {PTP_OC_SendObject,N_("Send object")}, |
| 3533 | {PTP_OC_InitiateCapture,N_("Initiate capture")}, |
| 3534 | {PTP_OC_FormatStore,N_("Format storage")}, |
| 3535 | {PTP_OC_ResetDevice,N_("Reset device")}, |
| 3536 | {PTP_OC_SelfTest,N_("Self test device")}, |
| 3537 | {PTP_OC_SetObjectProtection,N_("Set object protection")}, |
| 3538 | {PTP_OC_PowerDown,N_("Power down device")}, |
| 3539 | {PTP_OC_GetDevicePropDesc,N_("Get device property description")}, |
| 3540 | {PTP_OC_GetDevicePropValue,N_("Get device property value")}, |
| 3541 | {PTP_OC_SetDevicePropValue,N_("Set device property value")}, |
| 3542 | {PTP_OC_ResetDevicePropValue,N_("Reset device property value")}, |
| 3543 | {PTP_OC_TerminateOpenCapture,N_("Terminate open capture")}, |
| 3544 | {PTP_OC_MoveObject,N_("Move object")}, |
| 3545 | {PTP_OC_CopyObject,N_("Copy object")}, |
| 3546 | {PTP_OC_GetPartialObject,N_("Get partial object")}, |
| 3547 | {PTP_OC_InitiateOpenCapture,N_("Initiate open capture")} |
| 3548 | }; |
| 3549 | |
| 3550 | struct { |
| 3551 | uint16_t opcode; |
| 3552 | const char *name; |
| 3553 | } ptp_opcode_mtp_trans[] = { |
Linus Walleij | 870929f | 2006-10-23 07:38:58 +0000 | [diff] [blame] | 3554 | {PTP_OC_MTP_GetSecureTimeChallenge,N_("Get secure time challenge")}, |
| 3555 | {PTP_OC_MTP_GetSecureTimeResponse,N_("Get secure time response")}, |
| 3556 | {PTP_OC_MTP_SetLicenseResponse,N_("Set license response")}, |
| 3557 | {PTP_OC_MTP_GetSyncList,N_("Get sync list")}, |
| 3558 | {PTP_OC_MTP_SendMeterChallengeQuery,N_("Send meter challenge query")}, |
| 3559 | {PTP_OC_MTP_GetMeterChallenge,N_("Get meter challenge")}, |
| 3560 | {PTP_OC_MTP_SetMeterResponse,N_("Get meter response")}, |
| 3561 | {PTP_OC_MTP_CleanDataStore,N_("Clean data store")}, |
| 3562 | {PTP_OC_MTP_GetLicenseState,N_("Get license state")}, |
Linus Walleij | 7347d0f | 2006-10-23 07:23:39 +0000 | [diff] [blame] | 3563 | {PTP_OC_MTP_GetObjectPropsSupported,N_("Get object properties supported")}, |
| 3564 | {PTP_OC_MTP_GetObjectPropDesc,N_("Get object property description")}, |
| 3565 | {PTP_OC_MTP_GetObjectPropValue,N_("Get object property value")}, |
| 3566 | {PTP_OC_MTP_SetObjectPropValue,N_("Set object property value")}, |
| 3567 | {PTP_OC_MTP_GetObjPropList,N_("Get object property list")}, |
| 3568 | {PTP_OC_MTP_SetObjPropList,N_("Set object property list")}, |
| 3569 | {PTP_OC_MTP_GetInterdependendPropdesc,N_("Get interdependent property description")}, |
| 3570 | {PTP_OC_MTP_SendObjectPropList,N_("Send object property list")}, |
| 3571 | {PTP_OC_MTP_GetObjectReferences,N_("Get object references")}, |
| 3572 | {PTP_OC_MTP_SetObjectReferences,N_("Set object references")}, |
| 3573 | {PTP_OC_MTP_UpdateDeviceFirmware,N_("Update device firmware")}, |
| 3574 | {PTP_OC_MTP_Skip,N_("Skip to next position in playlist")} |
| 3575 | }; |
| 3576 | |
| 3577 | int |
| 3578 | ptp_render_opcode(PTPParams* params, uint16_t opcode, int spaceleft, char *txt) |
| 3579 | { |
| 3580 | int i; |
| 3581 | |
| 3582 | if (!(opcode & 0x8000)) { |
| 3583 | for (i=0;i<sizeof(ptp_opcode_trans)/sizeof(ptp_opcode_trans[0]);i++) |
| 3584 | if (opcode == ptp_opcode_trans[i].opcode) |
| 3585 | return snprintf(txt, spaceleft,_(ptp_opcode_trans[i].name)); |
| 3586 | } else { |
| 3587 | switch (params->deviceinfo.VendorExtensionID) { |
| 3588 | case PTP_VENDOR_MICROSOFT: |
| 3589 | for (i=0;i<sizeof(ptp_opcode_mtp_trans)/sizeof(ptp_opcode_mtp_trans[0]);i++) |
| 3590 | if (opcode == ptp_opcode_mtp_trans[i].opcode) |
| 3591 | return snprintf(txt, spaceleft,_(ptp_opcode_mtp_trans[i].name)); |
| 3592 | break; |
| 3593 | default:break; |
| 3594 | } |
| 3595 | } |
| 3596 | return snprintf (txt, spaceleft,_("Unknown(%04x)"), opcode); |
| 3597 | } |
| 3598 | |
| 3599 | |
| 3600 | struct { |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 3601 | uint16_t id; |
| 3602 | const char *name; |
| 3603 | } ptp_opc_trans[] = { |
| 3604 | {PTP_OPC_StorageID,"StorageID"}, |
| 3605 | {PTP_OPC_ObjectFormat,"ObjectFormat"}, |
| 3606 | {PTP_OPC_ProtectionStatus,"ProtectionStatus"}, |
| 3607 | {PTP_OPC_ObjectSize,"ObjectSize"}, |
| 3608 | {PTP_OPC_AssociationType,"AssociationType"}, |
| 3609 | {PTP_OPC_AssociationDesc,"AssociationDesc"}, |
| 3610 | {PTP_OPC_ObjectFileName,"ObjectFileName"}, |
| 3611 | {PTP_OPC_DateCreated,"DateCreated"}, |
| 3612 | {PTP_OPC_DateModified,"DateModified"}, |
| 3613 | {PTP_OPC_Keywords,"Keywords"}, |
| 3614 | {PTP_OPC_ParentObject,"ParentObject"}, |
| 3615 | {PTP_OPC_PersistantUniqueObjectIdentifier,"PersistantUniqueObjectIdentifier"}, |
| 3616 | {PTP_OPC_SyncID,"SyncID"}, |
| 3617 | {PTP_OPC_PropertyBag,"PropertyBag"}, |
| 3618 | {PTP_OPC_Name,"Name"}, |
| 3619 | {PTP_OPC_CreatedBy,"CreatedBy"}, |
| 3620 | {PTP_OPC_Artist,"Artist"}, |
| 3621 | {PTP_OPC_DateAuthored,"DateAuthored"}, |
| 3622 | {PTP_OPC_Description,"Description"}, |
| 3623 | {PTP_OPC_URLReference,"URLReference"}, |
| 3624 | {PTP_OPC_LanguageLocale,"LanguageLocale"}, |
| 3625 | {PTP_OPC_CopyrightInformation,"CopyrightInformation"}, |
| 3626 | {PTP_OPC_Source,"Source"}, |
| 3627 | {PTP_OPC_OriginLocation,"OriginLocation"}, |
| 3628 | {PTP_OPC_DateAdded,"DateAdded"}, |
| 3629 | {PTP_OPC_NonConsumable,"NonConsumable"}, |
| 3630 | {PTP_OPC_CorruptOrUnplayable,"CorruptOrUnplayable"}, |
| 3631 | {PTP_OPC_RepresentativeSampleFormat,"RepresentativeSampleFormat"}, |
| 3632 | {PTP_OPC_RepresentativeSampleSize,"RepresentativeSampleSize"}, |
| 3633 | {PTP_OPC_RepresentativeSampleHeight,"RepresentativeSampleHeight"}, |
| 3634 | {PTP_OPC_RepresentativeSampleWidth,"RepresentativeSampleWidth"}, |
| 3635 | {PTP_OPC_RepresentativeSampleDuration,"RepresentativeSampleDuration"}, |
| 3636 | {PTP_OPC_RepresentativeSampleData,"RepresentativeSampleData"}, |
| 3637 | {PTP_OPC_Width,"Width"}, |
| 3638 | {PTP_OPC_Height,"Height"}, |
| 3639 | {PTP_OPC_Duration,"Duration"}, |
| 3640 | {PTP_OPC_Rating,"Rating"}, |
| 3641 | {PTP_OPC_Track,"Track"}, |
| 3642 | {PTP_OPC_Genre,"Genre"}, |
| 3643 | {PTP_OPC_Credits,"Credits"}, |
| 3644 | {PTP_OPC_Lyrics,"Lyrics"}, |
| 3645 | {PTP_OPC_SubscriptionContentID,"SubscriptionContentID"}, |
| 3646 | {PTP_OPC_ProducedBy,"ProducedBy"}, |
| 3647 | {PTP_OPC_UseCount,"UseCount"}, |
| 3648 | {PTP_OPC_SkipCount,"SkipCount"}, |
| 3649 | {PTP_OPC_LastAccessed,"LastAccessed"}, |
| 3650 | {PTP_OPC_ParentalRating,"ParentalRating"}, |
| 3651 | {PTP_OPC_MetaGenre,"MetaGenre"}, |
| 3652 | {PTP_OPC_Composer,"Composer"}, |
| 3653 | {PTP_OPC_EffectiveRating,"EffectiveRating"}, |
| 3654 | {PTP_OPC_Subtitle,"Subtitle"}, |
| 3655 | {PTP_OPC_OriginalReleaseDate,"OriginalReleaseDate"}, |
| 3656 | {PTP_OPC_AlbumName,"AlbumName"}, |
| 3657 | {PTP_OPC_AlbumArtist,"AlbumArtist"}, |
| 3658 | {PTP_OPC_Mood,"Mood"}, |
| 3659 | {PTP_OPC_DRMStatus,"DRMStatus"}, |
| 3660 | {PTP_OPC_SubDescription,"SubDescription"}, |
| 3661 | {PTP_OPC_IsCropped,"IsCropped"}, |
| 3662 | {PTP_OPC_IsColorCorrected,"IsColorCorrected"}, |
| 3663 | {PTP_OPC_TotalBitRate,"TotalBitRate"}, |
| 3664 | {PTP_OPC_BitRateType,"BitRateType"}, |
| 3665 | {PTP_OPC_SampleRate,"SampleRate"}, |
| 3666 | {PTP_OPC_NumberOfChannels,"NumberOfChannels"}, |
| 3667 | {PTP_OPC_AudioBitDepth,"AudioBitDepth"}, |
| 3668 | {PTP_OPC_ScanDepth,"ScanDepth"}, |
| 3669 | {PTP_OPC_AudioWAVECodec,"AudioWAVECodec"}, |
| 3670 | {PTP_OPC_AudioBitRate,"AudioBitRate"}, |
| 3671 | {PTP_OPC_VideoFourCCCodec,"VideoFourCCCodec"}, |
| 3672 | {PTP_OPC_VideoBitRate,"VideoBitRate"}, |
| 3673 | {PTP_OPC_FramesPerThousandSeconds,"FramesPerThousandSeconds"}, |
| 3674 | {PTP_OPC_KeyFrameDistance,"KeyFrameDistance"}, |
| 3675 | {PTP_OPC_BufferSize,"BufferSize"}, |
| 3676 | {PTP_OPC_EncodingQuality,"EncodingQuality"}, |
| 3677 | }; |
| 3678 | |
| 3679 | int |
| 3680 | ptp_render_mtp_propname(uint16_t propid, int spaceleft, char *txt) { |
| 3681 | int i; |
| 3682 | for (i=0;i<sizeof(ptp_opc_trans)/sizeof(ptp_opc_trans[0]);i++) |
| 3683 | if (propid == ptp_opc_trans[i].id) |
| 3684 | return snprintf(txt, spaceleft,ptp_opc_trans[i].name); |
| 3685 | return snprintf (txt, spaceleft,"unknown(%04x)", propid); |
| 3686 | } |