1 /**************************************************************************** 2 * 3 * File: usb.h 4 * 5 ****************************************************************************/ 6 7 #ifndef _CANON_USB_H 8 #define _CANON_USB_H 9 10 /** 11 * USB_BULK_READ_SIZE 12 * 13 * Maximum size to be used for a USB "bulk read" operation 14 * 15 */ 16 #define USB_BULK_READ_SIZE 0x1400 17 18 19 /** 20 * USB_BULK_WRITE_SIZE 21 * 22 * Maximum size to be used for a USB "bulk write" operation 23 * 24 */ 25 /* #define USB_BULK_WRITE_SIZE 0xC000 */ 26 #define USB_BULK_WRITE_SIZE 0x1400 27 28 /** 29 * canonCommandIndex: 30 * @CANON_USB_FUNCTION_GET_FILE: Command to download a file from the camera. 31 * @CANON_USB_FUNCTION_IDENTIFY_CAMERA: Command to read the firmware version and 32 * strings with the camera type and owner from the camera. 33 * @CANON_USB_FUNCTION_GET_TIME: Command to get the time in Unix time format from the camera. 34 * @CANON_USB_FUNCTION_SET_TIME: Command to set the camera's internal time. 35 * @CANON_USB_FUNCTION_MKDIR: Command to create a directory on the camera storage device. 36 * @CANON_USB_FUNCTION_CAMERA_CHOWN: Change "owner" string on camera 37 * @CANON_USB_FUNCTION_RMDIR: Command to delete a directory from camera storage. 38 * @CANON_USB_FUNCTION_DISK_INFO: Command to get disk information from 39 * the camera, given a disk designator (e.g. "D:"). Returns total 40 * capacity and free space. 41 * @CANON_USB_FUNCTION_FLASH_DEVICE_IDENT: Command to request the disk specifier 42 * (drive letter) for the storage device being used. 43 * @CANON_USB_FUNCTION_POWER_STATUS: Command to query the camera for its power status: 44 * battery vs. mains, and whether the battery is low. 45 * @CANON_USB_FUNCTION_GET_DIRENT: Get directory entries 46 * @CANON_USB_FUNCTION_DELETE_FILE: Delete file 47 * @CANON_USB_FUNCTION_DISK_INFO_2: get disk info for newer protocol 48 * (capacity and free space) 49 * @CANON_USB_FUNCTION_SET_ATTR: Command to set the attributes of a 50 * file on the camera (e.g. downloaded, protect from delete). 51 * @CANON_USB_FUNCTION_GET_PIC_ABILITIES: Command to "get picture 52 * abilities", which seems to be a list of the different sizes and 53 * quality of images that are available on this camera. Not 54 * implemented (and will cause an error) on the EOS cameras or on 55 * newer PowerShot cameras such as S45, G3, G5. 56 * @CANON_USB_FUNCTION_GENERIC_LOCK_KEYS: Command to lock keys (and 57 * turn on "PC" indicator) on non-EOS cameras. 58 * @CANON_USB_FUNCTION_EOS_LOCK_KEYS: Lock keys (EOS cameras) 59 * @CANON_USB_FUNCTION_EOS_UNLOCK_KEYS: Unlock keys (EOS cameras) 60 * @CANON_USB_FUNCTION_RETRIEVE_CAPTURE: Command to retrieve the last 61 * image captured, depending on the transfer mode set via 62 * %CANON_USB_FUNCTION_CONTROL_CAMERA with subcommand 63 * %CANON_USB_CONTROL_SET_TRANSFER_MODE. 64 * @CANON_USB_FUNCTION_RETRIEVE_PREVIEW: Command to retrieve a preview 65 * image. 66 * @CANON_USB_FUNCTION_CONTROL_CAMERA: Remote camera control (with 67 * many subcodes) 68 * @CANON_USB_FUNCTION_FLASH_DEVICE_IDENT_2: Command to request the 69 * disk specifier (drive letter) for the storage device being 70 * used. Used with the "newer" protocol, e.g. with EOS 20D. 71 * @CANON_USB_FUNCTION_POWER_STATUS_2: Command to query the camera for 72 * its power status: battery vs. mains, and whether the battery is 73 * low. Used in the "newer" protocol, e.g. with EOS 20D. 74 * @CANON_USB_FUNCTION_UNKNOWN_FUNCTION: Don't know what this is for; 75 * it has been sighted in USB trace logs for an EOS D30, but not for 76 * a D60 or for any PowerShot camera. 77 * @CANON_USB_FUNCTION_EOS_GET_BODY_ID: Command to read the body ID (serial number) 78 * from an EOS camera. 79 * @CANON_USB_FUNCTION_SET_FILE_TIME: Set file time 80 * @CANON_USB_FUNCTION_20D_UNKNOWN_1: First seen with EOS 20D, not yet understood. 81 * @CANON_USB_FUNCTION_20D_UNKNOWN_2: First seen with EOS 20D, not yet understood. 82 * @CANON_USB_FUNCTION_EOS_GET_BODY_ID_2: Same function as 83 * %CANON_USB_FUNCTION_EOS_GET_BODY_ID, but first seen on EOS 20D. 84 * @CANON_USB_FUNCTION_GET_PIC_ABILITIES_2: Same function as 85 * %CANON_USB_FUNCTION_GET_PIC_ABILITIES, but first seen on EOS 20D. 86 * @CANON_USB_FUNCTION_CONTROL_CAMERA_2: Replacement for 87 * %CANON_USB_FUNCTION_CONTROL_CAMERA, with many similarities, first 88 * seen with EOS 20D. 89 * @CANON_USB_FUNCTION_RETRIEVE_CAPTURE_2: Same function as 90 * %CANON_USB_FUNCTION_RETRIEVE_CAPTURE, but first seen on EOS 20D. 91 * @CANON_USB_FUNCTION_LOCK_KEYS_2: Same as %CANON_USB_FUNCTION_EOS_LOCK_KEYS, 92 * but for newer protocol. 93 * @CANON_USB_FUNCTION_UNLOCK_KEYS_2: Same as %CANON_USB_FUNCTION_EOS_UNLOCK_KEYS, 94 * but for newer protocol. 95 * @CANON_USB_FUNCTION_SET_ATTR_2: Presumed code to set attribute bits 96 * for a file on an EOS 20D and its ilk. 97 * @CANON_USB_FUNCTION_CAMERA_CHOWN_2: Same as %CANON_USB_FUNCTION_CAMERA_CHOWN, 98 * but for newer protocol. 99 * @CANON_USB_FUNCTION_GET_OWNER: Gets just the owner name, in newer protocol. 100 * 101 * Codes to give to canon_usb_dialogue() or canon_usb_long_dialogue() 102 * to select which command to issue to the camera. See the protocol 103 * document for details. 104 */ 105 106 typedef enum { 107 CANON_USB_FUNCTION_GET_FILE = 1, 108 CANON_USB_FUNCTION_IDENTIFY_CAMERA, 109 CANON_USB_FUNCTION_GET_TIME, 110 CANON_USB_FUNCTION_SET_TIME, 111 CANON_USB_FUNCTION_MKDIR, 112 CANON_USB_FUNCTION_CAMERA_CHOWN, 113 CANON_USB_FUNCTION_RMDIR, 114 CANON_USB_FUNCTION_DISK_INFO, 115 CANON_USB_FUNCTION_FLASH_DEVICE_IDENT, 116 CANON_USB_FUNCTION_POWER_STATUS, 117 CANON_USB_FUNCTION_GET_DIRENT, 118 CANON_USB_FUNCTION_DELETE_FILE, 119 CANON_USB_FUNCTION_SET_ATTR, 120 CANON_USB_FUNCTION_GET_PIC_ABILITIES, 121 CANON_USB_FUNCTION_GENERIC_LOCK_KEYS, 122 CANON_USB_FUNCTION_EOS_LOCK_KEYS, 123 CANON_USB_FUNCTION_EOS_UNLOCK_KEYS, 124 CANON_USB_FUNCTION_RETRIEVE_CAPTURE, 125 CANON_USB_FUNCTION_RETRIEVE_PREVIEW, 126 CANON_USB_FUNCTION_CONTROL_CAMERA, 127 CANON_USB_FUNCTION_DISK_INFO_2, 128 CANON_USB_FUNCTION_FLASH_DEVICE_IDENT_2, 129 CANON_USB_FUNCTION_POWER_STATUS_2, 130 CANON_USB_FUNCTION_UNKNOWN_FUNCTION, 131 CANON_USB_FUNCTION_EOS_GET_BODY_ID, 132 CANON_USB_FUNCTION_SET_FILE_TIME, 133 CANON_USB_FUNCTION_20D_UNKNOWN_1, 134 CANON_USB_FUNCTION_20D_UNKNOWN_2, 135 CANON_USB_FUNCTION_EOS_GET_BODY_ID_2, 136 CANON_USB_FUNCTION_GET_PIC_ABILITIES_2, 137 CANON_USB_FUNCTION_CONTROL_CAMERA_2, 138 CANON_USB_FUNCTION_RETRIEVE_CAPTURE_2, 139 CANON_USB_FUNCTION_LOCK_KEYS_2, 140 CANON_USB_FUNCTION_UNLOCK_KEYS_2, 141 CANON_USB_FUNCTION_DELETE_FILE_2, 142 CANON_USB_FUNCTION_SET_ATTR_2, 143 CANON_USB_FUNCTION_CAMERA_CHOWN_2, 144 CANON_USB_FUNCTION_GET_OWNER, 145 } canonCommandIndex; 146 147 /** 148 * canonSubcommandIndex: 149 * @CANON_USB_CONTROL_INIT: Enter camera control mode 150 * @CANON_USB_CONTROL_SHUTTER_RELEASE: Release camera shutter (capture still) 151 * @CANON_USB_CONTROL_SET_PARAMS: Set release parameters (AE mode, beep, etc.) 152 * @CANON_USB_CONTROL_SET_TRANSFER_MODE: Set transfer mode for next image 153 * capture. Either the full image, a thumbnail or both may be either 154 * stored on the camera, downloaded to the host, or both. 155 * @CANON_USB_CONTROL_GET_PARAMS: Read the same parameters set by 156 * @CANON_USB_CONTROL_SET_PARAMS. 157 * @CANON_USB_CONTROL_GET_ZOOM_POS: Get the position of the zoom lens 158 * @CANON_USB_CONTROL_SET_ZOOM_POS: Set the position of the zoom lens 159 * @CANON_USB_CONTROL_GET_EXT_PARAMS_SIZE: Get the size of the "extended 160 * release parameters". 161 * @CANON_USB_CONTROL_GET_EXT_PARAMS: Get the "extended release parameters". 162 * @CANON_USB_CONTROL_EXIT: Leave camera control mode; opposite of 163 * @CANON_USB_CONTROL_INIT. 164 * @CANON_USB_CONTROL_VIEWFINDER_START: Switch video viewfinder on. 165 * @CANON_USB_CONTROL_VIEWFINDER_STOP: Swictch video viewfinder off. 166 * @CANON_USB_CONTROL_GET_AVAILABLE_SHOT: Get estimated number of images 167 * that can be captured in current mode before filling flash card. 168 * @CANON_USB_CONTROL_SET_CUSTOM_FUNC: Not yet seen in USB trace. 169 * @CANON_USB_CONTROL_GET_CUSTOM_FUNC: Read custom functions from an EOS camera 170 * @CANON_USB_CONTROL_GET_EXT_PARAMS_VER: Not yet seen in USB trace. 171 * @CANON_USB_CONTROL_SET_EXT_PARAMS: Not yet seen in USB trace. 172 * @CANON_USB_CONTROL_SELECT_CAM_OUTPUT: Not yet seen in USB trace. 173 * @CANON_USB_CONTROL_DO_AE_AF_AWB: Not yet seen in USB trace. 174 * @CANON_USB_CONTROL_UNKNOWN_1: part of new protocol, function unknown. 175 * @CANON_USB_CONTROL_UNKNOWN_2: part of new protocol, function unknown. 176 * 177 * CANON_USB_FUNCTION_CONTROL_CAMERA commands are used for a wide range 178 * of remote camera control actions. A control_cmdstruct is defined 179 * below for the following remote camera control options. 180 */ 181 typedef enum { 182 CANON_USB_CONTROL_INIT = 1, 183 CANON_USB_CONTROL_SHUTTER_RELEASE, 184 CANON_USB_CONTROL_SET_PARAMS, 185 CANON_USB_CONTROL_SET_TRANSFER_MODE, 186 CANON_USB_CONTROL_GET_PARAMS, 187 CANON_USB_CONTROL_GET_ZOOM_POS, 188 CANON_USB_CONTROL_SET_ZOOM_POS, 189 CANON_USB_CONTROL_GET_EXT_PARAMS_SIZE, 190 CANON_USB_CONTROL_GET_EXT_PARAMS, 191 CANON_USB_CONTROL_EXIT, 192 CANON_USB_CONTROL_VIEWFINDER_START, 193 CANON_USB_CONTROL_VIEWFINDER_STOP, 194 CANON_USB_CONTROL_GET_AVAILABLE_SHOT, 195 CANON_USB_CONTROL_SET_CUSTOM_FUNC, /* Not yet seen in USB trace */ 196 CANON_USB_CONTROL_GET_CUSTOM_FUNC, 197 CANON_USB_CONTROL_GET_EXT_PARAMS_VER, /* Not yet seen in USB trace */ 198 CANON_USB_CONTROL_SET_EXT_PARAMS, /* Not yet seen in USB trace */ 199 CANON_USB_CONTROL_SELECT_CAM_OUTPUT, /* Not yet seen in USB trace */ 200 CANON_USB_CONTROL_DO_AE_AF_AWB, /* Not yet seen in USB trace */ 201 CANON_USB_CONTROL_UNKNOWN_1, 202 CANON_USB_CONTROL_UNKNOWN_2 203 } canonSubcommandIndex; 204 205 206 struct canon_usb_control_cmdstruct 207 { 208 canonSubcommandIndex num; 209 char *description; 210 char subcmd; 211 int cmd_length; 212 int additional_return_length; 213 }; 214 215 /** 216 * MAX_INTERRUPT_TRIES 217 * 218 * Maximum number of times to try a read from the interrupt pipe. We 219 * will keep reading until an error, a read of non-zero length, or for 220 * a maximum of this many times. 221 */ 222 #define MAX_INTERRUPT_TRIES 12000 223 224 225 226 struct canon_usb_cmdstruct 227 { 228 canonCommandIndex num; 229 char *description; 230 char cmd1, cmd2; 231 int cmd3; 232 int return_length; 233 }; 234 235 236 /* USB command data structures defined in usb.c */ 237 /*extern const struct canon_usb_cmdstruct canon_usb_cmd[];*/ 238 239 extern const struct canon_usb_control_cmdstruct canon_usb_control_cmd[]; 240 241 242 /* For mapping status codes to intelligible messages */ 243 struct canon_usb_status { 244 int code; 245 char *message; 246 }; 247 248 /**************************************************************************** 249 * 250 * prototypes 251 * 252 ****************************************************************************/ 253 254 int canon_usb_init (Camera *camera, GPContext *context); 255 int canon_usb_set_file_time ( Camera *camera, char *camera_filename, time_t time, GPContext *context); 256 int canon_usb_put_file (Camera *camera, CameraFile *file, const char *filename, const char *destname, const char *destpath, 257 GPContext *context); 258 unsigned char *canon_usb_capture_dialogue (Camera *camera, unsigned int *return_length, int *photo_status, GPContext *context ); 259 unsigned char *canon_usb_dialogue_full (Camera *camera, canonCommandIndex canon_funct, 260 unsigned int *return_length, const unsigned char *payload, unsigned int payload_length); 261 unsigned char *canon_usb_dialogue (Camera *camera, canonCommandIndex canon_funct, 262 unsigned int *return_length, const unsigned char *payload, unsigned int payload_length); 263 int canon_usb_long_dialogue (Camera *camera, canonCommandIndex canon_funct, unsigned char **data, 264 unsigned int *data_length, unsigned int max_data_size, const unsigned char *payload, 265 unsigned int payload_length, int display_status, GPContext *context); 266 int canon_usb_get_file (Camera *camera, const char *name, unsigned char **data, unsigned int *length, GPContext *context); 267 int canon_usb_get_thumbnail (Camera *camera, const char *name, unsigned char **data, unsigned int *length, GPContext *context); 268 int canon_usb_get_captured_image (Camera *camera, const int key, unsigned char **data, unsigned int *length, GPContext *context); 269 int canon_usb_get_captured_secondary_image (Camera *camera, const int key, unsigned char **data, unsigned int *length, GPContext *context); 270 int canon_usb_get_captured_thumbnail (Camera *camera, const int key, unsigned char **data, unsigned int *length, GPContext *context); 271 int canon_usb_lock_keys(Camera *camera, GPContext *context); 272 int canon_usb_unlock_keys(Camera *camera, GPContext *context); 273 int canon_usb_get_dirents (Camera *camera, unsigned char **dirent_data, unsigned int *dirents_length, const char *path, GPContext *context); 274 int canon_usb_list_all_dirs (Camera *camera, unsigned char **dirent_data, 275 unsigned int *dirents_length, GPContext *context); 276 int canon_usb_set_file_attributes (Camera *camera, 277 unsigned int attr_bits, 278 const char *dir, const char *file, 279 GPContext *context); 280 int canon_usb_ready (Camera *camera, GPContext *context); 281 282 int canon_usb_wait_for_event (Camera *camera, int timeout, 283 CameraEventType *eventtype, void **eventdata, 284 GPContext *context); 285 #endif /* _CANON_USB_H */ 286 287 /**************************************************************************** 288 * 289 * End of file: usb.h 290 * 291 ****************************************************************************/ 292 293 /* 294 * Local Variables: 295 * c-file-style:"linux" 296 * indent-tabs-mode:t 297 * End: 298 */ 299