Use mtp-responder-dummy.socket when there is no mtp-responser.socket 08/225208/1 accepted/tizen/5.5/unified/20200221.094219 submit/tizen_5.5/20200218.230832 submit/tizen_5.5/20200220.232939
authorINSUN PYO <insun.pyo@samsung.com>
Tue, 18 Feb 2020 04:41:52 +0000 (13:41 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 18 Feb 2020 06:26:36 +0000 (06:26 +0000)
The mtp-responder.socket is special in the configfs environment.
If mtp-responder.socket is missing, gadget configuration will fail.
As a result, all usb operations do not work properly.
So in environments that mtp doesn't support, use dummy mtp.

Applied target : XU3, Artik headless, RPI4

Change-Id: I34bee7c1837ada478959407cd7c6500e219f28bc
(cherry picked from commit 0202291b7c1b3be3db32bba3001d51d7efe6a362)

CMakeLists.txt
hw/usb_gadget_common.c
mtp-responder-dummy/descs [new file with mode: 0644]
mtp-responder-dummy/mtp-responder-dummy.service [new file with mode: 0644]
mtp-responder-dummy/mtp-responder-dummy.socket [new file with mode: 0644]
mtp-responder-dummy/strs [new file with mode: 0644]
packaging/libdevice-node.spec

index 452fae7..4646bb0 100644 (file)
@@ -63,6 +63,12 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/hw/ DESTINATION include/hw
 CONFIGURE_FILE(hwcommon.pc.in hwcommon.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/hwcommon.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
+# dummy mtp responder
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mtp-responder-dummy/strs DESTINATION /etc/mtp-responder-dummy)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mtp-responder-dummy/descs DESTINATION /etc/mtp-responder-dummy)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mtp-responder-dummy/mtp-responder-dummy.socket DESTINATION /usr/lib/systemd/system)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mtp-responder-dummy/mtp-responder-dummy.service DESTINATION /usr/lib/systemd/system)
+
 IF(BUILD_GTESTS STREQUAL on)
        ADD_SUBDIRECTORY(unittest)
 ENDIF()
index 2ecef99..fb6a986 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <libsyscommon/dbus-systemd.h>
 
@@ -522,6 +523,17 @@ int simple_translator_open(struct hw_info *info,
        simple_translator->id_to_gadget = simple_id_to_gadget;
        simple_translator->cleanup_gadget = simple_cleanup_gadget;
 
+       /* Use mtp-responder-dummy.socket when there is no mtp-responser.socket.
+        *
+        * The mtp-responder.socket is special in the configfs environment.
+        * If mtp-responder.socket is missing, gadget configuration will fail.
+        * As a result, all usb operations do not work properly.
+        * So in environments that mtp doesn't support, use dummy mtp.
+        */
+       if (access("/usr/lib/systemd/system/mtp-responder.socket", F_OK)) {
+               _available_funcs[USB_FUNCTION_IDX_MTP]->ffs_service = "mtp-responder-dummy";
+       }
+
        *common = &simple_translator->common;
        return 0;
 }
diff --git a/mtp-responder-dummy/descs b/mtp-responder-dummy/descs
new file mode 100644 (file)
index 0000000..0bffd51
Binary files /dev/null and b/mtp-responder-dummy/descs differ
diff --git a/mtp-responder-dummy/mtp-responder-dummy.service b/mtp-responder-dummy/mtp-responder-dummy.service
new file mode 100644 (file)
index 0000000..04e7258
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=MTP dummy responder
+StartLimitIntervalSec=0
+
+[Service]
+User=network_fw
+Group=network_fw
+RemainAfterExit=yes
+ExecStart=/usr/bin/true
+SmackProcessLabel=System
+USBFunctionDescriptors=/etc/mtp-responder-dummy/descs
+USBFunctionStrings=/etc/mtp-responder-dummy/strs
diff --git a/mtp-responder-dummy/mtp-responder-dummy.socket b/mtp-responder-dummy/mtp-responder-dummy.socket
new file mode 100644 (file)
index 0000000..3f84ab7
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=MTP dummy responder functionfs socket
+
+[Socket]
+ListenUSBFunction=/dev/usb-funcs/mtp/default
+TriggerLimitIntervalSec=0
diff --git a/mtp-responder-dummy/strs b/mtp-responder-dummy/strs
new file mode 100644 (file)
index 0000000..b0bd4ab
Binary files /dev/null and b/mtp-responder-dummy/strs differ
index 2f9b9f0..809904f 100644 (file)
@@ -54,6 +54,10 @@ make %{?jobs:-j%jobs}
 %manifest %{name}.manifest
 %license LICENSE.Apache-2.0
 %{_libdir}/*.so.*
+%{_unitdir}/mtp-responder-dummy.socket
+%{_unitdir}/mtp-responder-dummy.service
+/etc/mtp-responder-dummy/strs
+/etc/mtp-responder-dummy/descs
 
 %files devel
 %manifest %{name}.manifest