linux)
AC_DEFINE(OS_LINUX, 1, [Linux backend])
AC_SUBST(OS_LINUX)
- AC_ARG_ENABLE([deviced],
- [AC_HELP_STRING([--enable-deviced], [Use deviced to obtain dev node fds [default=no]])],
- [], [enable_deviced="no"])
- if test "x$enable_deviced" = "xyes"; then
- PKG_CHECK_MODULES([DEVICED], [deviced])
- AC_DEFINE(USE_DEVICED, 1, [Use deviced to obtain dev node fds])
+ AC_ARG_ENABLE([usbhost_api],
+ [AC_HELP_STRING([--enable-usbhost-api], [Request to deviced to obtain dev node fds [default=no]])],
+ [], [enable_usbhost_api="no"])
+ if test "x$enable_usbhost_api" = "xyes"; then
+ PKG_CHECK_MODULES([USBHOST_API], [dbus-1])
+ AC_DEFINE(USE_USBHOST_API, 1, [Request to deviced to obtain dev node fds])
fi
- AC_SUBST(USE_DEVICED)
+ AC_SUBST(USE_USBHOST_API)
AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
AC_ARG_ENABLE([udev],
AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
-AM_CONDITIONAL(USE_DEVICED, test "x$enable_deviced" = xyes)
+AM_CONDITIONAL(USE_USBHOST_API, test "x$enable_usbhost_api" = xyes)
if test "$threads" = posix; then
AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
fi
#include <unistd.h>
/* Tizen specific */
-#ifdef USE_DEVICED
-#include <dd-usbhost.h>
+#ifdef USE_USBHOST_API
+#include <dbus/dbus.h>
#endif
#include "libusb.h"
return fd;
}
-#ifdef USE_DEVICED
+#ifdef USE_USBHOST_API
+
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD"
+#define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME
+#define DEVICED_PATH_USBHOST DEVICED_OBJECT_PATH"/Usbhost"
+#define DEVICED_INTERFACE_USBHOST DEVICED_INTERFACE_NAME".Usbhost"
+#define METHOD_OPEN_DEVICE "OpenDevice"
+
+DBusMessage *dbus_method_sync_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method, const char *param)
+{
+ DBusConnection *conn;
+ DBusMessage *msg;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ DBusError err;
+
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ usbi_err(NULL, "dbus_bus_get error");
+ return NULL;
+ }
+
+ msg = dbus_message_new_method_call(dest, path, interface, method);
+ if (!msg) {
+ usbi_err(NULL, "dbus_message_new_method_call(%s:%s-%s)",
+ path, interface, method);
+ return NULL;
+ }
+
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &path);
+
+ dbus_error_init(&err);
+
+ reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
+ if (!reply) {
+ usbi_err(NULL, "dbus_connection_send error(No reply) %s %s:%s-%s",
+ dest, path, interface, method);
+ }
+
+ if (dbus_error_is_set(&err)) {
+ usbi_err(NULL, "dbus_connection_send error(%s:%s) %s %s:%s-%s",
+ err.name, err.message, dest, path, interface, method);
+ dbus_error_free(&err);
+ reply = NULL;
+ }
+
+ dbus_message_unref(msg);
+ return reply;
+}
+
+static int open_usb_device(const char *path, int *fd)
+{
+ DBusMessage *reply;
+ DBusError err;
+ int ret, rfd;
+ dbus_bool_t result;
+
+ if (!fd || !path)
+ return -EINVAL;
+
+ dbus_error_init(&err);
+
+ reply = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_USBHOST,
+ DEVICED_INTERFACE_USBHOST,
+ METHOD_OPEN_DEVICE,
+ path);
+
+ if (!reply) {
+ usbi_err(NULL, "Unable to open USB device");
+ return -1;
+ }
+
+ result = dbus_message_get_args(reply, &err,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_UNIX_FD, &rfd,
+ DBUS_TYPE_INVALID);
+ if (!result) {
+ usbi_err(NULL, "Failed to get arguments: %s", err.message);
+ return -1;
+ }
+
+ if (ret >= 0)
+ *fd = rfd;
+
+ return ret;
+}
+
static int _ask_for_open(const char *path, mode_t mode, int silent)
{
int ret;
return ret;
}
-#endif /* USE_DEVICED */
+#endif /* USE_USBHOST_API */
static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
{
if (fd != -1)
return fd; /* Success */
-#ifdef USE_DEVICED
+#ifdef USE_USBHOST_API
/*
* If we are here, we were unable to go simple
* path and open the device directly. In Tizen
if (fd != -1)
return fd;
}
-#endif /* USE_DEVICED */
+#endif /* USE_USBHOST_API */
if (!silent) {
usbi_err(ctx, "libusb couldn't open USB device %s: %s",
struct stat statbuf;
int r;
-#ifdef USE_DEVICED
+#ifdef USE_USBHOST_API
/* find_usbfs_path() may fail if there are no devices connected.
* We assume that /dev/bus/usb is usbfs mount point. */
usbfs_path = "/dev/bus/usb";