aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Niestroj <m.niestroj@grinn-global.com>2017-06-10 16:36:18 +0200
committerMarcus Meissner <marcus@jet.franken.de>2017-06-10 16:36:59 +0200
commit718b2909ce8e7ffc20658ae6421ba288869b105a (patch)
tree76e0a39d919fe4d4f1947a9fb922f3580a264d7c
parent7e8c8508f18fc62c31927119fe4ed59aa9a0c9a4 (diff)
downloadlibmtp-718b2909ce8e7ffc20658ae6421ba288869b105a.tar.gz
Implemented a LIBMTP_Custom_Operation operation (no data transfer)
-rw-r--r--src/libmtp.c34
-rw-r--r--src/libmtp.h.in7
-rw-r--r--src/libmtp.sym1
3 files changed, 42 insertions, 0 deletions
diff --git a/src/libmtp.c b/src/libmtp.c
index cf4fba1..432f6b1 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -45,6 +45,7 @@
#include "mtpz.h"
+#include <stdarg.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
@@ -9154,3 +9155,36 @@ static void update_metadata_cache(LIBMTP_mtpdevice_t *device, uint32_t object_id
ptp_remove_object_from_cache(params, object_id);
add_object_to_cache(device, object_id);
}
+
+
+/**
+ * Issue custom (e.g. vendor specific) operation (without data phase)
+ * @param device a pointer to the device to send custom operation to.
+ * @param code operation code to send.
+ * @param n_param number of parameters passed.
+ * @param ... uint32_t operation specific parameters.
+ */
+int LIBMTP_Custom_Operation(LIBMTP_mtpdevice_t *device, uint16_t code, int n_param, ...)
+{
+ PTPParams *params = (PTPParams *) device->params;
+ PTPContainer ptp;
+ va_list args;
+ uint16_t ret;
+ int i;
+
+ ptp.Code = code;
+ ptp.Nparam = n_param;
+ va_start(args, n_param);
+ for (i = 0; i < n_param; i++)
+ (&ptp.Param1)[i] = va_arg(args, uint32_t);
+ va_end(args);
+
+ ret = ptp_transaction_new(params, &ptp, PTP_DP_NODATA, 0, NULL);
+
+ if (ret != PTP_RC_OK) {
+ add_ptp_error_to_errorstack(device, ret, "LIBMTP_Custom_Operation(): failed to execute operation.");
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/libmtp.h.in b/src/libmtp.h.in
index 7165f46..6a12891 100644
--- a/src/libmtp.h.in
+++ b/src/libmtp.h.in
@@ -1058,6 +1058,13 @@ int LIBMTP_Read_Event(LIBMTP_mtpdevice_t *, LIBMTP_event_t *, uint32_t *);
int LIBMTP_Read_Event_Async(LIBMTP_mtpdevice_t *, LIBMTP_event_cb_fn, void *);
int LIBMTP_Handle_Events_Timeout_Completed(struct timeval *, int *);
+/**
+ * @}
+ * @defgroup custom Custom operations API.
+ * @{
+ */
+int LIBMTP_Custom_Operation(LIBMTP_mtpdevice_t *, uint16_t, int, ...);
+
/** @} */
/* End of C++ exports */
diff --git a/src/libmtp.sym b/src/libmtp.sym
index 156b003..a05d6dd 100644
--- a/src/libmtp.sym
+++ b/src/libmtp.sym
@@ -110,3 +110,4 @@ LIBMTP_BeginEditObject
LIBMTP_EndEditObject
LIBMTP_TruncateObject
LIBMTP_Check_Capability
+LIBMTP_Custom_Operation