From: Adhavan M Date: Fri, 4 May 2018 11:32:39 +0000 (+0000) Subject: Revert "Revert "Extract descriptors and strings to binary files during compilation"" X-Git-Tag: submit/tizen/20180504.114430~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F177941%2F2;p=sdk%2Ftarget%2Fsdbd.git Revert "Revert "Extract descriptors and strings to binary files during compilation"" This reverts commit 7ada79938c7f386326c48b40f393d9ce2a3dfdc7. Change-Id: I0227dfbe9a46f9149869d9a6bda72555d536c38d --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b839a10..4416ce1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ SET(SDBD_SRCS src/hashtable.c src/plugin.c src/plugin_encrypt.c + src/descs_strings.c ) SET(SDBD_SUBS src/subprocess.c @@ -132,6 +133,15 @@ 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 348e8cf..8bba6c1 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -132,6 +132,8 @@ 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 new file mode 100644 index 0000000..f7da352 --- /dev/null +++ b/src/descs_strings.c @@ -0,0 +1,76 @@ +#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 new file mode 100644 index 0000000..26c5ac4 --- /dev/null +++ b/src/descs_strings.h @@ -0,0 +1,29 @@ +#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 new file mode 100644 index 0000000..64d5b7e --- /dev/null +++ b/src/extract_descs_strings.c @@ -0,0 +1,49 @@ +#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 7522c11..3e1ef6b 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -25,115 +25,18 @@ #include #include -#include -#include - #include "sysdeps.h" #define TRACE_TAG TRACE_USB #include "log.h" #include "sdb.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) +#include "descs_strings.h" 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