Extract descriptors and strings to binary files during compilation 89/60689/7
authorGeorgia Brikis <g.brikis@samsung.com>
Thu, 25 Feb 2016 10:51:13 +0000 (11:51 +0100)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Mon, 5 Mar 2018 13:12:58 +0000 (14:12 +0100)
For socket activation FunctionFs descriptors and strings have to be
provided as binary files. This commit adds support for extracting FFs
strings and descriptors during compilation and installing them.

Change-Id: I8a063e9d6c49d6703cc751e55fe4b86dafaa9e0d
Signed-off-by: Georgia Brikis <g.brikis@samsung.com>
[Rebased for Tizen 5.0]
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
CMakeLists.txt
packaging/sdbd.spec
src/descs_strings.c [new file with mode: 0644]
src/descs_strings.h [new file with mode: 0644]
src/extract_descs_strings.c [new file with mode: 0644]
src/usb_funcfs_client.c

index b839a10..4416ce1 100644 (file)
@@ -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)
index e206b39..06f955f 100644 (file)
@@ -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 (file)
index 0000000..f7da352
--- /dev/null
@@ -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 (file)
index 0000000..26c5ac4
--- /dev/null
@@ -0,0 +1,29 @@
+#include <linux/usb/ch9.h>
+#include <linux/usb/functionfs.h>
+
+#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 (file)
index 0000000..64d5b7e
--- /dev/null
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <errno.h>
+#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;
+}
+
index 7522c11..3e1ef6b 100644 (file)
 #include <dirent.h>
 #include <errno.h>
 
-#include <linux/usb/ch9.h>
-#include <linux/usb/functionfs.h>
-
 #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