src/init.c
src/fileutils.c
src/commandline_sdbd.c
+ src/usb_linux_client.c
+ src/usb_funcfs_client.c
)
include_directories(src)
-if(USE_FUNCTION_FS)
- list(APPEND sdbd_SRCS src/usb_funcfs_client.c)
-else()
- list(APPEND sdbd_SRCS src/usb_linux_client.c)
-endif()
-
add_executable(sdbd ${sdbd_SRCS})
set_property(
-/*
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*-
+ *
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
SdbdCommandlineArgs sdbd_commandline_args;
#endif
+void (*usb_init)() = NULL;
+void (*usb_cleanup)() = NULL;
+int (*usb_write)(usb_handle *h, const void *data, int len) = NULL;
+int (*usb_read)(usb_handle *h, void *data, int len) = NULL;
+int (*usb_close)(usb_handle *h) = NULL;
+void (*usb_kick)(usb_handle *h) = NULL;
+
int is_emulator(void) {
#if SDB_HOST
return 0;
}
if (!is_emulator()) {
+ /* choose the usb gadget backend */
+ if (access(USB_NODE_FILE, F_OK) == 0) {
+ /* legacy kernel-based sdb gadget */
+ usb_init = &linux_usb_init;
+ usb_cleanup = &linux_usb_cleanup;
+ usb_write = &linux_usb_write;
+ usb_read = &linux_usb_read;
+ usb_close = &linux_usb_close;
+ usb_kick = &linux_usb_kick;
+ } else {
+ /* functionfs based gadget */
+ usb_init = &ffs_usb_init;
+ usb_cleanup = &ffs_usb_cleanup;
+ usb_write = &ffs_usb_write;
+ usb_read = &ffs_usb_read;
+ usb_close = &ffs_usb_close;
+ usb_kick = &ffs_usb_kick;
+ }
// listen on USB
usb_init();
}
int local_connect_arbitrary_ports(int console_port, int sdb_port, const char *device_name);
/* usb host/client interface */
+#if SDB_HOST
void usb_init();
void usb_cleanup();
int usb_write(usb_handle *h, const void *data, int len);
int usb_read(usb_handle *h, void *data, int len);
int usb_close(usb_handle *h);
void usb_kick(usb_handle *h);
+#else
+
+extern void (*usb_init)();
+extern void (*usb_cleanup)();
+extern int (*usb_write)(usb_handle *h, const void *data, int len);
+extern int (*usb_read)(usb_handle *h, void *data, int len);
+extern int (*usb_close)(usb_handle *h);
+extern void (*usb_kick)(usb_handle *h);
+
+/* functionfs backend */
+void ffs_usb_init();
+void ffs_usb_cleanup();
+int ffs_usb_write(usb_handle *h, const void *data, int len);
+int ffs_usb_read(usb_handle *h, void *data, int len);
+int ffs_usb_close(usb_handle *h);
+void ffs_usb_kick(usb_handle *h);
+
+/* kernel sdb gadget backend */
+void linux_usb_init();
+void linux_usb_cleanup();
+int linux_usb_write(usb_handle *h, const void *data, int len);
+int linux_usb_read(usb_handle *h, void *data, int len);
+int linux_usb_close(usb_handle *h);
+void linux_usb_kick(usb_handle *h);
+
+#endif
/* used for USB device detection */
#if SDB_HOST
sdb_mutex_unlock(&h->control_lock);
}
-
-void usb_cleanup()
-{
- /* nothing to do here */
-}
-
-
static void *usb_open_thread(void *x)
{
struct usb_handle *usb = (struct usb_handle *)x;
/*
- * Writes data to bulk_in descriptor
- *
- * In fact, data is forwarded to bulk_write.
- *
- * @returns 0 on success and -1 on failure (errno is set)
- */
-int usb_write(usb_handle *h, const void *data, int len)
-{
- int n;
-
- D("about to write (fd=%d, len=%d)\n", h->bulk_in, len);
- n = bulk_write(h->bulk_in, data, len);
- if(n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->bulk_in, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->bulk_in);
- return 0;
-}
-
-
-/*
* Reads data from bulkout_fd
*
* Blocks until length data is read or error occurs.
return count;
}
-
-/*
- * Reads data from bulk_out descriptor
- *
- * In fact, reading task is forwarded to bulk_read.
- *
- * @returns 0 on success and -1 on failure (errno is set)
- */
-int usb_read(usb_handle *h, void *data, int len)
-{
- int n;
-
- D("%d: about to read (fd=%d, len=%d)\n", getpid(), h->bulk_out, len);
- n = bulk_read(h->bulk_out, data, len);
- if(n != len) {
- D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
- h->bulk_out, n, errno, strerror(errno));
- return -1;
- }
- D("[ done fd=%d ]\n", h->bulk_out);
- return 0;
-}
-
-
/*
* Checks if EP0 exists on filesystem
*/
-int ep0_exists()
+static int ep0_exists()
{
struct stat statb;
return stat(ep0_path, &statb) == 0;
/*
+ * Public host/client interface
+ */
+
+
+/*
* Creates and starts USB threads
*/
-void usb_init()
+void ffs_usb_init()
{
usb_handle *h;
sdb_thread_t tid;
}
-void usb_kick(usb_handle *h)
+void ffs_usb_cleanup()
+{
+ /* nothing to do here */
+}
+
+
+/*
+ * Writes data to bulk_in descriptor
+ *
+ * In fact, data is forwarded to bulk_write.
+ *
+ * @returns 0 on success and -1 on failure (errno is set)
+ */
+int ffs_usb_write(usb_handle *h, const void *data, int len)
+{
+ int n;
+
+ D("about to write (fd=%d, len=%d)\n", h->bulk_in, len);
+ n = bulk_write(h->bulk_in, data, len);
+ if(n != len) {
+ D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
+ h->bulk_in, n, errno, strerror(errno));
+ return -1;
+ }
+ D("[ done fd=%d ]\n", h->bulk_in);
+ return 0;
+}
+
+
+/*
+ * Reads data from bulk_out descriptor
+ *
+ * In fact, reading task is forwarded to bulk_read.
+ *
+ * @returns 0 on success and -1 on failure (errno is set)
+ */
+int ffs_usb_read(usb_handle *h, void *data, int len)
+{
+ int n;
+
+ D("%d: about to read (fd=%d, len=%d)\n", getpid(), h->bulk_out, len);
+ n = bulk_read(h->bulk_out, data, len);
+ if(n != len) {
+ D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
+ h->bulk_out, n, errno, strerror(errno));
+ return -1;
+ }
+ D("[ done fd=%d ]\n", h->bulk_out);
+ return 0;
+}
+
+
+int ffs_usb_close(usb_handle *h)
+{
+ return 0;
+}
+
+
+void ffs_usb_kick(usb_handle *h)
{
int err;
sdb_cond_signal(&h->kick_notify);
sdb_mutex_unlock(&h->kick_lock);
}
-
-
-int usb_close(usb_handle *h)
-{
- return 0;
-}
sdb_mutex_t lock;
};
-void usb_cleanup()
-{
- // nothing to do here
-}
-
static void *usb_open_thread(void *x)
{
struct usb_handle *usb = (struct usb_handle *)x;
return 0;
}
-int usb_write(usb_handle *h, const void *data, int len)
+// Public host/client interface
+
+int linux_usb_write(usb_handle *h, const void *data, int len)
{
int n;
return 0;
}
-int usb_read(usb_handle *h, void *data, int len)
+int linux_usb_read(usb_handle *h, void *data, int len)
{
int n;
return 0;
}
-void usb_init()
+void linux_usb_init()
{
usb_handle *h;
sdb_thread_t tid;
}
}
-void usb_kick(usb_handle *h)
+void linux_usb_kick(usb_handle *h)
{
D("usb_kick\n");
sdb_mutex_lock(&h->lock);
sdb_mutex_unlock(&h->lock);
}
-int usb_close(usb_handle *h)
+int linux_usb_close(usb_handle *h)
{
// nothing to do here
return 0;
}
+
+void linux_usb_cleanup()
+{
+ // nothing to do here
+}