summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2006-11-12 19:25:06 +0000
committerMarcus Meissner <marcus@jet.franken.de>2006-11-12 19:25:06 +0000
commit48e5e91d48f8d30ab21c06a7593c8b381b16865c (patch)
tree2d90d21ce179282ff2e9836d782b7d3edf8c8c85
parent58690e77af2df1765d96cd2e7a0934ff4bf1a92f (diff)
downloadlibgphoto2-48e5e91d48f8d30ab21c06a7593c8b381b16865c.tar.gz
ptp_mtp_sendobjectproplist implementation from the libmtp folks.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9392 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r--camlibs/ptp2/ChangeLog5
-rw-r--r--camlibs/ptp2/ptp-pack.c59
-rw-r--r--camlibs/ptp2/ptp.c37
-rw-r--r--camlibs/ptp2/ptp.h13
4 files changed, 112 insertions, 2 deletions
diff --git a/camlibs/ptp2/ChangeLog b/camlibs/ptp2/ChangeLog
index 646c27789..4dce595f5 100644
--- a/camlibs/ptp2/ChangeLog
+++ b/camlibs/ptp2/ChangeLog
@@ -1,3 +1,8 @@
+2006-11-12 Marcus Meissner <marcus@jet.franken.de>
+
+ * ptp.c, ptp.h, ptp-pack.c: Implementation of
+ MTP_SendObjectproplist from the libmtp folks.
+
2006-11-07 Marcus Meissner <marcus@jet.franken.de>
* library.c: Do incremental event read only for
diff --git a/camlibs/ptp2/ptp-pack.c b/camlibs/ptp2/ptp-pack.c
index 277c7ad13..b50b597fc 100644
--- a/camlibs/ptp2/ptp-pack.c
+++ b/camlibs/ptp2/ptp-pack.c
@@ -172,7 +172,7 @@ ptp_pack_string(PTPParams *params, char *string, unsigned char* data, uint16_t o
static inline unsigned char *
ptp_get_packed_stringcopy(PTPParams *params, char *string, uint32_t *packed_size)
{
-uint8_t packed[PTP_MAXSTRLEN+3], len;
+ uint8_t packed[PTP_MAXSTRLEN+3], len;
size_t plen;
unsigned char *retcopy = NULL;
@@ -832,6 +832,63 @@ ptp_pack_DPV (PTPParams *params, PTPPropertyValue* value, unsigned char** dpvptr
return size;
}
+#define MAX_MTP_PROPS 127
+static inline uint32_t
+ptp_pack_OPL (PTPParams *params, MTPPropList *proplist, unsigned char** opldataptr, uint32_t objectid)
+{
+ unsigned char* opldata;
+ MTPPropList *propitr;
+ unsigned char *packedprops[MAX_MTP_PROPS];
+ uint32_t packedpropslens[MAX_MTP_PROPS];
+ uint16_t packedpropsids[MAX_MTP_PROPS];
+ uint16_t packedpropstypes[MAX_MTP_PROPS];
+ uint32_t totalsize = 0;
+ uint32_t bufp = 0;
+ uint32_t noitems = 0;
+ uint32_t i;
+
+ totalsize = sizeof(uint32_t); /* 4 bytes to store the number of elements */
+ propitr = proplist;
+ while (propitr != NULL && noitems < MAX_MTP_PROPS) {
+ /* Overhead for each item */
+ totalsize += sizeof(uint32_t); /* Object ID */
+ /* Metadata type */
+ packedpropsids[noitems]=propitr->property;
+ totalsize += sizeof(uint16_t);
+ /* Data type */
+ packedpropstypes[noitems]= propitr->datatype;
+ totalsize += sizeof(uint16_t);
+ /* Add each property to be sent. */
+ packedpropslens[noitems] = ptp_pack_DPV (params, &propitr->propval, &packedprops[noitems], propitr->datatype);
+ totalsize += packedpropslens[noitems];
+ noitems ++;
+ propitr = propitr->next;
+ }
+
+ /* Allocate memory for the packed property list */
+ opldata = malloc(totalsize);
+
+ htod32a(&opldata[bufp],noitems);
+ bufp += 4;
+
+ /* Copy into a nice packed list */
+ for (i = 0; i < noitems; i++) {
+ /* Object ID */
+ htod32a(&opldata[bufp],objectid);
+ bufp += sizeof(uint32_t);
+ htod16a(&opldata[bufp],packedpropsids[i]);
+ bufp += sizeof(uint16_t);
+ htod16a(&opldata[bufp],packedpropstypes[i]);
+ bufp += sizeof(uint16_t);
+ /* The copy the actual property */
+ memcpy(&opldata[bufp], packedprops[i], packedpropslens[i]);
+ bufp += packedpropslens[i];
+ free(packedprops[i]);
+ }
+ *opldataptr = opldata;
+ return totalsize;
+}
+
/*
PTP USB Event container unpack
Copyright (c) 2003 Nikolai Kopanygin
diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c
index bef5c7fd5..4a58a33d8 100644
--- a/camlibs/ptp2/ptp.c
+++ b/camlibs/ptp2/ptp.c
@@ -2531,6 +2531,43 @@ ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArr
return ret;
}
+uint16_t
+ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle,
+ uint16_t objecttype, uint64_t objectsize, MTPPropList *proplist)
+{
+ uint16_t ret;
+ PTPContainer ptp;
+ int old_split_header_data;
+ unsigned char* opldata=NULL;
+ uint32_t oplsize;
+
+ PTP_CNT_INIT(ptp);
+ ptp.Code = PTP_OC_MTP_SendObjectPropList;
+ ptp.Param1 = *store;
+ ptp.Param2 = *parenthandle;
+ ptp.Param3 = (uint32_t) objecttype;
+ ptp.Param4 = (uint32_t) (objectsize >> 32);
+ ptp.Param5 = (uint32_t) (objectsize & 0xffffffffU);
+ ptp.Nparam = 5;
+
+ /* Temporary disable split headers */
+ old_split_header_data = params->split_header_data;
+ params->split_header_data = 0;
+
+ /* Set object handle to 0 for a new object */
+ oplsize = ptp_pack_OPL(params,proplist,&opldata,*handle);
+ ret = ptp_transaction(params, &ptp, PTP_DP_SENDDATA, oplsize, &opldata, NULL);
+ free(opldata);
+ *store = ptp.Param1;
+ *parenthandle = ptp.Param2;
+ *handle = ptp.Param3;
+
+ /* Restore split headers */
+ params->split_header_data = old_split_header_data;
+
+ return ret;
+}
+
/* Non PTP protocol functions */
/* devinfo testing functions */
diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h
index d5c1c4b4d..f8aefced4 100644
--- a/camlibs/ptp2/ptp.h
+++ b/camlibs/ptp2/ptp.h
@@ -594,6 +594,15 @@ union _PTPPropertyValue {
typedef union _PTPPropertyValue PTPPropertyValue;
+/* Metadata lists for MTP operations */
+struct _MTPPropList {
+ uint16_t property;
+ uint16_t datatype;
+ PTPPropertyValue propval;
+ struct _MTPPropList *next;
+};
+typedef struct _MTPPropList MTPPropList;
+
struct _PTPPropDescRangeForm {
PTPPropertyValue MinimumValue;
PTPPropertyValue MaximumValue;
@@ -1223,6 +1232,7 @@ uint16_t ptp_getdevicepropvalue (PTPParams* params, uint16_t propcode,
uint16_t ptp_setdevicepropvalue (PTPParams* params, uint16_t propcode,
PTPPropertyValue* value, uint16_t datatype);
+/* Microsoft MTP extensions */
uint16_t ptp_mtp_getobjectpropdesc (PTPParams* params, uint16_t opc, uint16_t ofc,
PTPObjectPropDesc *objectpropertydesc);
uint16_t ptp_mtp_getobjectpropvalue (PTPParams* params, uint32_t oid, uint16_t opc,
@@ -1231,7 +1241,8 @@ uint16_t ptp_mtp_setobjectpropvalue (PTPParams* params, uint32_t oid, uint16_t o
PTPPropertyValue *value, uint16_t datatype);
uint16_t ptp_mtp_getobjectreferences (PTPParams* params, uint32_t handle, uint32_t** ohArray, uint32_t* arraylen);
uint16_t ptp_mtp_setobjectreferences (PTPParams* params, uint32_t handle, uint32_t* ohArray, uint32_t arraylen);
-
+uint16_t ptp_mtp_sendobjectproplist (PTPParams* params, uint32_t* store, uint32_t* parenthandle, uint32_t* handle,
+ uint16_t objecttype, uint64_t objectsize, MTPPropList *proplist);
/* Eastman Kodak extensions */
uint16_t ptp_ek_9007 (PTPParams* params, unsigned char **serial, unsigned int *size);