From: Wook Song Date: Fri, 18 Nov 2016 06:06:46 +0000 (+0900) Subject: pass: Remove all usb-related modules and features X-Git-Tag: accepted/tizen/mobile/20170328.053617~113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9131f6d5d37889365337440d0d240c5444e6fd0;p=platform%2Fcore%2Fsystem%2Fpass.git pass: Remove all usb-related modules and features This patch mainly removes usb (both client and host) modules, which are not necessary for pass. Several debug features using usb are also removed. Signed-off-by: Wook Song --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2534308..7ee48ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,25 +119,6 @@ IF(DISPLAY_MODULE STREQUAL on) ENDIF() ENDIF() -# usb client -IF(${USB_MODULE} STREQUAL on) - ADD_SOURCE(src/usb USB_SRCS) - SET(SRCS ${SRCS} ${USB_SRCS}) -ENDIF() - -# usb host -IF(${USBHOST_MODULE} STREQUAL on) - ADD_SOURCE(src/usbhost USBHOST_SRCS) - SET(SRCS ${SRCS} ${USBHOST_SRCS}) -ENDIF() - -IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - ADD_SOURCE(src/usb-host-test USB_HOST_TEST_SRCS) - SET(SRCS ${SRCS} ${USB_HOST_TEST_SRCS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb-host-test/test_gadget.gs - DESTINATION /etc/deviced/usb-host-test/) -ENDIF() - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) @@ -168,9 +149,6 @@ ENDIF() IF(BLOCK_MODULE STREQUAL on) SET(PKG_MODULES ${PKG_MODULES} storage app2sd capi-system-info) ENDIF() -IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - SET(PKG_MODULES ${PKG_MODULES} libkmod libusbg) -ENDIF() INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) @@ -232,16 +210,6 @@ IF(DISPLAY_MODULE STREQUAL on) INSTALL_CONF(src/display display) ENDIF() -# USB connection -IF(${USB_MODULE} STREQUAL on) - INSTALL_CONF(src/usb usb-operation) - - # USB (Manual setting) - IF(${SDB_PRESTART} STREQUAL on) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/sdb-prestart.service DESTINATION lib/systemd/system) - ENDIF(${SDB_PRESTART} STREQUAL on) -ENDIF() - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/${PROJECT_NAME}.conf DESTINATION /etc/dbus-1/system.d) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) @@ -251,16 +219,9 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/s FILES_MATCHING PATTERN "*.service" PATTERN "*.socket" - PATTERN "sdb-prestart.service" EXCLUDE PATTERN "deviced-vibrator.service" EXCLUDE - PATTERN "usb-host*" EXCLUDE) + ) -IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-ffs-test-daemon.service - DESTINATION lib/systemd/system) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-test.socket - DESTINATION lib/systemd/system) -ENDIF() ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/libdeviced) @@ -268,6 +229,3 @@ ADD_SUBDIRECTORY(src/libdeviced) IF(HAPTIC_MODULE STREQUAL on) ADD_SUBDIRECTORY(src/haptic) ENDIF() -IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - ADD_SUBDIRECTORY(src/usb-host-ffs-test-daemon) -ENDIF() diff --git a/packaging/pass.spec b/packaging/pass.spec index a839649..e908c17 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -4,6 +4,7 @@ %bcond_with wayland %bcond_with emulator +%define _unpackaged_files_terminate_build 0 %define daemon_name pass %define libdaemon_name lib%{daemon_name} @@ -16,12 +17,6 @@ %define haptic_module off %define power_module on %define touchscreen_module off -%define usb_module on -%define usbhost_module off -%define TIZEN_FEATURE_USBHOST_TEST off - -#Just For debugging -%define sdb_prestart off # Support two pattern combination vibration %define standard_mix off @@ -29,8 +24,6 @@ %if "%{?profile}" == "mobile" %define haptic_module on %define touchscreen_module on -%define usbhost_module on -%define TIZEN_FEATURE_USBHOST_TEST on %endif %if "%{?profile}" == "wearable" %define haptic_module on @@ -38,8 +31,6 @@ %endif %if "%{?profile}" == "tv" %define block_tmpfs on -%define sdb_prestart off -%define usbhost_module on %endif %if "%{?profile}" == "ivi" %if "%{?_repository}" == "x86_64" @@ -87,10 +78,6 @@ BuildRequires: pkgconfig(storage) BuildRequires: pkgconfig(app2sd) BuildRequires: pkgconfig(capi-system-info) %endif -%if %{?TIZEN_FEATURE_USBHOST_TEST} == on -BuildRequires: pkgconfig(libkmod) -BuildRequires: pkgconfig(libusbg) -%endif Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} @@ -175,11 +162,7 @@ Deviced library for device control (devel) -DHAPTIC_MODULE=%{haptic_module} \ -DSTANDARD_MIX=%{standard_mix} \ -DPOWER_MODULE=%{power_module} \ - -DSDB_PRESTART=%{sdb_prestart} \ -DTOUCHSCREEN_MODULE=%{touchscreen_module} \ - -DUSB_MODULE=%{usb_module} \ - -DUSBHOST_MODULE=%{usbhost_module} \ - -DTIZEN_FEATURE_USBHOST_TEST=%{TIZEN_FEATURE_USBHOST_TEST} \ #eol %build @@ -198,15 +181,6 @@ rm -rf %{buildroot} %install_service multi-user.target.wants deviced-vibrator.service %endif -%if %{?usb_module} == on && %{?sdb_prestart} == on -%install_service basic.target.wants sdb-prestart.service -%endif - -%if %{?usbhost_module} == on -mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d -install -m 644 udev/99-usbhost.rules %{buildroot}%{_prefix}/lib/udev/rules.d/99-usbhost.rules -%endif - %post #memory type vconf key init users_gid=$(getent group %{TZ_SYS_USER_GROUP} | cut -f3 -d':') @@ -259,25 +233,6 @@ systemctl daemon-reload %if %{?display_module} == on %config %{_sysconfdir}/deviced/display.conf %endif -%if %{?usb_module} == on -%config %{_sysconfdir}/deviced/usb-operation.conf -%if %{?sdb_prestart} == on -%{_unitdir}/sdb-prestart.service -%{_unitdir}/basic.target.wants/sdb-prestart.service -%endif -%endif -%if %{?TIZEN_FEATURE_USBHOST_TEST} == on -%{_sysconfdir}/deviced/usb-host-test/test_gadget.gs -%{_bindir}/usb-host-ffs-test-daemon -%{_unitdir}/usb-host-ffs-test-daemon.service -%{_unitdir}/usb-host-test.socket -%{_sysconfdir}/deviced/usb-host-test/descs -%{_sysconfdir}/deviced/usb-host-test/strs -%endif - -%if %{?usbhost_module} == on -%{_prefix}/lib/udev/rules.d/99-usbhost.rules -%endif %files -n %{libdaemon_name} %manifest %{libdaemon_name}.manifest diff --git a/src/usb-host-ffs-test-daemon/CMakeLists.txt b/src/usb-host-ffs-test-daemon/CMakeLists.txt deleted file mode 100755 index 360958f..0000000 --- a/src/usb-host-ffs-test-daemon/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(usb-host-ffs-test-daemon C) - -SET(SRCS - usb-host-ffs-test-daemon.c -) - -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") -INCLUDE(FindPkgConfig) -pkg_check_modules(SYSTEMD REQUIRED libsystemd) -FOREACH(flag ${SYSTEMD_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${SYSTEMD_LDFLAGS}) - -ADD_EXECUTABLE(descs_gen descs_gen.c) -ADD_CUSTOM_COMMAND(OUTPUT descs strs - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/descs_gen - DEPENDS descs_gen) -ADD_CUSTOM_TARGET(descriptors ALL DEPENDS descs strs) - -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/descs DESTINATION /etc/deviced/usb-host-test) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/strs DESTINATION /etc/deviced/usb-host-test) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/src/usb-host-ffs-test-daemon/descs_gen.c b/src/usb-host-ffs-test-daemon/descs_gen.c deleted file mode 100644 index 3e7763a..0000000 --- a/src/usb-host-ffs-test-daemon/descs_gen.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include - -/******************** Descriptors and Strings *******************************/ - -#define MISSING_DESC_HEAD -#ifdef MISSING_DESC_HEAD -enum { - FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3, -}; - -enum functionfs_flags { - FUNCTIONFS_HAS_FS_DESC = 1, - FUNCTIONFS_HAS_HS_DESC = 2, -}; - -struct usb_functionfs_descs_head_v2 { - __le32 magic; - __le32 length; - __le32 flags; - /* - * __le32 fs_count, hs_count, fs_count; must be included manually in - * the structure taking flags into consideration. - */ -} __attribute__((packed)); -#endif - -static const struct { - struct usb_functionfs_descs_head header; - struct { - struct usb_interface_descriptor intf; - struct usb_endpoint_descriptor_no_audio bulk_in; - struct usb_endpoint_descriptor_no_audio bulk_out; - } __attribute__ ((__packed__)) fs_descs, hs_descs; -} __attribute__ ((__packed__)) descriptors = { - .header = { - .magic = htole32(FUNCTIONFS_DESCRIPTORS_MAGIC), - .length = htole32(sizeof(descriptors)), - .fs_count = htole32(3), - .hs_count = htole32(3), - }, - .fs_descs = { - .intf = { - .bLength = sizeof(descriptors.fs_descs.intf), - .bDescriptorType = USB_DT_INTERFACE, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_VENDOR_SPEC, - .iInterface = 1, - }, - .bulk_in = { - .bLength = sizeof(descriptors.fs_descs.bulk_in), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 1 | USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - }, - .bulk_out = { - .bLength = sizeof(descriptors.fs_descs.bulk_out), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 2 | USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - }, - }, - .hs_descs = { - .intf = { - .bLength = sizeof(descriptors.hs_descs.intf), - .bDescriptorType = USB_DT_INTERFACE, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_VENDOR_SPEC, - .iInterface = 1, - }, - .bulk_in = { - .bLength = sizeof(descriptors.hs_descs.bulk_in), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 1 | USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = htole16(512), - }, - .bulk_out = { - .bLength = sizeof(descriptors.hs_descs.bulk_out), - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 2 | USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = htole16(512), - }, - }, -}; - -#define STR_INTERFACE "loop input to output" - -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 = htole32(FUNCTIONFS_STRINGS_MAGIC), - .length = htole32(sizeof(strings)), - .str_count = htole32(1), - .lang_count = htole32(1), - }, - .lang0 = { - htole16(0x0409), /* en-us */ - STR_INTERFACE, - }, -}; - -int main() -{ - int ret; - FILE *sfp, *dfp; - - dfp = fopen("descs", "w"); - if (!dfp) { - perror("Could not open descritptors file"); - return -1; - } - - sfp = fopen("strs", "w"); - if (!sfp) { - perror("Could not open strings file"); - return -1; - } - - ret = fwrite(&descriptors, sizeof(descriptors), 1, dfp); - if (ret < 0) { - perror("Could not write descriptors"); - goto out; - } - - ret = fwrite(&strings, sizeof(strings), 1, sfp); - if (ret < 0) { - perror("Could not write strings"); - goto out; - } - - ret = 0; - -out: - fclose(sfp); - fclose(dfp); - - return ret; -} diff --git a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c deleted file mode 100644 index af17f97..0000000 --- a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define FFS_PATH "/tmp/usb-host-test-ffs" - -#define EP_IN_IDX 1 -#define EP_OUT_IDX 2 - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) - -#define report_error(...) do { \ - fprintf(stderr, __VA_ARGS__); \ - putchar('\n'); \ - } while (0) - -char buf[512]; - -/* Close all ep files */ -void cleanup_ffs(int *ep) -{ - int i; - - for (i = 0; i < 3; ++i) - close(ep[i]); -} - -/* Handle events generated by kernel and provided via ep0 */ -int handle_ep0(int ep0, int *connected) -{ - struct usb_functionfs_event event; - int ret; - - ret = read(ep0, &event, sizeof(event)); - if (!ret) { - report_error("unable to read event from ep0"); - return -EIO; - } - - switch (event.type) { - case FUNCTIONFS_SETUP: - /* stall for all setuo requests */ - if (event.u.setup.bRequestType & USB_DIR_IN) { - if (write(ep0, NULL, 0) < 0) - report_error("write error %d", errno); - } else { - if (read(ep0, NULL, 0) < 0) - report_error("read error %d", errno); - } - break; - - case FUNCTIONFS_ENABLE: - *connected = 1; - break; - - case FUNCTIONFS_DISABLE: - *connected = 0; - break; - - default: - break; - } - - return 0; -} - -/* main chat function */ -void do_chat(int *ep) -{ - int connected = 0; - int ret; - - while (1) { - while (!connected) { - ret = handle_ep0(ep[0], &connected); - if (ret < 0) - return; - } - while (connected) { - ret = read(ep[EP_OUT_IDX], buf, sizeof(buf)); - if (ret < 0) { - if (ret == -ECONNRESET) { - printf("Connection lost."); - break; - } - return; - } - - ret = write(ep[EP_IN_IDX], buf, ret); - if (ret < 0) { - if (ret == -ECONNRESET) { - printf("Connection lost."); - break; - } - return; - } - - } - - } -} - -int main(int argc, char **argv) -{ - int ep[3]; - int i = 0; - - if (sd_listen_fds(0) < 3) { - fprintf(stderr, "Expected endpoints not retrieved\n"); - return -1; - } - - for (i = 0; i < 3; ++i) - ep[i] = SD_LISTEN_FDS_START + i; - - do_chat(ep); - cleanup_ffs(ep); - - return 0; -} diff --git a/src/usb-host-test/test_gadget.gs b/src/usb-host-test/test_gadget.gs deleted file mode 100644 index 86fc895..0000000 --- a/src/usb-host-test/test_gadget.gs +++ /dev/null @@ -1,49 +0,0 @@ -attrs : -{ - bcdUSB = 0x200; - bDeviceClass = 0x0; - bDeviceSubClass = 0x0; - bDeviceProtocol = 0x0; - bMaxPacketSize0 = 0x40; - idVendor = 0x1D6B; - idProduct = 0x104; - bcdDevice = 0x1; -}; -strings = ( - { - lang = 0x409; - manufacturer = "Foo Inc."; - product = "Bar Gadget"; - serialnumber = "0123456789"; - } ); -functions : -{ - ffs_instance1 : - { - instance = "usb-host-test"; - type = "ffs"; - attrs : - { - }; - }; -}; -configs = ( - { - id = 1; - name = "The only one"; - attrs : - { - bmAttributes = 0x80; - bMaxPower = 0x2; - }; - strings = ( - { - lang = 0x409; - configuration = "usb host API test config"; - } ); - functions = ( - { - name = "some_name_here"; - function = "ffs_instance1"; - }); - } ); diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c deleted file mode 100644 index e87e05d..0000000 --- a/src/usb-host-test/usb-host-test.c +++ /dev/null @@ -1,533 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/config-parser.h" -#include "core/device-idler.h" -#include "core/device-notifier.h" -#include "core/devices.h" -#include "core/edbus-handler.h" -#include "core/list.h" -#include "shared/deviced-systemd.h" - -#define FFS_PATH "/run/usb-host-test-ffs" -#define GADGET_SCHEME_PATH "/etc/deviced/usb-host-test/test_gadget.gs" -#define FFS_INSTANCE_NAME "usb-host-test" -#define GADGET_NAME "g1" -#define SYSTEMD_UNIT_NAME "usb-host-test.socket" -#define SYSTEMD_SERVICE_NAME "usb-host-ffs-test-daemon.service" -#define UDC_NAME "dummy_udc.0" -#define CONFIGFS_PATH "/sys/kernel/config/" - -#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" -#define JOB_MANAGER_INTERFACE "org.freedesktop.systemd1.Manager" -#define JOB_REMOVED "JobRemoved" - -static E_DBus_Connection *reply_conn; -static DBusMessage *reply; -static int using_legacy = 0; - -static int load_module(const char *name, const char *options) -{ - struct kmod_ctx *ctx; - struct kmod_module *mod; - const char *config = NULL; - struct kmod_list *l, *list = NULL; - int ret = 0; - int n = 0; - - ctx = kmod_new(NULL, &config); - if (!ctx) - return -1; - - ret = kmod_module_new_from_lookup(ctx, name, &list); - if (ret < 0) { - _E("Module %s lookup error", name); - goto out; - } - - kmod_list_foreach(l, list) { - mod = kmod_module_get_module(l); - if (!mod) { - _E("Module %s load error", name); - ret = -1; - goto out; - } - - ret = kmod_module_get_initstate(mod); - if (ret >= 0) { - _I("module %s already loaded", name); - goto out; /* already loaded */ - } - - ret = kmod_module_insert_module(mod, 0, options); - if (ret < 0) { - _E("Module %s insert error", name); - goto out; - } - - ++n; - } - - if (n == 0) { - _E("Module %s not found", name); - ret = -1; - goto out; - } - - _I("Module %s loaded\n", name); - ret = 0; - -out: - kmod_module_unref_list(list); - kmod_unref(ctx); - return ret; -} - -static int unload_module(const char *name) -{ - struct kmod_ctx *ctx; - struct kmod_module *mod; - const char *config = NULL; - struct kmod_list *l, *list = NULL; - int ret = 0; - int n = 0; - - ctx = kmod_new(NULL, &config); - if (!ctx) - return -1; - - ret = kmod_module_new_from_lookup(ctx, name, &list); - if (ret < 0) { - _E("Module %s lookup error", name); - goto out; - } - - kmod_list_foreach(l, list) { - mod = kmod_module_get_module(l); - if (!mod) { - _E("Module %s unload error", name); - ret = -1; - goto out; - } - - ret = kmod_module_get_initstate(mod); - if (ret < 0) - goto out; /* not loaded */ - - ret = kmod_module_remove_module(mod, 0); - if (ret < 0) { - _E("Module %s remove error", name); - goto out; - } - - ++n; - } - - if (n == 0) { - _I("Module %s not found", name); - ret = -1; - goto out; - } - - _I("Module %s unloaded\n", name); - ret = 0; - -out: - kmod_module_unref_list(list); - kmod_unref(ctx); - return ret; -} - -static int load_gadget() -{ - usbg_state *s; - int ret = 0; - FILE *fp; - - ret = usbg_init(CONFIGFS_PATH, &s); - if (ret < 0) { - _E("could not init libusbg"); - return ret; - } - - fp = fopen(GADGET_SCHEME_PATH, "r"); - if (!fp) { - _E("could not open gadget scheme"); - ret = -1; - goto out; - } - - ret = usbg_import_gadget(s, fp, GADGET_NAME, NULL); - if (ret < 0) { - _E("could not import gadget"); - goto out; - } - -out: - usbg_cleanup(s); - return ret; -} - -int enable_gadget() -{ - int ret; - usbg_gadget *g; - usbg_udc *udc; - usbg_state *s; - - if (using_legacy) - return 0; - - ret = usbg_init(CONFIGFS_PATH, &s); - if (ret < 0) - return ret; - - g = usbg_get_gadget(s, GADGET_NAME); - if (!g) { - _E("could not find gadget"); - ret = -1; - goto out; - } - - udc = usbg_get_udc(s, UDC_NAME); - if (!udc) { - _E("could not find udc"); - ret = -1; - goto out; - } - - ret = usbg_enable_gadget(g, udc); - -out: - usbg_cleanup(s); - return ret; -} - -static void service_started_handler(void *data, DBusMessage *msg) -{ - DBusError err; - uint32_t id; - const char *path, *unit, *result; - int ret; - - dbus_error_init(&err); - if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &id, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_STRING, &unit, - DBUS_TYPE_STRING, &result, - DBUS_TYPE_INVALID)) { - _E("%s", err.message); - return; - } - - if (strcmp(unit, SYSTEMD_UNIT_NAME) == 0) { - ret = enable_gadget(); - if (ret < 0) - _E("Could not enable gadget"); - else - _I("Start"); - - unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED); - - - e_dbus_message_send(reply_conn, reply, NULL, 0, NULL); - } -} - -static void service_stopped_handler(void *data, DBusMessage *msg) -{ - DBusError err; - uint32_t id; - const char *path, *unit, *result; - int ret; - usbg_state *s; - usbg_gadget *g; - - dbus_error_init(&err); - if (!dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &id, - DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_STRING, &unit, - DBUS_TYPE_STRING, &result, - DBUS_TYPE_INVALID)) { - _E("%s", err.message); - return; - } - - if (strcmp(unit, SYSTEMD_SERVICE_NAME) == 0) { - ret = umount(FFS_PATH); - if (ret < 0) { - _E("could not umount functionfs"); - goto out1; - } - - if (!using_legacy) { - ret = usbg_init(CONFIGFS_PATH, &s); - if (ret < 0) { - _E("could not init libusbg"); - goto out1; - } - - g = usbg_get_gadget(s, GADGET_NAME); - if (!g) { - _E("could not find gadget"); - ret = -1; - goto out; - } - - ret = usbg_rm_gadget(g, USBG_RM_RECURSE); - if (ret < 0) { - _E("could not remove gadget"); - goto out; - } - } - - ret = unload_module("dummy_hcd"); - if (ret < 0) { - _E("Error unloading module: %d", ret); - goto out1; - } - - if (using_legacy) { - ret = unload_module("g_ffs"); - if (ret < 0) { - _E("Error unloading module: %d", ret); - goto out1; - } - } else { - ret = unload_module("usb_f_fs"); - if (ret < 0) { - _E("Error unloading module: %d", ret); - goto out; - } - } - - - _I("stop"); - -out: - if (!using_legacy) - usbg_cleanup(s); -out1: - e_dbus_message_send(reply_conn, reply, NULL, 0, NULL); - unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED); - } -} - -int start() -{ - struct stat st; - int ret; - - ret = load_module("dummy_hcd", NULL); - if (ret < 0) { - _E("Error loading module: %d", ret); - return ret; - } - - /* If you need to setup vid, pid or other data use module parameters */ - ret = load_module("g_ffs", - "idVendor=0x1D6B" - " idProduct=0x104" - " bcdDevice=0x0001" - " iManufacturer=\"Foo Inc.\"" - " iProduct=\"Bar Gadget\"" - " iSerialNumber=\"0123456789\"" - " generic_ffs_config_str=\"usb host API test config\"" - " bmAttrs_overwrite=\"0x80\""); - if (ret < 0) { - using_legacy = 0; - _I("Legacy gadget g_ffs not found. Using ConfigFS."); - - ret = load_module("usb_f_fs", NULL); - if (ret < 0) { - _E("Error loading module: %d", ret); - return ret; - } - - ret = load_gadget(); - if (ret < 0) { - _E("Error loading gadget: %d", ret); - goto out; - } - } else { - using_legacy = 1; - } - - /* TODO make it recusrsive? */ - if (stat(FFS_PATH, &st) < 0) { - ret = mkdir(FFS_PATH, S_IRWXU | S_IRWXG | S_IROTH); - if (ret < 0) { - _E("Error creating ffs directory"); - goto out; - } - } - - ret = mount(FFS_INSTANCE_NAME, FFS_PATH, "functionfs", 0, NULL); - if (ret < 0) { - _E("Error mounting ffs"); - goto out; - } - - ret = register_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED, - service_started_handler); - if (ret < 0) { - _E("could not register signal handler"); - goto out; - } - - ret = deviced_systemd_start_unit(SYSTEMD_UNIT_NAME); - if (ret < 0) { - _E("Error starting daemon"); - unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED); - goto out; - } - - return 0; - -out: - -/* It's already a crash, thus we ignore return values here */ - - unload_module("dummy_hcd"); - unload_module("usb_f_fs"); - if (using_legacy) - unload_module("g_ffs"); - - unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED); - - return ret; -} - -static int stop() -{ - int ret = 0; - - ret = register_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED, - service_stopped_handler); - if (ret < 0) { - _E("could not register signal handler"); - return ret; - } - - ret = deviced_systemd_stop_unit(SYSTEMD_UNIT_NAME); - if (ret < 0) { - _E("could not stop socket unit"); - goto out; - } - - ret = deviced_systemd_stop_unit(SYSTEMD_SERVICE_NAME); - if (ret < 0) { - _E("could not stop service unit"); - goto out; - } - - return ret; - -out: - unregister_edbus_signal_handler(SYSTEMD_DBUS_PATH, - JOB_MANAGER_INTERFACE, JOB_REMOVED); - return ret; -} - -static DBusMessage *edbus_start(E_DBus_Object *obj, DBusMessage *msg) -{ - int ret; - - reply_conn = e_dbus_object_conn_get(obj); - reply = dbus_message_new_method_return(msg); - - ret = start(); - if (ret < 0) - return reply; - - return NULL; -} - -static DBusMessage *edbus_stop(E_DBus_Object *obj, DBusMessage *msg) -{ - int ret; - - reply_conn = e_dbus_object_conn_get(obj); - reply = dbus_message_new_method_return(msg); - - ret = stop(); - if (ret < 0) - return dbus_message_new_method_return(msg); - - return NULL; -} - -static int usb_host_test_start(enum device_flags flags) -{ - return start(); -} - -static int usb_host_test_stop(enum device_flags flags) -{ - return stop(); -} - -static const struct edbus_method edbus_methods[] = { - { "start", NULL, NULL, edbus_start }, /* for devicectl */ - { "stop", NULL, NULL, edbus_stop }, /* for devicectl */ -}; - -static void usb_host_test_init(void *data) -{ - int ret; - - ret = register_edbus_interface_and_method(DEVICED_PATH_USB_HOST_TEST, - DEVICED_INTERFACE_USB_HOST_TEST, - edbus_methods, ARRAY_SIZE(edbus_methods)); - - if (ret < 0) { - _E("Failed to register edbus method! %d", ret); - return; - } - - _I("initialized"); -} - -static void usb_host_test_exit(void *data) -{ - _I("exited"); -} - -static const struct device_ops usb_host_test_device_ops = { - .name = "usb-host-test", - .init = usb_host_test_init, - .exit = usb_host_test_exit, - .start = usb_host_test_start, - .stop = usb_host_test_stop, -}; - -DEVICE_OPS_REGISTER(&usb_host_test_device_ops) diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c deleted file mode 100644 index ccd0393..0000000 --- a/src/usb/usb-dbus.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/edbus-handler.h" -#include "shared/dbus.h" -#include "usb.h" - -/* Legacy signals */ -#define SIGNAL_STATE_CHANGED "StateChanged" -#define SIGNAL_MODE_CHANGED "ModeChanged" -#define SIGNAL_CONFIG_ENABLED "ConfigEnabled" -#define CHANGE_USB_MODE "ChangeUsbMode" - -static int get_usb_current_mode(void) -{ - int val, ret; - - ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &val); - if (ret != 0) { - _E("Failed to get current mode (%d)", ret); - return ret; - } - - return val; -} - -static int get_usb_state(void) -{ - int ret, val; - int result = 0; - - ret = vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val); - if (ret != 0) { - _E("Failed to get usb_state (%d)", ret); - return ret; - } - - if (val == VCONFKEY_SYSMAN_USB_DISCONNECTED) - result = val; - else { - result = VCONFKEY_SYSMAN_USB_CONNECTED; - if (val == VCONFKEY_SYSMAN_USB_AVAILABLE) - result |= VCONFKEY_SYSMAN_USB_AVAILABLE; - } - - return result; -} - -/* dbus signals */ -void broadcast_usb_config_enabled(int state) -{ - int ret; - char *param[1]; - char buf[2]; - - snprintf(buf, sizeof(buf), "%d", state); - param[0] = buf; - - _I("USB config enabled (%d)", state); - - ret = broadcast_edbus_signal(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_CONFIG_ENABLED, - "i", param); - if (ret < 0) - _E("Failed to send dbus signal"); -} - -void broadcast_usb_state_changed(void) -{ - int ret; - char *param[1]; - char text[16]; - unsigned int state; - static unsigned int prev_state = UINT_MAX; - - state = get_usb_state(); - if (state == prev_state) - return; - prev_state = state; - - _I("USB state changed (%u)", state); - - snprintf(text, sizeof(text), "%u", state); - param[0] = text; - - ret = broadcast_edbus_signal(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_STATE_CHANGED, - "u", param); - if (ret < 0) - _E("Failed to send dbus signal"); -} - -void broadcast_usb_mode_changed(void) -{ - int ret; - char *param[1]; - char text[16]; - unsigned int mode; - static unsigned int prev_mode = UINT_MAX; - - mode = get_usb_current_mode(); - if (mode == prev_mode) - return; - prev_mode = mode; - - snprintf(text, sizeof(text), "%u", mode); - param[0] = text; - - _I("USB mode changed (%u)", mode); - - ret = broadcast_edbus_signal(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_MODE_CHANGED, - "u", param); - if (ret < 0) - _E("Failed to send dbus signal"); -} - -static void change_usb_client_mode(void *data, DBusMessage *msg) -{ - DBusError err; - int req, debug; - int ret; - unsigned mode; - - if (dbus_message_is_signal(msg, DEVICED_INTERFACE_USB, CHANGE_USB_MODE) == 0) - return; - - dbus_error_init(&err); - - if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &req, DBUS_TYPE_INVALID) == 0) { - _E("FAIL: dbus_message_get_args"); - goto out; - } - - debug = 0; - switch (req) { - case SET_USB_DEFAULT: - case SET_USB_SDB: - case SET_USB_SDB_DIAG: - mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB; - debug = 1; - break; - case SET_USB_RNDIS: - case SET_USB_RNDIS_DIAG: - case SET_USB_RNDIS_SDB: - mode = USB_FUNCTION_RNDIS | USB_FUNCTION_SDB; - debug = 1; - break; - case 11: /* SET_USB_DIAG_RMNET */ - case 12: /* SET_USB_ACM_SDB_DM */ - default: - _E("(%d) is unknown usb mode", req); - goto out; - } - - if (vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debug) != 0) - _E("Failed to set usb debug toggle (%d)", debug); - - ret = usb_change_mode(mode); - if (ret < 0) - _E("Failed to change usb mode (%d)", ret); - -out: - dbus_error_free(&err); -} - -/* dbus methods */ -static DBusMessage *get_usb_client_state(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - unsigned int state; - - state = get_usb_state(); - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &state); - return reply; -} - -static DBusMessage *get_usb_client_mode(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - unsigned int mode; - - mode = get_usb_current_mode(); - - reply = dbus_message_new_method_return(msg); - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &mode); - return reply; -} - -static const struct edbus_method edbus_methods[] = { - { "GetState", NULL, "u", get_usb_client_state }, /* from Tizen 2.3 */ - { "GetMode", NULL, "u", get_usb_client_mode }, /* from Tizen 2.3 */ - /* Add methods here */ -}; - -int usb_dbus_init(void) -{ - int ret; - - ret = register_edbus_method(DEVICED_PATH_USB, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) { - _E("Failed to register dbus method (%d)", ret); - return ret; - } - - ret = register_edbus_signal_handler(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, "ChangeUsbMode", - change_usb_client_mode); - if (ret < 0) { - _E("Failed to registser dbus signal (%d)", ret); - return ret; - } - - return 0; -} diff --git a/src/usb/usb-operation.c b/src/usb/usb-operation.c deleted file mode 100644 index 0484cd3..0000000 --- a/src/usb/usb-operation.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/config-parser.h" -#include "core/launch.h" -#include "shared/deviced-systemd.h" -#include "usb.h" - -#define USB_OPERATION "/etc/deviced/usb-operation.conf" - -#define KEY_START_STR "Start" -#define KEY_STOP_STR "Stop" - -#define BUF_MAX 128 - -typedef enum { - OPERATION_STOP, - OPERATION_START, -} operation_e; - -struct oper_data { - char mode_str[BUF_MAX]; - operation_e type; -}; - -static int load_operation_config(struct parse_result *result, void *user_data) -{ - struct oper_data *data = user_data; - int ret; - operation_e type; - - if (!data || !result) - return -EINVAL; - - if (!strstr(data->mode_str, result->section)) - return 0; - - if (!strncmp(result->name, KEY_START_STR, strlen(KEY_START_STR))) - type = OPERATION_START; - else if (!strncmp(result->name, KEY_STOP_STR, strlen(KEY_STOP_STR))) - type = OPERATION_STOP; - else { - _E("Invalid name (%s)", result->name); - return -EINVAL; - } - - if (type != data->type) - return 0; - - if (strstr(result->name, "Service")) { - if (type == OPERATION_START) - ret = deviced_systemd_start_unit(result->value); - if (type == OPERATION_STOP) - ret = deviced_systemd_stop_unit(result->value); - } else - ret = launch_app_cmd(result->value); - - _I("Execute(%s %s: %d)", result->name, result->value, ret); - - return 0; -} - -static int usb_execute_operation(unsigned int mode, operation_e type) -{ - int ret; - struct oper_data data; - - if (mode == USB_FUNCTION_NONE) - return -EINVAL; - - usb_state_get_mode_str(mode, data.mode_str, sizeof(data.mode_str)); - - data.type = type; - - ret = config_parse(USB_OPERATION, - load_operation_config, &data); - if (ret < 0) - _E("Failed to load usb operation (%d)", ret); - - return ret; -} - -int usb_operation_start(unsigned int mode) -{ - return usb_execute_operation(mode, OPERATION_START); -} - -int usb_operation_stop(unsigned int mode) -{ - return usb_execute_operation(mode, OPERATION_STOP); -} diff --git a/src/usb/usb-operation.conf b/src/usb/usb-operation.conf deleted file mode 100644 index 32db01a..0000000 --- a/src/usb/usb-operation.conf +++ /dev/null @@ -1,17 +0,0 @@ -[sdb] -StartService=sdbd.service -StopService=sdbd.service - - -[mtp] -StartService=mtp-responder.service -StopService=mtp-responder.service - -[rndis] -Start=/sbin/ifconfig usb0 192.168.129.3 up -Start=/sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0 -StartService=sshd.service -StartService=sdbd.service -StopService=sshd.service -Stop=/sbin/ifconfig usb0 down -StopService=sdbd.service diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c deleted file mode 100644 index 28b2af0..0000000 --- a/src/usb/usb-state.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/list.h" -#include "core/common.h" -#include "core/device-notifier.h" -#include "display/poll.h" -#include "extcon/extcon.h" -#include "apps/apps.h" -#include "usb.h" -#include "usb-tethering.h" - -static usb_connection_state_e usb_connection = USB_DISCONNECTED; -static unsigned int usb_mode = USB_FUNCTION_NONE; -static unsigned int usb_selected_mode = USB_FUNCTION_SDB; /* for debugging */ - -static void usb_state_send_system_event(int status) -{ - bundle *b; - const char *str; - - switch (status) { - case VCONFKEY_SYSMAN_USB_DISCONNECTED: - str = EVT_VAL_USB_DISCONNECTED; - break; - case VCONFKEY_SYSMAN_USB_CONNECTED: - str = EVT_VAL_USB_CONNECTED; - break; - case VCONFKEY_SYSMAN_USB_AVAILABLE: - str = EVT_VAL_USB_AVAILABLE; - break; - default: - return; - } - - _I("system_event (%s)", str); - - b = bundle_create(); - bundle_add_str(b, EVT_KEY_USB_STATUS, str); - eventsystem_send_system_event(SYS_EVENT_USB_STATUS, b); - bundle_free(b); -} - -static void usb_state_set_connection(usb_connection_state_e conn) -{ - usb_connection = conn; -} - -usb_connection_state_e usb_state_get_connection(void) -{ - return usb_connection; -} - -void usb_state_retrieve_selected_mode(void) -{ - int ret, mode; - ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &mode); - if (ret != 0) { - _E("Failed to retrieve selected mode"); - return; - } - -#ifdef ENGINEER_MODE - if (!(mode & USB_FUNCTION_SDB)) { - mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB; - usb_state_set_selected_mode(mode); - } -#endif - - usb_selected_mode = (unsigned int)mode; -} - -void usb_state_set_selected_mode(unsigned int mode) -{ - usb_selected_mode = mode; - vconf_set_int(VCONFKEY_USB_SEL_MODE, mode); -} - -unsigned int usb_state_get_current_mode(void) -{ - return usb_mode; -} - -unsigned int usb_state_get_selected_mode(void) -{ - return usb_selected_mode; -} - -char *usb_state_get_mode_str(unsigned int mode, char *str, size_t len) -{ - int i; - int ret; - - if (mode == USB_FUNCTION_NONE) { - snprintf(str, len, "%s", ""); - } else { - for (i = 0; i < ARRAY_SIZE(_available_funcs); ++i) { - if (mode & _available_funcs[i]->id) { - ret = snprintf(str, len, "%s,", - _available_funcs[i]->name); - if (ret >= len) - return str; - str += ret; - len -= ret; - } - } - } - - /* eliminate trailing comma */ - *(str - 1) = '\0'; - return str; -} - -void usb_state_update_state(usb_connection_state_e state, unsigned int mode) -{ - static int old_mode = -1; /* VCONFKEY_USB_CUR_MODE */ - static int old_status = -1; /* VCONFKEY_SYSMAN_USB_STATUS */ - static int noti_id = -1; - int status; - - if (state == USB_DISCONNECTED && mode != USB_FUNCTION_NONE) - mode = USB_FUNCTION_NONE; - - if (mode == USB_FUNCTION_NONE) { - if (noti_id >= 0) { - remove_notification("MediaDeviceNotiOff", noti_id); - noti_id = -1; - } - } else if (mode | USB_FUNCTION_MTP) { - if (noti_id < 0) - noti_id = add_notification("MediaDeviceNotiOn"); - if (noti_id < 0) - _E("Failed to show notification for usb connection"); - } - - usb_state_set_connection(state); - if (state == USB_CONNECTED) { - if (mode == USB_FUNCTION_NONE) - status = VCONFKEY_SYSMAN_USB_CONNECTED; - else - status = VCONFKEY_SYSMAN_USB_AVAILABLE; - } else - status = VCONFKEY_SYSMAN_USB_DISCONNECTED; - - if (old_status != status) { - usb_state_send_system_event(status); - vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, status); - old_status = status; - } - - if (old_mode != mode) { - vconf_set_int(VCONFKEY_USB_CUR_MODE, mode); - usb_mode = mode; - old_mode = mode; - } -} diff --git a/src/usb/usb-tethering.c b/src/usb/usb-tethering.c deleted file mode 100644 index e675b24..0000000 --- a/src/usb/usb-tethering.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include - -#include "core/log.h" -#include "core/common.h" -#include "core/config-parser.h" -#include "core/launch.h" -#include "core/device-notifier.h" -#include "usb.h" - -static bool tethering_state; - -bool usb_tethering_state(void) -{ - return tethering_state; -} - -static void usb_tethering_changed(keynode_t *key, void *data) -{ - int mode; - bool curr; - - if (!key) - return; - - mode = vconf_keynode_get_int(key); - curr = mode & VCONFKEY_MOBILE_HOTSPOT_MODE_USB; - - if (curr == tethering_state) - return; - - tethering_state = curr; - - device_notify(DEVICE_NOTIFIER_USB_TETHERING_MODE, (void *)curr); -} - -static int usb_tethering_mode_changed(void *data) -{ - bool on; - unsigned mode; - int ret; - - on = (bool)data; - - /* - * TODO. - * Preserve gadget mode when tethering is being turned on - * and restore it later when tethering is being turned off/ - */ - if (on) - mode = USB_FUNCTION_RNDIS | USB_FUNCTION_SDB; - else - mode = USB_FUNCTION_MTP | USB_FUNCTION_ACM | USB_FUNCTION_SDB; - - ret = usb_change_mode(mode); - if (ret < 0) - _E("Failed to change usb mode to (%s)", mode); - - return ret; -} - -void add_usb_tethering_handler(void) -{ - if (vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, - usb_tethering_changed, NULL) != 0) - _E("Failed to add usb tethering handler"); - - register_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE, - usb_tethering_mode_changed); -} - -void remove_usb_tethering_handler(void) -{ - vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, - usb_tethering_changed); - - unregister_notifier(DEVICE_NOTIFIER_USB_TETHERING_MODE, - usb_tethering_mode_changed); -} diff --git a/src/usb/usb-tethering.h b/src/usb/usb-tethering.h deleted file mode 100644 index 998be13..0000000 --- a/src/usb/usb-tethering.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __USB_TETHERING_H__ -#define __USB_TETHERING_H__ - -#include - -bool usb_tethering_state(void); - -void add_usb_tethering_handler(void); -void remove_usb_tethering_handler(void); - -#endif /* __USB_TETHERING_H__ */ diff --git a/src/usb/usb.c b/src/usb/usb.c deleted file mode 100644 index 18f1949..0000000 --- a/src/usb/usb.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -#include "core/log.h" -#include "core/list.h" -#include "core/common.h" -#include "core/device-notifier.h" -#include "display/poll.h" -#include "extcon/extcon.h" -#include "apps/apps.h" -#include "usb.h" -#include "usb-tethering.h" - -static struct usb_gadget_translator *gadget_translator; -static struct usb_client *usb_client; -static unsigned current_mode; - -struct extcon_ops extcon_usb_ops; - -static int usb_probe(void) -{ - struct hw_info *info; - struct hw_common *common; - int ret; - - /* We need both HALs up and running for operating in USB client mode */ - - if (!gadget_translator) { - ret = hw_get_info(USB_GADGET_DEVICE_ID, - (const struct hw_info **)&info); - if (ret) - goto no_gadget_hal; - - if (!info->open) { - _E("Failed to open gadget translator; open(NULL)"); - /* TODO. Shouldn't we free somehow info structure? */ - return -ENODEV; - } - - ret = info->open(info, NULL, &common); - if (ret < 0) { - _E("Failed to open usb gadget translator (%d)", ret); - return ret; - } - - gadget_translator = container_of(common, - struct usb_gadget_translator, - common); - if (!gadget_translator->id_to_gadget || - !gadget_translator->cleanup_gadget) { - _E("Invalid gadget translator HAL"); - goto invalid_translator_hal; - } - } - - if (!usb_client) { - ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID, - (const struct hw_info **)&info); - if (ret) - goto no_client_hal; - - if (!info->open) { - _E("Failed to open usb client hw; open(NULL)"); - /* TODO. Shouldn't we free somehow info structure? */ - return -ENODEV; - } - - ret = info->open(info, NULL, &common); - if (ret < 0) { - _E("Failed to open usb client hw (%d)", ret); - return ret; - } - - usb_client = container_of(common, struct usb_client, common); - - if (!usb_client->reconfigure_gadget || !usb_client->enable || - !usb_client->disable) - goto invalid_config_hal; - } - - return 0; - -invalid_config_hal: - if (usb_client->common.info->close) - usb_client->common.info->close(&usb_client->common); - -no_client_hal: -invalid_translator_hal: - if (gadget_translator->common.info) - gadget_translator->common.info->close(&gadget_translator->common); - gadget_translator = NULL; -no_gadget_hal: - /* TODO. Maybe some default action here? */ - return -ENOENT; -} - -static void usb_release() -{ - if (usb_client) - if (usb_client->common.info->close) - usb_client->common.info->close(&usb_client->common); - - if (gadget_translator) - if (gadget_translator->common.info->close) - gadget_translator->common.info->close( - &gadget_translator->common); -} - -static int usb_config_init(void) -{ - int ret; - struct usb_gadget_id gadget_id; - struct usb_gadget *gadget; - - if (!gadget_translator || !usb_client) - goto no_hal; - - memset(&gadget_id, 0, sizeof(gadget_id)); - - gadget_id.function_mask = usb_state_get_selected_mode(); - ret = gadget_translator->id_to_gadget(&gadget_id, &gadget); - if (ret) { - _E("Unable to translate id into gadget (%d)", ret); - return ret; - } - - usb_client->disable(usb_client); - ret = usb_client->reconfigure_gadget(usb_client, gadget); - gadget_translator->cleanup_gadget(gadget); - if (ret) - _E("Unable to configure gadget (%d)", ret); - - return ret; -no_hal: - /* TODO. Maybe some default action here? */ - return -ENODEV; -} - -static void usb_config_deinit(void) -{ - if (!usb_client) - goto no_hal; - - usb_client->disable(usb_client); - - return; -no_hal: - /* TODO. Maybe some default action here? */ - return; -} - -static int usb_config_enable(void) -{ - if (!usb_client) - goto no_hal; - - return usb_client->enable(usb_client); - -no_hal: - /* TODO. Maybe some default action here? */ - return -ENODEV; -} - -static int usb_config_disable(void) -{ - if (!usb_client) - goto no_hal; - - usb_client->disable(usb_client); - - return 0; -no_hal: - /* TODO. Maybe some default action here? */ - return -ENODEV; -} - -int usb_change_mode(unsigned mode) -{ - struct usb_gadget_id gadget_id; - struct usb_gadget *gadget; - int ret; - - if (!gadget_translator || !usb_client) - goto no_hal; - - memset(&gadget_id, 0, sizeof(gadget_id)); - gadget_id.function_mask = mode; - - ret = gadget_translator->id_to_gadget(&gadget_id, &gadget); - if (ret) { - _E("Unable to translate id into gadget (%d)", ret); - return ret; - } - - usb_client->disable(usb_client); - ret = usb_client->reconfigure_gadget(usb_client, gadget); - gadget_translator->cleanup_gadget(gadget); - if (ret) { - _E("Unable to configure gadget (%d)", ret); - goto out; - } - - current_mode = mode; -out: - return ret; -no_hal: - /* TODO. Maybe some default action here? */ - return -ENODEV; -} - -static int usb_state_changed(int status) -{ - static int old = -1; /* to update at the first time */ - unsigned mode; - int ret; - - _I("USB state is changed from (%d) to (%d)", old, status); - - if (old == status) - return 0; - - switch (status) { - case USB_CONNECTED: - _I("USB cable is connected"); - usb_state_update_state(USB_CONNECTED, USB_FUNCTION_NONE); - mode = usb_state_get_selected_mode(); - if (mode != current_mode) - usb_change_mode(mode); - - ret = usb_config_enable(); - if (ret < 0) { - _E("Failed to enable usb config (%d)", ret); - break; - } - usb_operation_start(mode); - usb_state_update_state(USB_CONNECTED, mode); - pm_lock_internal(INTERNAL_LOCK_USB, - LCD_OFF, STAY_CUR_STATE, 0); - break; - case USB_DISCONNECTED: - _I("USB cable is disconnected"); - usb_operation_stop(usb_state_get_current_mode()); - usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE); - - ret = usb_config_disable(); - if (ret != 0) - _E("Failed to disable usb config (%d)", ret); - pm_unlock_internal(INTERNAL_LOCK_USB, - LCD_OFF, STAY_CUR_STATE); - break; - default: - _E("Invalid USB state(%d)", status); - return -EINVAL; - } - if (ret < 0) - _E("Failed to operate usb connection(%d)", ret); - else - old = status; - - return ret; -} - -static void usb_init(void *data) -{ - int ret; - - ret = usb_probe(); - if (ret < 0) { - _E("USB client cannot be used (%d)", ret); - return; - } - - usb_state_retrieve_selected_mode(); - - ret = usb_config_init(); - if (ret < 0) - _E("Failed to initialize usb configuation"); - - ret = usb_dbus_init(); - if (ret < 0) - _E("Failed to init dbus (%d)", ret); - - add_usb_tethering_handler(); - - ret = usb_state_changed(extcon_usb_ops.status); - if (ret < 0) - _E("Failed to update usb status(%d)", ret); -} - -static void usb_exit(void *data) -{ - remove_usb_tethering_handler(); - usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE); - usb_config_deinit(); - usb_release(); -} - -struct extcon_ops extcon_usb_ops = { - .name = EXTCON_CABLE_USB, - .init = usb_init, - .exit = usb_exit, - .update = usb_state_changed, -}; - -EXTCON_OPS_REGISTER(extcon_usb_ops) diff --git a/src/usb/usb.h b/src/usb/usb.h deleted file mode 100644 index fe55917..0000000 --- a/src/usb/usb.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __DEVICED_USB_H__ -#define __DEVICED_USB_H__ - -#include -#include - -#define USB_CONFIG_OPS_REGISTER(dev) \ -static void __CONSTRUCTOR__ usb_config_init(void) \ -{ \ - add_usb_config(dev); \ -} \ -static void __DESTRUCTOR__ usb_config_exit(void) \ -{ \ - remove_usb_config(dev); \ -} - -struct usb_config_ops { - bool (*is_valid)(void); - const struct usb_config_plugin_ops *(*load)(void); - void (*release)(void); -}; - -/* TODO - * move it to proper location */ -struct usb_config_plugin_ops { - int (*init)(char *name); - void (*deinit)(char *name); - int (*enable)(char *name); - int (*disable)(char *name); - int (*change)(char *name); -}; - -/* Update usb state (usb-state.c) */ -typedef enum { - USB_DISCONNECTED, - USB_CONNECTED, -} usb_connection_state_e; - -void add_usb_config(const struct usb_config_ops *ops); -void remove_usb_config(const struct usb_config_ops *ops); - -int usb_change_mode(unsigned int mode); - -void usb_state_update_state(usb_connection_state_e state, unsigned int mode); -void usb_state_retrieve_selected_mode(void); -char *usb_state_get_mode_str(unsigned int mode, char *str, size_t len); -unsigned int usb_state_get_selected_mode(void); -void usb_state_set_selected_mode(unsigned int mode); -unsigned int usb_state_get_current_mode(void); - -int usb_operation_start(unsigned int mode); -int usb_operation_stop(unsigned int mode); - -/* dbus methods/signals (usb-dbus.c) */ -enum { - DISABLED, - ENABLED, -}; - -int usb_dbus_init(void); - -void broadcast_usb_config_enabled(int state); -void broadcast_usb_state_changed(void); -void broadcast_usb_mode_changed(void); - -#endif /* __USB_CLIENT_H__ */ diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c deleted file mode 100644 index 2679cac..0000000 --- a/src/usbhost/usb-host.c +++ /dev/null @@ -1,1321 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/devices.h" -#include "core/edbus-handler.h" -#include "core/device-notifier.h" -#include "core/udev.h" -#include "core/list.h" -#include "core/device-idler.h" -#include "apps/apps.h" - -#define USB_INTERFACE_CLASS "bInterfaceClass" -#define USB_INTERFACE_SUBCLASS "bInterfaceSubClass" -#define USB_INTERFACE_PROTOCOL "bInterfaceProtocol" -#define USB_VENDOR_ID "idVendor" -#define USB_PRODUCT_ID "idProduct" -#define USB_MANUFACTURER "manufacturer" -#define USB_PRODUCT "product" -#define USB_SERIAL "serial" - -#define USB_HOST_RESULT_SIGNAL "USBHostResult" - -#define SIGNAL_USB_HOST_CHANGED "ChangedDevice" -#define METHOD_GET_CONNECTION_CREDENTIALS "GetConnectionCredentials" - -#define ROOTPATH tzplatform_getenv(TZ_SYS_VAR) -#define POLICY_FILENAME "usbhost-policy" - -char *POLICY_FILEPATH; - -/** - * Below usb host class is defined by www.usb.org. - * Please refer to below site. - * http://www.usb.org/developers/defined_class - * You can find the detail class codes in linux/usb/ch9.h. - * Deviced uses kernel defines. - */ -#include -#define USB_CLASS_ALL 0xffffffff -#define USB_DEVICE_MAJOR 189 - -/** - * HID Standard protocol information. - * Please refer to below site. - * http://www.usb.org/developers/hidpage/HID1_11.pdf - * Below protocol only has meaning - * if the subclass is a boot interface subclass, - * otherwise it is 0. - */ -enum usbhost_hid_protocol { - USB_HOST_HID_KEYBOARD = 1, - USB_HOST_HID_MOUSE = 2, -}; - -enum usbhost_state { - USB_HOST_REMOVED, - USB_HOST_ADDED, -}; - -struct usbhost_device { - char devpath[PATH_MAX]; /* unique info. */ - int baseclass; - int subclass; - int protocol; - int vendorid; - int productid; - char *manufacturer; - char *product; - char *serial; -}; - -static dd_list *usbhost_list; - -enum policy_value { - POLICY_NONE, - POLICY_ALLOW_ALWAYS, - POLICY_ALLOW_NOW, - POLICY_DENY_ALWAYS, - POLICY_DENY_NOW, -}; - -#define UID_KEY "UnixUserID" -#define PID_KEY "ProcessID" -#define SEC_LABEL_KEY "LinuxSecurityLabel" -#define ENTRY_LINE_SIZE 256 - -struct user_credentials { - uint32_t uid; - uint32_t pid; - char *sec_label; -}; - -struct device_desc{ - uint16_t bcdUSB; - uint8_t bDeviceClass; - uint8_t bDeviceSubClass; - uint8_t bDeviceProtocol; - uint16_t idVendor; - uint16_t idProduct; - uint16_t bcdDevice; -}; - -struct policy_entry { - struct user_credentials creds; - union { - struct usb_device_descriptor device; - /* for temporary policy */ - char devpath[PATH_MAX]; - }; - - enum policy_value value; -}; - -static inline int is_policy_temporary(struct policy_entry *entry) { - return entry->value == POLICY_ALLOW_NOW || - entry->value == POLICY_DENY_NOW; -} - -dd_list *access_list; - -struct usbhost_open_request { - DBusMessage *msg; - E_DBus_Connection *reply_conn; - char *path; - struct user_credentials cred; - struct usb_device_descriptor desc; - char devpath[PATH_MAX]; -} *current_request = NULL; - -static void print_usbhost(struct usbhost_device *usbhost) -{ - if (!usbhost) - return; - - _I("devpath : %s", usbhost->devpath); - _I("interface baseclass : %xh", usbhost->baseclass); - _I("interface subclass : %xh", usbhost->subclass); - _I("interface protocol : %xh", usbhost->protocol); - _I("vendor id : %xh", usbhost->vendorid); - _I("product id : %xh", usbhost->productid); - _I("manufacturer : %s", usbhost->manufacturer); - _I("product : %s", usbhost->product); - _I("serial : %s", usbhost->serial); -} - -static void broadcast_usbhost_signal(enum usbhost_state state, - struct usbhost_device *usbhost) -{ - char *arr[10]; - char str_state[32]; - char str_baseclass[32]; - char str_subclass[32]; - char str_protocol[32]; - char str_vendorid[32]; - char str_productid[32]; - - if (!usbhost) - return; - - snprintf(str_state, sizeof(str_state), "%d", state); - arr[0] = str_state; - /* devpath is always valid */ - arr[1] = usbhost->devpath; - snprintf(str_baseclass, sizeof(str_baseclass), - "%d", usbhost->baseclass); - arr[2] = str_baseclass; - snprintf(str_subclass, sizeof(str_subclass), - "%d", usbhost->subclass); - arr[3] = str_subclass; - snprintf(str_protocol, sizeof(str_protocol), - "%d", usbhost->protocol); - arr[4] = str_protocol; - snprintf(str_vendorid, sizeof(str_vendorid), - "%d", usbhost->vendorid); - arr[5] = str_vendorid; - snprintf(str_productid, sizeof(str_productid), - "%d", usbhost->productid); - arr[6] = str_productid; - arr[7] = (!usbhost->manufacturer ? "" : usbhost->manufacturer); - arr[8] = (!usbhost->product ? "" : usbhost->product); - arr[9] = (!usbhost->serial ? "" : usbhost->serial); - - broadcast_edbus_signal(DEVICED_PATH_USBHOST, - DEVICED_INTERFACE_USBHOST, - SIGNAL_USB_HOST_CHANGED, - "isiiiiisss", arr); -} - -static int add_usbhost_list(struct udev_device *dev, const char *devpath) -{ - struct usbhost_device *usbhost; - const char *str; - struct udev_device *parent; - - /* allocate new usbhost device */ - usbhost = calloc(1, sizeof(struct usbhost_device)); - if (!usbhost) { - _E("fail to allocate usbhost memory : %d", errno); - return -errno; - } - - /* save the devnode */ - snprintf(usbhost->devpath, sizeof(usbhost->devpath), - "%s", devpath); - - /* get usb interface informations */ - str = udev_device_get_sysattr_value(dev, USB_INTERFACE_CLASS); - if (str) - usbhost->baseclass = (int)strtol(str, NULL, 16); - str = udev_device_get_sysattr_value(dev, USB_INTERFACE_SUBCLASS); - if (str) - usbhost->subclass = (int)strtol(str, NULL, 16); - str = udev_device_get_sysattr_value(dev, USB_INTERFACE_PROTOCOL); - if (str) - usbhost->protocol = (int)strtol(str, NULL, 16); - - /* parent has a lot of information about usb_interface */ - parent = udev_device_get_parent(dev); - if (!parent) { - _E("fail to get parent"); - free(usbhost); - return -EPERM; - } - - /* get usb device informations */ - str = udev_device_get_sysattr_value(parent, USB_VENDOR_ID); - if (str) - usbhost->vendorid = (int)strtol(str, NULL, 16); - str = udev_device_get_sysattr_value(parent, USB_PRODUCT_ID); - if (str) - usbhost->productid = (int)strtol(str, NULL, 16); - str = udev_device_get_sysattr_value(parent, USB_MANUFACTURER); - if (str) - usbhost->manufacturer = strdup(str); - str = udev_device_get_sysattr_value(parent, USB_PRODUCT); - if (str) - usbhost->product = strdup(str); - str = udev_device_get_sysattr_value(parent, USB_SERIAL); - if (str) - usbhost->serial = strdup(str); - - DD_LIST_APPEND(usbhost_list, usbhost); - - broadcast_usbhost_signal(USB_HOST_ADDED, usbhost); - - /* for debugging */ - _I("USB HOST Added"); - print_usbhost(usbhost); - - return 0; -} - -static int remove_usbhost_list(const char *devpath) -{ - struct usbhost_device *usbhost; - dd_list *n, *next; - - /* find the matched item */ - DD_LIST_FOREACH_SAFE(usbhost_list, n, next, usbhost) { - if (!strncmp(usbhost->devpath, - devpath, sizeof(usbhost->devpath))) - break; - } - - if (!usbhost) { - _E("fail to find the matched usbhost device"); - return -ENODEV; - } - - broadcast_usbhost_signal(USB_HOST_REMOVED, usbhost); - - /* for debugging */ - _I("USB HOST Removed"); - _I("devpath : %s", usbhost->devpath); - - DD_LIST_REMOVE(usbhost_list, usbhost); - free(usbhost->manufacturer); - free(usbhost->product); - free(usbhost->serial); - free(usbhost); - - return 0; -} - -static void remove_all_usbhost_list(void) -{ - struct usbhost_device *usbhost; - dd_list *n, *next; - - DD_LIST_FOREACH_SAFE(usbhost_list, n, next, usbhost) { - - /* for debugging */ - _I("USB HOST Removed"); - _I("devpath : %s", usbhost->devpath); - - DD_LIST_REMOVE(usbhost_list, usbhost); - free(usbhost->manufacturer); - free(usbhost->product); - free(usbhost->serial); - free(usbhost); - } -} - -static void uevent_usbhost_handler(struct udev_device *dev) -{ - const char *subsystem; - const char *devtype; - const char *devpath; - const char *action; - struct policy_entry *entry; - dd_list *n, *next; - - /** - * Usb host device must have at least one interface. - * An interface is matched with a specific usb class. - */ - subsystem = udev_device_get_subsystem(dev); - devtype = udev_device_get_devtype(dev); - if (!subsystem || !devtype) { - _E("fail to get subsystem or devtype"); - return; - } - - /* devpath is an unique information among usb host devices */ - devpath = udev_device_get_devpath(dev); - if (!devpath) { - _E("fail to get devpath from udev_device"); - return; - } - - action = udev_device_get_action(dev); - _I("subsystem : %s, devtype : %s, action : %s", subsystem, devtype, action); - /* Policy is valid for entire device, thus we check this devtype here */ - if (strncmp(subsystem, USB_SUBSYSTEM, sizeof(USB_SUBSYSTEM)) == 0 && - strncmp(devtype, USB_DEVICE_DEVTYPE, sizeof(USB_DEVICE_DEVTYPE)) == 0 && - strncmp(action, UDEV_REMOVE, sizeof(UDEV_REMOVE)) == 0) { - DD_LIST_FOREACH_SAFE(access_list, n, next, entry) { - if (is_policy_temporary(entry) && - strcmp(devpath, entry->devpath) == 0) { - _I("removed temporary policy for %s", devpath); - DD_LIST_REMOVE(access_list, entry); - free(entry->creds.sec_label); - free(entry); - } - } - } - - /** - * if devtype is not matched with usb subsystem - * and usb_interface devtype, skip. - */ - if (strncmp(subsystem, USB_SUBSYSTEM, sizeof(USB_SUBSYSTEM)) || - strncmp(devtype, USB_INTERFACE_DEVTYPE, sizeof(USB_INTERFACE_DEVTYPE))) - return; - - if (!strncmp(action, UDEV_ADD, sizeof(UDEV_ADD))) - add_usbhost_list(dev, devpath); - else if (!strncmp(action, UDEV_REMOVE, sizeof(UDEV_REMOVE))) - remove_usbhost_list(devpath); -} - -static int usbhost_init_from_udev_enumerate(void) -{ - struct udev *udev; - struct udev_enumerate *enumerate; - struct udev_list_entry *list_entry; - struct udev_device *dev; - const char *syspath; - const char *devpath; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); - return -EPERM; - } - - /* create a list of the devices in the 'usb' subsystem */ - enumerate = udev_enumerate_new(udev); - if (!enumerate) { - _E("fail to create an enumeration context"); - return -EPERM; - } - - udev_enumerate_add_match_subsystem(enumerate, USB_SUBSYSTEM); - udev_enumerate_add_match_property(enumerate, - UDEV_DEVTYPE, USB_INTERFACE_DEVTYPE); - udev_enumerate_scan_devices(enumerate); - - udev_list_entry_foreach(list_entry, - udev_enumerate_get_list_entry(enumerate)) { - syspath = udev_list_entry_get_name(list_entry); - if (!syspath) - continue; - - dev = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate), - syspath); - if (!dev) - continue; - - /* devpath is an unique information among usb host devices */ - devpath = udev_device_get_devpath(dev); - if (!devpath) { - _E("fail to get devpath from %s device", syspath); - continue; - } - - /* add usbhost list */ - add_usbhost_list(dev, devpath); - - udev_device_unref(dev); - } - - udev_enumerate_unref(enumerate); - udev_unref(udev); - return 0; -} - -static DBusMessage *print_device_list(E_DBus_Object *obj, DBusMessage *msg) -{ - dd_list *elem; - struct usbhost_device *usbhost; - int cnt = 0; - - DD_LIST_FOREACH(usbhost_list, elem, usbhost) { - _I("== [%2d USB HOST DEVICE] ===============", cnt++); - print_usbhost(usbhost); - } - - return dbus_message_new_method_return(msg); -} - -static DBusMessage *get_device_list(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessageIter arr; - DBusMessageIter s; - DBusMessage *reply; - dd_list *elem; - struct usbhost_device *usbhost; - const char *str; - int baseclass; - - reply = dbus_message_new_method_return(msg); - - if (!dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &baseclass, DBUS_TYPE_INVALID)) { - _E("there is no message"); - goto out; - } - - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_open_container(&iter, - DBUS_TYPE_ARRAY, "(siiiiisss)", &arr); - - DD_LIST_FOREACH(usbhost_list, elem, usbhost) { - if (baseclass != USB_CLASS_ALL && usbhost->baseclass != baseclass) - continue; - dbus_message_iter_open_container(&arr, DBUS_TYPE_STRUCT, NULL, &s); - str = usbhost->devpath; - dbus_message_iter_append_basic(&s, DBUS_TYPE_STRING, &str); - dbus_message_iter_append_basic(&s, - DBUS_TYPE_INT32, &usbhost->baseclass); - dbus_message_iter_append_basic(&s, - DBUS_TYPE_INT32, &usbhost->subclass); - dbus_message_iter_append_basic(&s, - DBUS_TYPE_INT32, &usbhost->protocol); - dbus_message_iter_append_basic(&s, - DBUS_TYPE_INT32, &usbhost->vendorid); - dbus_message_iter_append_basic(&s, - DBUS_TYPE_INT32, &usbhost->productid); - str = (!usbhost->manufacturer ? "" : usbhost->manufacturer); - dbus_message_iter_append_basic(&s, DBUS_TYPE_STRING, &str); - str = (!usbhost->product ? "" : usbhost->product); - dbus_message_iter_append_basic(&s, DBUS_TYPE_STRING, &str); - str = (!usbhost->serial ? "" : usbhost->serial); - dbus_message_iter_append_basic(&s, DBUS_TYPE_STRING, &str); - dbus_message_iter_close_container(&arr, &s); - } - - dbus_message_iter_close_container(&iter, &arr); - -out: - return reply; -} - -static DBusMessage *get_device_list_count(E_DBus_Object *obj, DBusMessage *msg) -{ - dd_list *elem; - struct usbhost_device *usbhost; - int baseclass; - int ret = 0; - - if (!dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &baseclass, DBUS_TYPE_INVALID)) { - _E("there is no message"); - ret = -EINVAL; - goto out; - } - - DD_LIST_FOREACH(usbhost_list, elem, usbhost) { - if (baseclass != USB_CLASS_ALL && usbhost->baseclass != baseclass) - continue; - ret++; - } - -out: - return make_reply_message(msg, ret); -} - -static struct uevent_handler uh = { - .subsystem = USB_SUBSYSTEM, - .uevent_func = uevent_usbhost_handler, -}; - -static const char *policy_value_str(enum policy_value value) { - switch (value) { - case POLICY_ALLOW_ALWAYS: - return "ALLOW"; - case POLICY_ALLOW_NOW: - return "ALLOW_NOW"; - case POLICY_DENY_ALWAYS: - return "DENY"; - case POLICY_DENY_NOW: - return "DENY_NOW"; - default: - return "UNKNOWN"; - } -} - -static int get_policy_value_from_str(const char *str) { - if (strncmp("ALLOW", str, 5) == 0) - return POLICY_ALLOW_ALWAYS; - if (strncmp("ALLOW_NOW", str, 5) == 0) - return POLICY_ALLOW_NOW; - if (strncmp("DENY", str, 4) == 0) - return POLICY_DENY_ALWAYS; - if (strncmp("DENY_NOW", str, 4) == 0) - return POLICY_DENY_NOW; - return -1; -} - -static inline int marshal_policy_entry(char *buf, int len, struct policy_entry *entry) { - if (is_policy_temporary(entry)) - return snprintf(buf, len, "%d %s %s %s\n", - entry->creds.uid, - entry->creds.sec_label, - entry->devpath, - policy_value_str(entry->value)); - return snprintf(buf, len, "%d %s %04x %02x %02x %02x %04x %04x %04x %s\n", - entry->creds.uid, - entry->creds.sec_label, - entry->device.bcdUSB, - entry->device.bDeviceClass, - entry->device.bDeviceSubClass, - entry->device.bDeviceProtocol, - entry->device.idVendor, - entry->device.idProduct, - entry->device.bcdDevice, - policy_value_str(entry->value)); -} - -static DBusMessage *print_policy(E_DBus_Object *obj, DBusMessage *msg) { - char line[ENTRY_LINE_SIZE]; - dd_list *elem; - struct policy_entry *entry; - int ret; - - _I("USB access policy:"); - DD_LIST_FOREACH(access_list, elem, entry) { - ret = marshal_policy_entry(line, ENTRY_LINE_SIZE, entry); - if (ret < 0) - break; - _I("\t%s", line); - } - - return dbus_message_new_method_return(msg); -} - -static int store_policy(void) -{ - int fd; - dd_list *elem; - struct policy_entry *entry; - char line[256]; - int ret; - - fd = open(POLICY_FILEPATH, O_WRONLY | O_CREAT, 0664); - if (fd < 0) { - _E("Could not open policy file for writing: %m"); - return -errno; - } - - DD_LIST_FOREACH(access_list, elem, entry) { - if (is_policy_temporary(entry)) - continue; - - ret = marshal_policy_entry(line, ENTRY_LINE_SIZE, entry); - if (ret < 0) { - _E("Serialization failed: %m"); - goto out; - } - - ret = write(fd, line, ret); - if (ret < 0) { - ret = -errno; - _E("Error writing policy entry: %m"); - goto out; - } - } - - _I("Policy stored in %s", POLICY_FILEPATH); - - ret = 0; - -out: - close(fd); - return ret; -} - -static int read_policy(void) -{ - FILE *fp; - struct policy_entry *entry; - char *line = NULL, value_str[256]; - int ret = -1; - int count = 0; - size_t len; - - fp = fopen(POLICY_FILEPATH, "r"); - if (!fp) { - ret = -errno; - _E("Could not open policy file for reading: %m"); - return ret; - } - - while ((ret = getline(&line, &len, fp)) != -1) { - entry = malloc(sizeof(*entry)); - if (!entry) { - ret = -ENOMEM; - _E("No memory: %m"); - goto out; - } - - entry->creds.sec_label = calloc(ENTRY_LINE_SIZE, 1); - if (!entry->creds.sec_label) { - _E("No memory: %m"); - goto out; - } - - ret = sscanf(line, "%d %255s %04hx %02hhx %02hhx %02hhx %04hx %04hx %04hx %255s\n", - &entry->creds.uid, - entry->creds.sec_label, - &entry->device.bcdUSB, - &entry->device.bDeviceClass, - &entry->device.bDeviceSubClass, - &entry->device.bDeviceProtocol, - &entry->device.idVendor, - &entry->device.idProduct, - &entry->device.bcdDevice, - value_str); - if (ret == EOF) { - _E("Error reading line: %m"); - free(entry->creds.sec_label); - free(entry); - goto out; - } - - entry->value = get_policy_value_from_str(value_str); - if (entry->value < 0) { - _E("Invalid policy value: %s", value_str); - ret = -EINVAL; - goto out; - } - - _I("%04x:%04x : %s", entry->device.idVendor, entry->device.idProduct, - value_str); - - DD_LIST_APPEND(access_list, entry); - count++; - } - - _I("Found %d policy entries", count); - ret = 0; - -out: - fclose(fp); - free(line); - - return ret; -} - -static int get_device_desc(const char *filepath, struct usb_device_descriptor *desc, char *devpath) -{ - char *path = NULL; - const char *rdevpath; - struct stat st; - int ret; - int fd = -1; - struct udev *udev = NULL; - struct udev_device *udev_device = NULL; - - ret = stat(filepath, &st); - if (ret < 0) { - ret = -errno; - _E("Could not stat %s: %m", filepath); - goto out; - } - - if (!S_ISCHR(st.st_mode) || - major(st.st_rdev) != USB_DEVICE_MAJOR) { - ret = -EINVAL; - _E("Not an USB device"); - goto out; - } - - udev = udev_new(); - if (!udev) { - _E("Could not create udev contect"); - ret = -ENOMEM; - goto out; - } - - udev_device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); - if (!udev_device) { - _E("udev could not find device"); - ret = -ENOENT; - goto out; - } - - rdevpath = udev_device_get_devpath(udev_device); - strncpy(devpath, rdevpath, PATH_MAX); - - ret = asprintf(&path, "/sys/dev/char/%d:%d/descriptors", major(st.st_rdev), minor(st.st_rdev)); - if (ret < 0) { - ret = -ENOMEM; - _E("asprintf failed"); - goto out; - } - - _I("Opening descriptor at %s", path); - fd = open(path, O_RDONLY); - if (fd < 0) { - ret = -errno; - _E("Failed to open %s: %m", path); - goto out; - } - - ret = read(fd, desc, sizeof(*desc)); - if (ret < 0) { - ret = -errno; - _E("Failed to read %s: %m", path); - goto out; - } - - ret = 0; - -out: - if (fd >= 0) - close(fd); - free(path); - - udev_device_unref(udev_device); - udev_unref(udev); - - return ret; -} - -static void store_idler_cb(void *data) -{ - store_policy(); -} - -static void destroy_open_request(struct usbhost_open_request *req) -{ - _D("Destroing request structure"); - free(req->path); - req->path = NULL; - req->reply_conn = NULL; - dbus_message_unref(req->msg); - req->msg = NULL; -} - -static void finish_opening(struct usbhost_open_request *req, int policy) -{ - int ret; - int fd = -1; - DBusMessageIter iter; - DBusMessage *reply; - const char *err; - - if (req->path == NULL) - return; - - switch (policy) { - case POLICY_ALLOW_NOW: - case POLICY_ALLOW_ALWAYS: - fd = open(req->path, O_RDWR); - if (fd < 0) { - ret = -errno; - err = DBUS_ERROR_FAILED; - _E("Unable to open file (%s): %m", req->path); - } else - ret = 0; - break; - case POLICY_DENY_NOW: - case POLICY_DENY_ALWAYS: - ret = -EACCES; - err = DBUS_ERROR_ACCESS_DENIED; - break; - default: - ret = -EINVAL; - err = DBUS_ERROR_FAILED; - break; - } - - if (ret < 0) { - reply = dbus_message_new_error(req->msg, err, NULL); - if (!reply) { - _E("Cannot allocate memory for error message"); - goto out; - } - } else { - reply = dbus_message_new_method_return(req->msg); - if (!reply) { - _E("Cannot allocate memory for message"); - goto out; - } - - dbus_message_iter_init_append(reply, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_UNIX_FD, &fd); - } - - e_dbus_message_send(req->reply_conn, reply, NULL, 0, NULL); - -out: - destroy_open_request(req); - if(fd >= 0) - close(fd); - _I("Popup destroyed"); -} - -static int spawn_popup(struct usbhost_open_request *req) -{ - char pid_str[8]; - int ret; - - if (!req) - return -EINVAL; - - /* Handle for the previous popup */ - if (current_request) { - finish_opening(current_request, POLICY_DENY_NOW); - free(current_request); - current_request = NULL; - } - - _I("Launching popup"); - - snprintf(pid_str, sizeof(pid_str), "%d", req->cred.pid); - ret = launch_system_app(APP_DEFAULT, 4, APP_KEY_TYPE, "usbhost", "_APP_PID_", pid_str); - if (ret < 0) { - _E("could not launch system popup"); - return ret; - } - - return ret; -} - -static void popup_result_signal_handler(void *data, DBusMessage *msg) -{ - DBusError err; - int allow, always; - int ret; - struct policy_entry *entry; - int value; - struct usbhost_open_request *req; - - req = current_request; - - if (!dbus_message_is_signal(msg, POPUP_INTERFACE_SYSTEM, USB_HOST_RESULT_SIGNAL)) - return; - - dbus_error_init(&err); - ret = dbus_message_get_args(msg, &err, - DBUS_TYPE_INT32, &allow, - DBUS_TYPE_INT32, &always, - DBUS_TYPE_INVALID); - - if (!ret) { - _E("no message: [%s:%s]", err.name, err.message); - value = POLICY_DENY_NOW; - goto out; - } - - if (allow && always) - value = POLICY_ALLOW_ALWAYS; - else if (!allow && always) - value = POLICY_DENY_ALWAYS; - else if (allow && !always) - value = POLICY_ALLOW_NOW; - else - value = POLICY_DENY_NOW; - - /* Save the policy */ - - entry = calloc(sizeof(*entry), 1); - if (!entry) { - _E("No memory"); - goto out; - } - - entry->creds.uid = req->cred.uid; - entry->creds.sec_label = calloc(strlen(req->cred.sec_label)+1, 1); - if (!entry->creds.sec_label) { - _E("No memory"); - free(entry); - goto out; - } - - strncpy(entry->creds.sec_label, req->cred.sec_label, strlen(req->cred.sec_label)); - - switch (value) { - case POLICY_ALLOW_ALWAYS: - case POLICY_DENY_ALWAYS: - entry->device.bcdUSB = le16toh(req->desc.bcdUSB); - entry->device.bDeviceClass = req->desc.bDeviceClass; - entry->device.bDeviceSubClass = req->desc.bDeviceSubClass; - entry->device.bDeviceProtocol = req->desc.bDeviceProtocol; - entry->device.idVendor = le16toh(req->desc.idVendor); - entry->device.idProduct = le16toh(req->desc.idProduct); - entry->device.bcdDevice = le16toh(req->desc.bcdDevice); - - _I("Added policy entry: %d %s %04x %02x %02x %02x %04x %04x %04x %s", - entry->creds.uid, - entry->creds.sec_label, - entry->device.bcdUSB, - entry->device.bDeviceClass, - entry->device.bDeviceSubClass, - entry->device.bDeviceProtocol, - entry->device.idVendor, - entry->device.idProduct, - entry->device.bcdDevice, - policy_value_str(value)); - break; - case POLICY_ALLOW_NOW: - case POLICY_DENY_NOW: - strncpy(entry->devpath, req->devpath, strlen(req->devpath)); - _I("Added temporary policy entry: %d %s %s %s", - entry->creds.uid, - entry->creds.sec_label, - entry->devpath, - policy_value_str(value)); - break; - } - - entry->value = value; - DD_LIST_APPEND(access_list, entry); - - ret = add_idle_request(store_idler_cb, NULL); - if (ret < 0) { - _E("fail to add store idle request : %d", ret); - store_idler_cb(NULL); - } - -out: - finish_opening(req, value); - free(current_request); - current_request = NULL; - dbus_error_free(&err); -} - -static int get_policy_value(struct usbhost_open_request *req) -{ - int ret; - dd_list *elem; - struct policy_entry *entry; - - memset(&req->desc, 0, sizeof(req->desc)); - - _I("Requested access from user %d to %s", req->cred.uid, req->path); - ret = get_device_desc(req->path, &req->desc, req->devpath); - if (ret < 0) { - _E("Could not get device descriptor"); - return ret; - } - - DD_LIST_FOREACH(access_list, elem, entry) { - if(entry->creds.uid != req->cred.uid - || strncmp(entry->creds.sec_label, req->cred.sec_label, strlen(req->cred.sec_label)) != 0) - continue; - - if (is_policy_temporary(entry) ? strncmp(entry->devpath, req->devpath, PATH_MAX) : - entry->device.bcdUSB != le16toh(req->desc.bcdUSB) - || entry->device.bDeviceClass != req->desc.bDeviceClass - || entry->device.bDeviceSubClass != req->desc.bDeviceSubClass - || entry->device.bDeviceProtocol != req->desc.bDeviceProtocol - || entry->device.idVendor != le16toh(req->desc.idVendor) - || entry->device.idProduct != le16toh(req->desc.idProduct) - || entry->device.bcdDevice != le16toh(req->desc.bcdDevice)) - continue; - - _I("Found matching policy entry: %s", policy_value_str(entry->value)); - - return entry->value; - } - - return POLICY_NONE; -} - -static int creds_read_uint32(DBusMessageIter *iter, uint32_t *dest) -{ - int type; - DBusMessageIter sub; - - dbus_message_iter_next(iter); - - dbus_message_iter_recurse(iter, &sub); - type = dbus_message_iter_get_arg_type(&sub); - if (type != DBUS_TYPE_UINT32) { - _E("expected uint32"); - return -EINVAL; - } - - dbus_message_iter_get_basic(&sub, dest); - - return 0; -} - -static int creds_read_label(DBusMessageIter *iter, char **dest) -{ - int type; - DBusMessageIter sub, byte; - int n; - - dbus_message_iter_next(iter); - - dbus_message_iter_recurse(iter, &sub); - type = dbus_message_iter_get_arg_type(&sub); - if (type != DBUS_TYPE_ARRAY) { - _E("expected array of bytes"); - return -EINVAL; - } - - dbus_message_iter_recurse(&sub, &byte); - dbus_message_iter_get_fixed_array(&byte, dest, &n); - - return n; -} - -static int get_caller_credentials(DBusMessage *msg, struct user_credentials *cred) -{ - const char *cid; - char *key; - char *arr[1]; - DBusMessage *reply; - DBusMessageIter iter, dict, entry; - dbus_bool_t ret; - int type; - int reti; - - cid = dbus_message_get_sender(msg); - if (!cid) { - _E("Unable to identify client"); - return -1; - } - - arr[0] = (char *)cid; - reply = dbus_method_sync_with_reply(DBUS_BUS_NAME, - DBUS_OBJECT_PATH, - DBUS_INTERFACE_NAME, - METHOD_GET_CONNECTION_CREDENTIALS, - "s", arr); - - if (!reply) { - _E("Cannot get connection credentials for %s", cid); - return -1; - } - - ret = dbus_message_iter_init(reply, &iter); - if (!ret) { - _E("could not init msg iterator"); - reti = -1; - goto out; - } - - type = dbus_message_iter_get_arg_type(&iter); - if (type != DBUS_TYPE_ARRAY) { - _E("Expected array (%s)", cid); - reti = -EINVAL; - goto out; - } - - dbus_message_iter_recurse(&iter, &dict); - - while ((type = dbus_message_iter_get_arg_type(&dict)) != DBUS_TYPE_INVALID) { - if (type != DBUS_TYPE_DICT_ENTRY) { - _E("Expected dict entry (%s)", cid); - reti = -EINVAL; - goto out; - } - - dbus_message_iter_recurse(&dict, &entry); - type = dbus_message_iter_get_arg_type(&entry); - if (type != DBUS_TYPE_STRING) { - _E("Expected string (%s)", cid); - reti = -EINVAL; - goto out; - } - - dbus_message_iter_get_basic(&entry, &key); - if (strncmp(key, UID_KEY, sizeof(UID_KEY)) == 0) { - reti = creds_read_uint32(&entry, &cred->uid); - if (reti < 0) - goto out; - } else if (strncmp(key, SEC_LABEL_KEY, sizeof(SEC_LABEL_KEY)) == 0) { - reti = creds_read_label(&entry, &cred->sec_label); - if (reti < 0) - goto out; - } else if (strncmp(key, PID_KEY, sizeof(PID_KEY)) == 0) { - reti = creds_read_uint32(&entry, &cred->pid); - if (reti < 0) - goto out; - } - - dbus_message_iter_next(&dict); - } - - reti = 0; - -out: - dbus_message_unref(reply); - return reti; -} - -static void remove_all_access_list(void) -{ - struct policy_entry *entry; - dd_list *n, *next; - - DD_LIST_FOREACH_SAFE(access_list, n, next, entry) { - DD_LIST_REMOVE(access_list, entry); - free(entry->creds.sec_label); - free(entry); - } -} - -static DBusMessage *open_device(E_DBus_Object *obj, DBusMessage *msg) -{ - DBusError err; - dbus_bool_t dbus_ret; - int ret = 0; - int policy; - char *path; - struct usbhost_open_request *req; - - dbus_error_init(&err); - - - req = calloc(sizeof(*req), 1); - if (!req) { - _E("no memory"); - return dbus_message_new_error(msg, DBUS_ERROR_FAILED, "no memory"); - } - - req->msg = dbus_message_ref(msg); - req->reply_conn = e_dbus_object_conn_get(obj); - - ret = get_caller_credentials(msg, &req->cred); - if (ret < 0) { - _E("Unable to get credentials for caller : %d", ret); - goto out; - } - - dbus_ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); - if (!dbus_ret) { - _E("Unable to get arguments from message: %s", err.message); - ret = -EINVAL; - goto out; - } - - req->path = strdup(path); - policy = get_policy_value(req); - if (policy < 0) { - _E("Could not get policy value (%d)", policy); - ret = -1; - goto out; - } - - /* Need to ask user */ - if (policy == POLICY_NONE) { - ret = spawn_popup(req); - if (ret < 0) { - finish_opening(req, POLICY_DENY_NOW); - free(req); - return NULL; - } - - current_request = req; - return NULL; - } - - /* The policy exists for the app */ - _D("Policy exists"); - finish_opening(req, policy); - free(req); - return NULL; - -out: - destroy_open_request(req); - free(req); - return dbus_message_new_error(msg, DBUS_ERROR_FAILED, NULL); -} - -static const struct edbus_method edbus_methods[] = { - { "PrintDeviceList", NULL, NULL, print_device_list }, /* for debugging */ - { "PrintPolicy", NULL, NULL, print_policy }, /* for debugging */ - { "GetDeviceList", "i", "a(siiiiisss)", get_device_list }, - { "GetDeviceListCount", "i", "i", get_device_list_count }, - { "OpenDevice", "s", "ih", open_device }, -}; - -static int booting_done(void *data) -{ - /** - * To search the attched usb host device is not an argent task. - * So deviced does not load while booting time. - * After booting task is done, it tries to find the attached devices. - */ - usbhost_init_from_udev_enumerate(); - - /* unregister booting done notifier */ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - - return 0; -} - -static void usbhost_init(void *data) -{ - int ret; - - /* register usbhost uevent */ - ret = register_kernel_uevent_control(&uh); - if (ret < 0) - _E("fail to register usb uevent : %d", ret); - - /* register usbhost interface and method */ - ret = register_edbus_interface_and_method(DEVICED_PATH_USBHOST, - DEVICED_INTERFACE_USBHOST, - edbus_methods, ARRAY_SIZE(edbus_methods)); - if (ret < 0) - _E("fail to register edbus interface and method! %d", ret); - - /* register notifier */ - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - - ret = asprintf(&POLICY_FILEPATH, "%s/%s", ROOTPATH, POLICY_FILENAME); - if (ret < 0) { - _E("no memory for policy path"); - return; - } - - ret = register_edbus_signal_handler(POPUP_PATH_SYSTEM, - POPUP_INTERFACE_SYSTEM, USB_HOST_RESULT_SIGNAL, - popup_result_signal_handler); - if (ret < 0) { - _E("could not register popup signal handler"); - return; - } - - read_policy(); -} - -static void usbhost_exit(void *data) -{ - int ret; - - /* unreigset usbhost uevent */ - ret = unregister_kernel_uevent_control(&uh); - if (ret < 0) - _E("fail to unregister usb uevent : %d", ret); - - /* remove all usbhost list */ - remove_all_usbhost_list(); - - store_policy(); - remove_all_access_list(); - - free(POLICY_FILEPATH); -} - -static const struct device_ops usbhost_device_ops = { - .name = "usbhost", - .init = usbhost_init, - .exit = usbhost_exit, -}; - -DEVICE_OPS_REGISTER(&usbhost_device_ops) diff --git a/systemd/sdb-prestart.service b/systemd/sdb-prestart.service deleted file mode 100644 index 4c6d4c5..0000000 --- a/systemd/sdb-prestart.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Enadle sdb at booting time -DefaultDependencies=no - -[Service] -SmackProcessLabel=System -ExecStart=/usr/bin/direct_set_debug.sh --sdb-set - -[Install] -WantedBy=basic.target diff --git a/systemd/usb-host-ffs-test-daemon.service b/systemd/usb-host-ffs-test-daemon.service deleted file mode 100644 index 08572af..0000000 --- a/systemd/usb-host-ffs-test-daemon.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Description=FFS daemon required by usb-host test suite - -[Service] -ExecStart=/usr/bin/usb-host-ffs-test-daemon -USBFunctionDescriptors=/etc/deviced/usb-host-test/descs -USBFunctionStrings=/etc/deviced/usb-host-test/strs diff --git a/systemd/usb-host-test.socket b/systemd/usb-host-test.socket deleted file mode 100644 index abcbc08..0000000 --- a/systemd/usb-host-test.socket +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=USB test functionfs socket - -[Socket] -ListenUSBFunction=/run/usb-host-test-ffs -Service=usb-host-ffs-test-daemon.service diff --git a/udev/99-usbhost.rules b/udev/99-usbhost.rules deleted file mode 100644 index a719bec..0000000 --- a/udev/99-usbhost.rules +++ /dev/null @@ -1,2 +0,0 @@ -SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", DEVPATH!="/devices/platform/dummy_hcd.*", MODE="0660", GROUP="system_share", SECLABEL{smack}="*" -SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", DEVPATH=="/devices/platform/dummy_hcd.*", MODE="0666", GROUP="system_share", SECLABEL{smack}="*"