summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Walleij <triad@df.lth.se>2010-12-07 20:43:00 +0000
committerLinus Walleij <triad@df.lth.se>2010-12-07 20:43:00 +0000
commitd7072c3fa6182eed4767c97d371b15860bc386af (patch)
tree917ae4242c28c67a87f9928017836fbb11c4bdf7
parentb8ff72fb43d220ad51864beece89d0c32251a917 (diff)
downloadlibmtp-d7072c3fa6182eed4767c97d371b15860bc386af.tar.gz
Update PTP code to match upstream
-rw-r--r--ChangeLog3
-rw-r--r--src/ptp-pack.c45
-rw-r--r--src/ptp.c76
-rw-r--r--src/ptp.h60
4 files changed, 125 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index 26e6e35..a98aaf1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
* configure.ac: make sure the prober only compiles for
Linux.
+ * src/ptp.c: update to match upstream.
+ * src/ptp.h: dito.
+ * src/ptp-pack.c: dito.
2010-12-05 Linus Walleij <triad@df.lth.se>
diff --git a/src/ptp-pack.c b/src/ptp-pack.c
index 05dab7b..bfe7fe2 100644
--- a/src/ptp-pack.c
+++ b/src/ptp-pack.c
@@ -1300,6 +1300,7 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
uint32_t type = dtoh32a(&curdata[PTP_ece_Type]);
(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN;
+ (*ce)[i].u.info = NULL;
switch (type) {
case PTP_EC_CANON_EOS_ObjectAddedEx:
(*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO;
@@ -1430,6 +1431,9 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
}
dpd = &params->canon_props[j].dpd;
+ (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_PROPERTY;
+ (*ce)[i].u.propid = proptype;
+
/* fix GetSet value */
switch (proptype) {
#define XX(x) case PTP_DPC_CANON_##x:
@@ -1546,16 +1550,6 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
/* custom func entries look like this on the 400D: '5 0 0 0 ?' = 4 bytes size + 1 byte data */
data += 4;
break;
- /* ImageFormat special handling */
- case PTP_DPC_CANON_EOS_ImageFormat:
- case PTP_DPC_CANON_EOS_ImageFormatCF:
- case PTP_DPC_CANON_EOS_ImageFormatSD:
- case PTP_DPC_CANON_EOS_ImageFormatExtHD:
- dpd->DataType = PTP_DTC_UINT16;
- dpd->FactoryDefaultValue.u16 = ptp_unpack_EOS_ImageFormat( params, &data );
- dpd->CurrentValue.u16 = dpd->FactoryDefaultValue.u16;
- ptp_debug (params,"event %d: decoded imageformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
- break;
/* yet unknown 32bit props */
case PTP_DPC_CANON_EOS_ColorTemperature:
case PTP_DPC_CANON_EOS_WftStatus:
@@ -1582,6 +1576,12 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
for (j=0;j<(size-PTP_ece_Prop_Val_Data)/sizeof(uint32_t);j++)
ptp_debug (params, " %d: 0x%8x", j, ((uint32_t*)data)[j]);
break;
+ /* ImageFormat properties have to be ignored here, see special handling below */
+ case PTP_DPC_CANON_EOS_ImageFormat:
+ case PTP_DPC_CANON_EOS_ImageFormatCF:
+ case PTP_DPC_CANON_EOS_ImageFormatSD:
+ case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+ break;
default:
ptp_debug (params, "event %d: Unknown EOS property %04x, datasize is %d", i ,proptype, size-PTP_ece_Prop_Val_Data);
for (j=0;j<size-PTP_ece_Prop_Val_Data;j++)
@@ -1624,8 +1624,26 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
break;
}
+ /* ImageFormat special handling (WARNING: dont move this in front of the dpd->DataType switch!) */
+ switch (proptype) {
+ case PTP_DPC_CANON_EOS_ImageFormat:
+ case PTP_DPC_CANON_EOS_ImageFormatCF:
+ case PTP_DPC_CANON_EOS_ImageFormatSD:
+ case PTP_DPC_CANON_EOS_ImageFormatExtHD:
+ dpd->DataType = PTP_DTC_UINT16;
+ dpd->FactoryDefaultValue.u16 = ptp_unpack_EOS_ImageFormat( params, &data );
+ dpd->CurrentValue.u16 = dpd->FactoryDefaultValue.u16;
+ ptp_debug (params,"event %d: decoded imageformat, currentvalue of %x is %x", i, proptype, dpd->CurrentValue.u16);
+ break;
+ }
+
break;
}
+ case PTP_EC_CANON_EOS_CameraStatusChanged:
+ ptp_debug (params, "event %d: EOS event CameraStatusChanged (size %d)", i, size);
+ (*ce)[i].type = PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS;
+ (*ce)[i].u.status = dtoh32a(curdata+8);
+ break;
case 0: /* end marker */
if (size == 8) /* no output */
break;
@@ -1633,7 +1651,11 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
break;
default:
switch (type) {
-#define XX(x) case PTP_EC_CANON_EOS_##x: ptp_debug (params, "event %d: unhandled EOS event "#x" (size %d)", i, size);break;
+#define XX(x) case PTP_EC_CANON_EOS_##x: \
+ ptp_debug (params, "event %d: unhandled EOS event "#x" (size %d)", i, size); \
+ (*ce)[i].u.info = malloc(strlen("unhandled EOS event "#x" (size 123456789)")); \
+ sprintf ((*ce)[i].u.info, "unhandled EOS event "#x" (size %d)", size); \
+ break;
XX(RequestGetEvent)
XX(ObjectRemoved)
XX(RequestGetObjectInfoEx)
@@ -1641,7 +1663,6 @@ ptp_unpack_CANON_changes (PTPParams *params, unsigned char* data, int datasize,
XX(StorageInfoChanged)
XX(ObjectInfoChangedEx)
XX(ObjectContentChanged)
- XX(CameraStatusChanged)
XX(WillSoonShutdown)
XX(ShutdownTimerUpdated)
XX(RequestCancelTransfer)
diff --git a/src/ptp.c b/src/ptp.c
index b9b1d95..90e2512 100644
--- a/src/ptp.c
+++ b/src/ptp.c
@@ -742,6 +742,33 @@ ptp_canon_eos_bulbstart (PTPParams* params)
}
/**
+ * ptp_eos_capture:
+ * params: PTPParams*
+ * uint32_t* result
+ *
+ * This starts a EOS400D style capture. You have to use the
+ * get_eos_events to find out what resulted.
+ * The return value is "0" for all OK, and "1" for capture failed. (not fully confirmed)
+ *
+ * Return values: Some PTP_RC_* code.
+ **/
+uint16_t
+ptp_canon_eos_capture (PTPParams* params, uint32_t *result)
+{
+ uint16_t ret;
+ PTPContainer ptp;
+
+ PTP_CNT_INIT(ptp);
+ ptp.Code = PTP_OC_CANON_EOS_RemoteRelease;
+ ptp.Nparam = 0;
+ *result = 0;
+ ret = ptp_transaction(params, &ptp, PTP_DP_NODATA, 0, NULL, NULL);
+ if ((ret == PTP_RC_OK) && (ptp.Nparam >= 1))
+ *result = ptp.Param1;
+ return ret;
+}
+
+/**
* ptp_canon_eos_bulbend:
* params: PTPParams*
*
@@ -1688,23 +1715,25 @@ ptp_check_eos_events (PTPParams *params) {
PTPCanon_changes_entry *entries = NULL, *nentries;
int nrofentries = 0;
- ret = ptp_canon_eos_getevent (params, &entries, &nrofentries);
- if (ret != PTP_RC_OK)
- return ret;
- if (!nrofentries)
- return PTP_RC_OK;
+ while (1) { /* call it repeatedly until the camera does not report any */
+ ret = ptp_canon_eos_getevent (params, &entries, &nrofentries);
+ if (ret != PTP_RC_OK)
+ return ret;
+ if (!nrofentries)
+ return PTP_RC_OK;
- if (params->nrofbacklogentries) {
- nentries = realloc(params->backlogentries,sizeof(entries[0])*(params->nrofbacklogentries+nrofentries));
- if (!nentries)
- return PTP_RC_GeneralError;
- params->backlogentries = nentries;
- memcpy (nentries+params->nrofbacklogentries, entries, nrofentries*sizeof(entries[0]));
- params->nrofbacklogentries += nrofentries;
- free (entries);
- } else {
- params->backlogentries = entries;
- params->nrofbacklogentries = nrofentries;
+ if (params->nrofbacklogentries) {
+ nentries = realloc(params->backlogentries,sizeof(entries[0])*(params->nrofbacklogentries+nrofentries));
+ if (!nentries)
+ return PTP_RC_GeneralError;
+ params->backlogentries = nentries;
+ memcpy (nentries+params->nrofbacklogentries, entries, nrofentries*sizeof(entries[0]));
+ params->nrofbacklogentries += nrofentries;
+ free (entries);
+ } else {
+ params->backlogentries = entries;
+ params->nrofbacklogentries = nrofentries;
+ }
}
return PTP_RC_OK;
}
@@ -2785,19 +2814,6 @@ ptp_mtp_setobjectproplist (PTPParams* params, MTPProperties *props, int nrofprop
/* devinfo testing functions */
int
-ptp_operation_issupported(PTPParams* params, uint16_t operation)
-{
- int i=0;
-
- for (;i<params->deviceinfo.OperationsSupported_len;i++) {
- if (params->deviceinfo.OperationsSupported[i]==operation)
- return 1;
- }
- return 0;
-}
-
-
-int
ptp_event_issupported(PTPParams* params, uint16_t event)
{
int i=0;
@@ -4963,7 +4979,7 @@ uint16_t
ptp_object_want (PTPParams *params, uint32_t handle, int want, PTPObject **retob) {
uint16_t ret;
PTPObject *ob;
- //Camera *camera = ((PTPData *)params->data)->camera;
+ /*Camera *camera = ((PTPData *)params->data)->camera;*/
*retob = NULL;
if (!handle) {
diff --git a/src/ptp.h b/src/ptp.h
index 1f87912..31031b9 100644
--- a/src/ptp.h
+++ b/src/ptp.h
@@ -567,7 +567,13 @@ typedef struct _PTPIPHeader PTPIPHeader;
#define PTP_RC_NIKON_AdvancedTransferCancel 0xA022
/* Canon specific response codes */
-#define PTP_RC_CANON_A009 0xA009
+#define PTP_RC_CANON_UNKNOWN_COMMAND 0xA001
+#define PTP_RC_CANON_OPERATION_REFUSED 0xA005
+#define PTP_RC_CANON_LENS_COVER 0xA006
+#define PTP_RC_CANON_BATTERY_LOW 0xA101
+#define PTP_RC_CANON_NOT_READY 0xA102
+
+#define PTP_RC_CANON_A009 0xA009
/* Microsoft/MTP specific codes */
#define PTP_RC_MTP_Undefined 0xA800
@@ -802,6 +808,8 @@ typedef struct _PTPObjectInfo PTPObjectInfo;
#define PTP_OFC_CANON_CRW 0xb101
#define PTP_OFC_CANON_CRW3 0xb103
#define PTP_OFC_CANON_MOV 0xb104
+/* CHDK specific raw mode */
+#define PTP_OFC_CANON_CHDK_CRW 0xb1ff
/* MTP extensions */
#define PTP_OFC_MTP_MediaCard 0xb211
#define PTP_OFC_MTP_MediaCardGroup 0xb212
@@ -1057,7 +1065,7 @@ struct _PTPNIKONWifiProfile {
uint8_t encryption; /* 0 - None, 1 - WEP 64bit, 2 - WEP 128bit (not supported: 3 - TKIP) */
uint8_t key[64];
uint8_t key_nr;
-// char guid[16];
+/* char guid[16]; */
};
typedef struct _PTPNIKONWifiProfile PTPNIKONWifiProfile;
@@ -1065,9 +1073,11 @@ typedef struct _PTPNIKONWifiProfile PTPNIKONWifiProfile;
#define PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN 0
#define PTP_CANON_EOS_CHANGES_TYPE_OBJECTINFO 1
#define PTP_CANON_EOS_CHANGES_TYPE_OBJECTTRANSFER 2
+#define PTP_CANON_EOS_CHANGES_TYPE_PROPERTY 3
+#define PTP_CANON_EOS_CHANGES_TYPE_CAMERASTATUS 4
struct _PTPCanon_New_Object {
- uint32_t oid;
+ uint32_t oid;
PTPObjectInfo oi;
};
@@ -1075,6 +1085,9 @@ struct _PTPCanon_changes_entry {
int type;
union {
struct _PTPCanon_New_Object object; /* TYPE_OBJECTINFO */
+ char *info;
+ uint16_t propid;
+ int status;
} u;
};
typedef struct _PTPCanon_changes_entry PTPCanon_changes_entry;
@@ -1963,6 +1976,7 @@ struct _PTPParams {
PTPCanon_changes_entry *backlogentries;
int nrofbacklogentries;
int eos_captureenabled;
+ int eos_viewfinderenabled;
/* PTP: Wifi profiles */
uint8_t wifi_profiles_version;
@@ -2312,19 +2326,7 @@ uint16_t ptp_canon_checkevent (PTPParams* params,
*
**/
#define ptp_canon_eos_requestdevicepropvalue(params,prop) ptp_generic_no_data(params,PTP_OC_CANON_EOS_RequestDevicePropValue,1,prop)
-/**
- * ptp_canon_eos_capture:
- *
- * This starts a EOS400D style capture. You have to use the
- * 0x9116 command to poll for its completion.
- * The image is saved on the CF Card currently.
- *
- * params: PTPParams*
- *
- * Return values: Some PTP_RC_* code.
- *
- **/
-#define ptp_canon_eos_capture(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_RemoteRelease,0)
+uint16_t ptp_canon_eos_capture (PTPParams* params, uint32_t *result);
uint16_t ptp_canon_eos_getevent (PTPParams* params, PTPCanon_changes_entry **entries, int *nrofentries);
uint16_t ptp_canon_getpartialobject (PTPParams* params, uint32_t handle,
uint32_t offset, uint32_t size,
@@ -2481,6 +2483,19 @@ uint16_t ptp_nikon_writewifiprofile (PTPParams* params, PTPNIKONWifiProfile* pro
**/
#define ptp_canon_eos_afdrive(params) ptp_generic_no_data(params,PTP_OC_CANON_EOS_DoAf,0)
/**
+ * ptp_canon_eos_zoom:
+ *
+ * This command runs (drives) the lens autofocus.
+ *
+ * params: PTPParams*
+ * params: arg1 unknown
+ *
+ * Return values: Some PTP_RC_* code.
+ *
+ **/
+#define ptp_canon_eos_zoom(params,x) ptp_generic_no_data(params,PTP_OC_CANON_EOS_Zoom,1,x)
+#define ptp_canon_eos_zoomposition(params,x,y) ptp_generic_no_data(params,PTP_OC_CANON_EOS_ZoomPosition,2,x,y)
+/**
* ptp_nikon_mfdrive:
*
* This command runs (drives) the lens focus manually.
@@ -2583,7 +2598,18 @@ uint16_t ptp_nikon_getfileinfoinblock (PTPParams* params, uint32_t p1, uint32_t
uint16_t ptp_mtp_getobjectpropssupported (PTPParams* params, uint16_t ofc, uint32_t *propnum, uint16_t **props);
/* Non PTP protocol functions */
-int ptp_operation_issupported (PTPParams* params, uint16_t operation);
+static int
+ptp_operation_issupported(PTPParams* params, uint16_t operation)
+{
+ int i=0;
+
+ for (;i<params->deviceinfo.OperationsSupported_len;i++) {
+ if (params->deviceinfo.OperationsSupported[i]==operation)
+ return 1;
+ }
+ return 0;
+}
+
int ptp_event_issupported (PTPParams* params, uint16_t event);
int ptp_property_issupported (PTPParams* params, uint16_t property);