From: Adhavan M Date: Fri, 4 May 2018 10:36:45 +0000 (+0000) Subject: Revert "Extract descriptors and strings to binary files during compilation" X-Git-Tag: submit/tizen/20180504.104640~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ada79938c7f386326c48b40f393d9ce2a3dfdc7;p=sdk%2Ftarget%2Fsdbd.git Revert "Extract descriptors and strings to binary files during compilation" This reverts commit fdfe62c3c3d634427a8b983418cdc9aef07f5bfa. Change-Id: Ic346eae1081f3872f454f45ddc921414a2c00caf --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4416ce1..b839a10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,6 @@ SET(SDBD_SRCS src/hashtable.c src/plugin.c src/plugin_encrypt.c - src/descs_strings.c ) SET(SDBD_SUBS src/subprocess.c @@ -133,15 +132,6 @@ endif() install(TARGETS sdbd sdbd-user DESTINATION /usr/sbin) install(FILES script/sdbd DESTINATION /etc/init.d) -# Extract descriptors and strings for systemd socket activation -add_executable(extract_descs_strings src/extract_descs_strings.c src/descs_strings.c) -add_custom_command(OUTPUT descs strs - COMMAND ./extract_descs_strings - DEPENDS extract_descs_strings) -add_custom_target(descs_strings ALL DEPENDS descs strs) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/descs DESTINATION /etc/sdbd) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/strs DESTINATION /etc/sdbd) # Optionally build unit tests binary -- could be helpful during further development if(BUILD_UNIT_TESTS) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 8bba6c1..348e8cf 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -132,8 +132,6 @@ chsmack -e "User::Shell" /sbin/sdbd-user %{_unitdir}/multi-user.target.wants/sdbd.service %{_prefix}/lib/udev/rules.d/99-sdbd.rules %{TZ_SYS_BIN}/profile_command -%{_sysconfdir}/sdbd/descs -%{_sysconfdir}/sdbd/strs %ifarch %{ix86} x86_64 %post extension-emulator diff --git a/src/descs_strings.c b/src/descs_strings.c deleted file mode 100644 index f7da352..0000000 --- a/src/descs_strings.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "descs_strings.h" -#include "sdb.h" - -struct sdb_usb_descs descriptors = { - .header = { - .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC), - .length = cpu_to_le32(sizeof(descriptors)), - .fs_count = 3, - .hs_count = 3, - }, - .fs_descs = { - .intf = { - .bLength = sizeof(descriptors.fs_descs.intf), - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bNumEndpoints = 2, - .bInterfaceClass = SDB_CLASS, - .bInterfaceSubClass = SDB_SUBCLASS, - .bInterfaceProtocol = SDB_PROTOCOL, - .iInterface = 1, /* first string from the provided table */ - }, - .source = { - .bLength = sizeof(descriptors.fs_descs.source), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 1 | USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = MAX_PACKET_SIZE_FS, - }, - .sink = { - .bLength = sizeof(descriptors.fs_descs.sink), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 2 | USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = MAX_PACKET_SIZE_FS, - }, - }, - .hs_descs = { - .intf = { - .bLength = sizeof(descriptors.hs_descs.intf), - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bNumEndpoints = 2, - .bInterfaceClass = SDB_CLASS, - .bInterfaceSubClass = SDB_SUBCLASS, - .bInterfaceProtocol = SDB_PROTOCOL, - .iInterface = 1, /* first string from the provided table */ - }, - .source = { - .bLength = sizeof(descriptors.hs_descs.source), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 1 | USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = MAX_PACKET_SIZE_HS, - }, - .sink = { - .bLength = sizeof(descriptors.hs_descs.sink), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 2 | USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = MAX_PACKET_SIZE_HS, - }, - }, -}; - -struct sdb_usb_strings strings = { - .header = { - .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC), - .length = cpu_to_le32(sizeof(strings)), - .str_count = cpu_to_le32(1), - .lang_count = cpu_to_le32(1), - }, - .lang0 = { - cpu_to_le16(0x0409), /* en-us */ - STR_INTERFACE, - }, -}; diff --git a/src/descs_strings.h b/src/descs_strings.h deleted file mode 100644 index 26c5ac4..0000000 --- a/src/descs_strings.h +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -#define TRACE_TAG TRACE_USB - -#define MAX_PACKET_SIZE_FS 64 -#define MAX_PACKET_SIZE_HS 512 - -#define cpu_to_le16(x) htole16(x) -#define cpu_to_le32(x) htole32(x) - -extern struct sdb_usb_descs { - struct usb_functionfs_descs_head header; - struct { - struct usb_interface_descriptor intf; - struct usb_endpoint_descriptor_no_audio source; - struct usb_endpoint_descriptor_no_audio sink; - } __attribute__((packed)) fs_descs, hs_descs; -} __attribute__((packed)) descriptors; - -#define STR_INTERFACE "SDB Interface" - -extern struct sdb_usb_strings { - struct usb_functionfs_strings_head header; - struct { - __le16 code; - const char str1[sizeof(STR_INTERFACE)]; - } __attribute__((packed)) lang0; -} __attribute__((packed)) strings; diff --git a/src/extract_descs_strings.c b/src/extract_descs_strings.c deleted file mode 100644 index 64d5b7e..0000000 --- a/src/extract_descs_strings.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include "descs_strings.h" - -/* - * Writing descriptors and strings to binary file - */ - -int main() { - - int ret; - FILE *descs, *strs; - - /* open file for descriptors */ - descs = fopen("descs","w"); - if (!descs){ - ret = -errno; - perror("could not open file with descriptors"); - return ret; - } - - /* open file for strings */ - strs = fopen("strs", "w"); - if (!strs) { - ret = -errno; - perror("could not open file with strings"); - return ret; - } - - /* write descriptors to file */ - ret = fwrite(&descriptors, sizeof(descriptors), 1, descs); - if (ret < 0) { - perror("could not write descriptors"); - return ferror(descs); - } - - /* write strings to file */ - ret = fwrite(&strings, sizeof(strings), 1, strs); - if(ret < 0) { - perror("could not write strings"); - return ferror(strs); - } - - fclose(descs); - fclose(strs); - - return 0; -} - diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index 3e1ef6b..7522c11 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -25,18 +25,115 @@ #include #include +#include +#include + #include "sysdeps.h" #define TRACE_TAG TRACE_USB #include "log.h" #include "sdb.h" -#include "descs_strings.h" + +#define MAX_PACKET_SIZE_FS 64 +#define MAX_PACKET_SIZE_HS 512 + +#define cpu_to_le16(x) htole16(x) +#define cpu_to_le32(x) htole32(x) static const char ep0_path[] = USB_FUNCFS_SDB_PATH"/ep0"; static const char ep1_path[] = USB_FUNCFS_SDB_PATH"/ep1"; static const char ep2_path[] = USB_FUNCFS_SDB_PATH"/ep2"; +static const struct { + struct usb_functionfs_descs_head header; + struct { + struct usb_interface_descriptor intf; + struct usb_endpoint_descriptor_no_audio source; + struct usb_endpoint_descriptor_no_audio sink; + } __attribute__((packed)) fs_descs, hs_descs; +} __attribute__((packed)) descriptors = { + .header = { + .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC), + .length = cpu_to_le32(sizeof(descriptors)), + .fs_count = 3, + .hs_count = 3, + }, + .fs_descs = { + .intf = { + .bLength = sizeof(descriptors.fs_descs.intf), + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bNumEndpoints = 2, + .bInterfaceClass = SDB_CLASS, + .bInterfaceSubClass = SDB_SUBCLASS, + .bInterfaceProtocol = SDB_PROTOCOL, + .iInterface = 1, /* first string from the provided table */ + }, + .source = { + .bLength = sizeof(descriptors.fs_descs.source), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = MAX_PACKET_SIZE_FS, + }, + .sink = { + .bLength = sizeof(descriptors.fs_descs.sink), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 2 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = MAX_PACKET_SIZE_FS, + }, + }, + .hs_descs = { + .intf = { + .bLength = sizeof(descriptors.hs_descs.intf), + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bNumEndpoints = 2, + .bInterfaceClass = SDB_CLASS, + .bInterfaceSubClass = SDB_SUBCLASS, + .bInterfaceProtocol = SDB_PROTOCOL, + .iInterface = 1, /* first string from the provided table */ + }, + .source = { + .bLength = sizeof(descriptors.hs_descs.source), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = MAX_PACKET_SIZE_HS, + }, + .sink = { + .bLength = sizeof(descriptors.hs_descs.sink), + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 2 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = MAX_PACKET_SIZE_HS, + }, + }, +}; + +#define STR_INTERFACE "SDB Interface" + +static const struct { + struct usb_functionfs_strings_head header; + struct { + __le16 code; + const char str1[sizeof(STR_INTERFACE)]; + } __attribute__((packed)) lang0; +} __attribute__((packed)) strings = { + .header = { + .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC), + .length = cpu_to_le32(sizeof(strings)), + .str_count = cpu_to_le32(1), + .lang_count = cpu_to_le32(1), + }, + .lang0 = { + cpu_to_le16(0x0409), /* en-us */ + STR_INTERFACE, + }, +}; + /* A local struct to store state of application */ struct usb_handle