diff options
author | jy910.yun <jy910.yun@samsung.com> | 2012-08-21 19:32:30 +0900 |
---|---|---|
committer | jy910.yun <jy910.yun@samsung.com> | 2012-08-21 19:32:30 +0900 |
commit | d675c476c375bb7dfd0afe0c5a173be25132b546 (patch) | |
tree | 562fb0e0c01b3750d0e83b4efa7c11eda06016b9 | |
parent | 9d218fe6244a90dc326b8440c65dc37aea83c8f5 (diff) | |
download | usb-manager-d675c476c375bb7dfd0afe0c5a173be25132b546.tar.gz usb-manager-d675c476c375bb7dfd0afe0c5a173be25132b546.tar.bz2 usb-manager-d675c476c375bb7dfd0afe0c5a173be25132b546.zip |
patch tizen_2.0_build
42 files changed, 2651 insertions, 0 deletions
@@ -0,0 +1,2 @@ +Jinkun Jang <jinkun.jang@samsung.com>
+DongGi Jang <dg0402.jang@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b687131 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(usb-server C) + +SET(SRCS + src/um_common.c + src/um_customize.c + src/um_main.c + src/um_usb_accessory_manager.c + src/um_usb_connection_manager.c + src/um_usb_server.c) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + appcore-common + ecore + vconf + heynoti + dlog + syspopup-caller + iniparser + devman + appsvc) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DTARGET") + +SET(UDEV_RULES_PATH share/usb-server/udev-rules) +SET(UDEV_RULES udev-rules/91-usb-server.rules) + +CONFIGURE_FILE(${UDEV_RULES}.in ${UDEV_RULES} @ONLY) + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl") + +INSTALL(FILES ${UDEV_RULES} DESTINATION ${UDEV_RULES_PATH}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/usb-server.sh DESTINATION /etc/rc.d/init.d) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/start_dr.sh DESTINATION bin) +ADD_SUBDIRECTORY(po) @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+
diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..7e7e20d --- /dev/null +++ b/debian/changelog @@ -0,0 +1,8 @@ +usb-manager (0.0.1-1) unstable; urgency=low + + * modify obs spec file for devman_plugin + * Git: slp/pkgs/u/usb-manager + * Tag: usb-manager_0.0.1-1 + + -- Taeyoung Kim <ty317.kim@samsung.com> Mon, 19 Mar 2012 11:00:59 +0900 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..e3e7c5b --- /dev/null +++ b/debian/control @@ -0,0 +1,28 @@ +Source: usb-manager +Section: tools +Priority: extra +Maintainer: Taeyoung Kim <ty317.kim@samsung.com> Taesoo Jun <steve.jun@samsung.com> +Uploaders: Taeyoung Kim <ty317.kim@samsung.com> Taesoo Jun <steve.jun@samsung.com> +Build-Depends: debhelper (>= 5), + libappcore-common-dev, + libecore-dev, + libheynoti-dev, + libslp-setting-dev, + libdevman-dev, + dlog-dev, + syspopup-caller-dev, + iniparser-dev, + libappsvc-dev +Standards-Version: 3.7.2 + +Package: usb-server +Section: devel +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: usb server package + +Package: usb-server-dbg +Section: debug +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, usb-server (= ${Source-Version}) +Description: usb server degug package diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..a57a869 --- /dev/null +++ b/debian/rules @@ -0,0 +1,130 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS ?= -Wall -g +CXXFLAGS ?= -Wall -g +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /opt + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 + CXXFLAGS += -O0 +else + CFLAGS += -O2 + CXXFLAGS += -O2 +endif + +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + rm -rf CMakeCache.txt + rm -rf CMakeFiles + rm -rf cmake_install.cmake + rm -rf Makefile + rm -rf install_manifest.txt + rm -rf *.so + rm -rf *.desktop + rm -rf po/CMakeCache.txt + rm -rf po/CMakeFiles + rm -rf po/cmake_install.cmake + rm -rf po/Makefile + rm -rf po/install_manifest.txt + rm -rf po/*.so + rm -rf udev-rules/*.rules + + + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp. + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/ + ln -s ../init.d/usb-server.sh $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S36usb-server + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/ + ln -s ../init.d/usb-server.sh $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S01usb-server + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link +# dh_strip + dh_strip --dbg-package=usb-server-dbg + dh_compress + dh_fixperms +# dh_perl + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/debian/usb-server.install.in b/debian/usb-server.install.in new file mode 100644 index 0000000..cc1eb57 --- /dev/null +++ b/debian/usb-server.install.in @@ -0,0 +1,6 @@ +/usr/bin/start_dr.sh +/usr/bin/usb-server +/usr/share/locale/*/LC_MESSAGES/usb-server.mo +/usr/share/usb-server/udev-rules/91-usb-server.rules +/etc/* +/usr/bin/set_usb_debug.sh diff --git a/debian/usb-server.postinst.in b/debian/usb-server.postinst.in new file mode 100644 index 0000000..1680685 --- /dev/null +++ b/debian/usb-server.postinst.in @@ -0,0 +1,17 @@ +#!/bin/sh + +chown root:root /usr/bin/usb-server +chown root:root /usr/bin/start_dr.sh +chown root:root /usr/bin/set_usb_debug.sh +vconftool set -t int memory/usb/mass_storage_status "0" -u 0 -i -f +vconftool set -t int memory/usb/accessory_status "0" -u 5000 -i -f +vconftool set -t int db/usb/keep_debug "0" + +heynotitool set device_usb_accessory +heynotitool set device_host_chgdet +heynotitool set device_storage_chgdet + +mkdir -p /etc/udev/rules.d +if ! [ -L /etc/udev/rules.d/91-usb-server.rules ]; then + ln -s @PREFIX@/share/usb-server/udev-rules/91-usb-server.rules /etc/udev/rules.d/91-usb-server.rules +fi diff --git a/include/um_common.h b/include/um_common.h new file mode 100644 index 0000000..13c9e7e --- /dev/null +++ b/include/um_common.h @@ -0,0 +1,117 @@ +/* + * Usb server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 __UM_COMMON_H__ +#define __UM_COMMON_H__ + +#include <stdio.h> +#include <stdlib.h> +#include <appcore-common.h> +#include <heynoti.h> +#include <vconf.h> +#include <devman.h> +#include <sys/types.h> +#include <glib.h> +#include <syspopup_caller.h> +#include "um_data.h" + +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> + +#define SOCK_PATH "/tmp/usb_server_sock" +#define ACC_SOCK_PATH "/tmp/usb_acc_sock" +#define USB_ACCESSORY_NODE "/dev/usb_accessory" +#define SETTING_USB_ACCESSORY_MODE 5 +#define SOCK_STR_LEN 1542 /* 6 elements + 5 separators + 1 NULL terminator + = 256 * 6 + 5 * 1 + 1 = 1542 */ +#define ACC_INFO_NUM 6 +#define SETTING_USB_DEFAULT_MODE 0 + + +#define PACKAGE "usb-server" /* for i18n */ +#define LOCALEDIR PREFIX"/share/locale" +#define SYSPOPUP_PARAM_LEN 3 +#define USB_SYSPOPUP "usb-syspopup" + +#include <dlog.h> + +#define USB_TAG "USB_SERVER" + +#define USB_LOG(format, args...) \ + LOG(LOG_VERBOSE, USB_TAG, "[%s][Ln: %d] " format, (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args) + +#define USB_LOG_ERROR(format, args...) \ + LOG(LOG_ERROR, USB_TAG, "[%s][Ln: %d] " format, (char*)(strrchr(__FILE__, '/')+1), __LINE__, ##args) + +#define __USB_FUNC_ENTER__ \ + USB_LOG("Entering: %s()\n", __func__) + +#define __USB_FUNC_EXIT__ \ + USB_LOG("Exit: %s()\n", __func__) + +#define FREE(arg) \ + do { \ + if(arg) { \ + free((void *)arg); \ + arg = NULL; \ + } \ + } while (0); + +#ifndef retv_if +#define retv_if(expr, val) \ + do { \ + if(expr) { \ + return (val); \ + } \ + } while (0) +#endif + +#define um_retvm_if(expr, val, fmt, arg...) \ + do { \ + if(expr) { \ + USB_LOG_ERROR(fmt, ##arg); \ + return (val); \ + } \ + } while (0); + +#define um_retm_if(expr, fmt, arg...) \ + do { \ + if(expr) { \ + USB_LOG_ERROR(fmt, ##arg); \ + return; \ + } \ + } while (0); + +int check_usb_connection(); +int check_storage_connection(); +int launch_usb_syspopup(UmMainData *ad, POPUP_TYPE _popup_type); +void load_system_popup(UmMainData *ad, POPUP_TYPE _popup_type); + +int ipc_request_server_init(); +int ipc_request_server_close(UmMainData *ad); +int ipc_noti_server_init(); +int ipc_noti_server_close(int *sock_remote); + +#endif /* __UM_COMMON_H__ */ diff --git a/include/um_customize.h b/include/um_customize.h new file mode 100644 index 0000000..658662a --- /dev/null +++ b/include/um_customize.h @@ -0,0 +1,79 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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_SETTING_CUSTOMIZE_H__ +#define __USB_SETTING_CUSTOMIZE_H__ + +#include <string.h> +#include <vconf.h> +#include "um_common.h" + +#define CMD_DR_START \ + "/usr/bin/start_dr.sh" +#define DATA_ROUTER_PATH \ + "/usr/bin/data-router" +#define KERNEL_SET_PATH \ + "/sys/devices/platform/usb_mode/UsbMenuSel" +#define DRIVER_VERSION_PATH \ + "/sys/class/usb_mode/version" +#define DRIVER_VERSION_1_0 \ + "1.0" +#define USB_MODE_ENABLE \ + "/sys/class/usb_mode/usb0/enable" +#define USB_VENDOR_ID \ + "/sys/class/usb_mode/usb0/idVendor" +#define USB_PRODUCT_ID \ + "/sys/class/usb_mode/usb0/idProduct" +#define USB_FUNCTIONS \ + "/sys/class/usb_mode/usb0/functions" +#define USB_DEVICE_CLASS \ + "/sys/class/usb_mode/usb0/bDeviceClass" +#define USB_DEVICE_SUBCLASS \ + "/sys/class/usb_mode/usb0/bDeviceSubClass" +#define USB_DEVICE_PROTOCOL \ + "/sys/class/usb_mode/usb0/bDeviceProtocol" +#define DRIVER_VERSION_BUF_LEN 64 +#define FILE_PATH_BUF_SIZE 256 +#define KERNEL_SET_BUF_SIZE 3 +#define KERNEL_DEFAULT_MODE 0 +#define KERNEL_DEBUG_MODE 4 +#define __STR_EMUL "emul" +#define __LEN_STR_EMUL 4 +#define BIN_INFO_FILE_PATH "/etc/info.ini" +#define USB_SERVER_MESSAGE_DOMAIN \ + "usb-server" + +#define USB_NOTICE_SYSPOPUP_FAIL \ + "USB system popup failed" +#define TICKERNOTI_SYSPOPUP \ + "tickernoti-syspopup" + +static int mode_set_driver_0_0(int mode); +static int mode_set_driver_1_0(int mode); +static Eina_Bool write_file(const char *filepath, char *content); +int check_driver_version(UmMainData *ad); + +int mode_set_kernel(USB_DRIVER_VERSION version, int mode); +void start_dr(UmMainData *ad); +void load_connection_popup(UmMainData *ad); + +#endif + diff --git a/include/um_data.h b/include/um_data.h new file mode 100644 index 0000000..0a7fef6 --- /dev/null +++ b/include/um_data.h @@ -0,0 +1,121 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 __UM_DATA_H__ +#define __UM_DATA_H__ + +#include <Ecore.h> +#include <unistd.h> +#define ACC_ELEMENT_LEN 256 +#define PKG_NAME_LEN 64 + +typedef enum { + CHANGE_COMPLETE = 0, + IN_MODE_CHANGE +} MODE_CHANGE; + +typedef enum { + SYSPOPUP_TYPE = 0, + MAX_NUM_SYSPOPUP_PARAM + /* When we need to deliver other parameters to USB-syspopup + * add the types of parameters */ +} SYSPOPUP_PARAM; + +typedef enum { + ERROR_POPUP = 0, + SELECT_PKG_FOR_ACC_POPUP, + REQUEST_PERM_POPUP, + MAX_NUM_SYSPOPUP_TYPE + /* When we need to add other system popup, + * Write here the type of popup */ +} POPUP_TYPE; + +typedef enum { + IPC_ERROR = 0, + IPC_FAIL, + IPC_SUCCESS +} IPC_SIMPLE_RESULT; + +typedef enum { + LAUNCH_APP = 0, + REQUEST_PERMISSION, + HAS_PERMISSION, + REQ_PERM_NOTI_YES_BTN, + REQ_PERM_NOTI_NO_BTN, + GET_ACC_INFO, + ERROR_POPUP_OK_BTN, +} REQUEST_TO_USB_MANGER; + +typedef enum { + NOTPERMITTED = 0, + PERMITTED +} HAS_PERM; + +typedef enum { + USB_DRIVER_0_0 = 0, + USB_DRIVER_1_0, + MAX_NUM_USB_DRIVER_VERSION + /* We can add kernel versions here */ +} USB_DRIVER_VERSION; + +typedef enum { + ACT_SUCCESS = 0x1000, + ACT_FAIL +} ACTION_RESULT; + +typedef enum { + ACC_MANUFACTURER = 0, + ACC_MODEL, + ACC_DESCRIPTION, + ACC_VERSION, + ACC_URI, + ACC_SERIAL +} ACC_ELEMENT; + +typedef struct _UsbAccessory { + char *manufacturer; + char *model; + char *description; + char *version; + char *uri; + char *serial; +} UsbAccessory; + +typedef struct _UmMainData { + Ecore_Fd_Handler *ipcRequestServerFdHandler; + int server_sock_local; + int server_sock_remote; + + int acc_noti_fd; + + UsbAccessory *usbAcc; + char *permittedPkgForAcc; + char *launchedApp; + + /* System status */ + USB_DRIVER_VERSION driverVersion; + + /* USB connection */ + int usbSelMode; +} UmMainData; + +#endif /* __UM_DATA_H__ */ diff --git a/include/um_main.h b/include/um_main.h new file mode 100644 index 0000000..399feb5 --- /dev/null +++ b/include/um_main.h @@ -0,0 +1,28 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 __UM_MAIN_H__ +#define __UM_MAIN_H__ + +#include "um_usb_server.h" + +#endif /* __UM_MAIN_H__ */ diff --git a/include/um_usb_accessory_manager.h b/include/um_usb_accessory_manager.h new file mode 100644 index 0000000..5b7fcc2 --- /dev/null +++ b/include/um_usb_accessory_manager.h @@ -0,0 +1,37 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_customize.h" +#include <vconf.h> +#include <appsvc.h> + +#define USB_ACCESSORY_GET_MANUFACTURER _IOW('M', 1, char[256]) +#define USB_ACCESSORY_GET_MODEL _IOW('M', 2, char[256]) +#define USB_ACCESSORY_GET_DESCRIPTION _IOW('M', 3, char[256]) +#define USB_ACCESSORY_GET_VERSION _IOW('M', 4, char[256]) +#define USB_ACCESSORY_GET_URI _IOW('M', 5, char[256]) +#define USB_ACCESSORY_GET_SERIAL _IOW('M', 6, char[256]) + +int initAccessory(UsbAccessory *usbAcc); +int connectAccessory(UmMainData *ad); +int disconnectAccessory(UmMainData *ad); +void getCurrentAccessory(); +void umAccInfoInit(UmMainData *ad); diff --git a/include/um_usb_connection_manager.h b/include/um_usb_connection_manager.h new file mode 100644 index 0000000..69b5925 --- /dev/null +++ b/include/um_usb_connection_manager.h @@ -0,0 +1,49 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_customize.h" + +#define SDBD_START "/etc/init.d/sdbd start" +#define SDBD_STOP "/etc/init.d/sdbd stop" +#define SET_USB0_IP \ + "ifconfig usb0 192.168.129.3 up" +#define UNSET_USB0_IP \ + "ifconfig usb0 down" +#define ADD_DEFAULT_GW \ + "route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0" +#define OPENSSHD_START \ + "/etc/init.d/ssh start" +#define OPENSSHD_STOP \ + "/etc/init.d/ssh stop" + +int action_clean(UmMainData *ad, int mode); +int call_cmd(char* cmd); +int connectUsb(UmMainData *ad); +int disconnectUsb(UmMainData *ad); +void change_mode_cb(keynode_t* in_key, void *data); +void change_hotspot_status_cb(keynode_t* in_key, void *data); +static int check_mobile_hotspot_status(); +static int run_core_action(UmMainData *ad, int mode); +void select_kies_mode_popup(UmMainData *ad); +int set_USB_mode(UmMainData *ad, int mode); +void change_hotspot_status_cb(keynode_t* in_key, void *data); +void usb_connection_selected_btn(UmMainData *ad, int input); + diff --git a/include/um_usb_server.h b/include/um_usb_server.h new file mode 100644 index 0000000..fefcc51 --- /dev/null +++ b/include/um_usb_server.h @@ -0,0 +1,29 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 <vconf.h> +#include "um_main.h" +#include "um_usb_accessory_manager.h" +#include "um_usb_connection_manager.h" + +void um_signal_init(); +int um_usb_server_init(); diff --git a/packaging/usb-manager.spec b/packaging/usb-manager.spec new file mode 100644 index 0000000..d053cda --- /dev/null +++ b/packaging/usb-manager.spec @@ -0,0 +1,62 @@ +Name: usb-server +Summary: USB server +Version: 0.0.1 +Release: 3 +Group: TO_BE/FILLED_IN +License: TO_BE/FILLED_IN +Source0: usb-server-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: libattr-devel +BuildRequires: gettext-devel +BuildRequires: pkgconfig(appcore-common) +BuildRequires: pkgconfig(ecore) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(iniparser) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(appsvc) + +%description +Description: USB server + + +%prep +%setup -q +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + +%build +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d/ +ln -s %{_sysconfdir}/init.d/usb-server.sh %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S36usb-server +mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d/ +ln -s %{_sysconfdir}/init.d/usb-server.sh %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S01usb-server + + +%post + +vconftool set -t int memory/usb/mass_storage_status "0" -u 0 -i -f +vconftool set -t int memory/usb/accessory_status "0" -u 5000 -i -f + +heynotitool set device_usb_accessory + +mkdir -p /etc/udev/rules.d +if ! [ -L /etc/udev/rules.d/91-usb-server.rules ]; then + ln -s /usr/share/usb-server/udev-rules/91-usb-server.rules /etc/udev/rules.d/91-usb-server.rules +fi + + +%files +%defattr(540,root,root,-) +/usr/bin/start_dr.sh +/usr/bin/usb-server +%attr(440,root,root) /usr/share/locale/*/LC_MESSAGES/usb-server.mo +%attr(440,root,root) /usr/share/usb-server/udev-rules/91-usb-server.rules +/etc/* diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt new file mode 100644 index 0000000..f908c14 --- /dev/null +++ b/po/CMakeLists.txt @@ -0,0 +1,23 @@ +# for i18n +#SET(POFILES en_US.po en_GB.po ja.po ko.po zh_CN.po) +SET(POFILES de_DE.po el_GR.po en.po es_ES.po fr_FR.po it_IT.po ja_JP.po ko_KR.po nl_NL.po pt_PT.po ru_RU.po tr_TR.po zh_CN.po zh_HK.po zh_TW.po) +SET(MSGFMT "/usr/bin/msgfmt") + +FOREACH(pofile ${POFILES}) + SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile}) + MESSAGE("PO: ${pofile}") + GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE) + GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE) + SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo) + ADD_CUSTOM_COMMAND( + OUTPUT ${moFile} + COMMAND ${MSGFMT} -o ${moFile} ${absPofile} + DEPENDS ${absPofile} + ) + INSTALL(FILES ${moFile} + DESTINATION share/locale/${lang}/LC_MESSAGES RENAME usb-server.mo) + SET(moFiles ${moFiles} ${moFile}) +ENDFOREACH(pofile) + +MESSAGE(".mo files: ${moFiles}") +ADD_CUSTOM_TARGET(po_usb_server ALL DEPENDS ${moFiles}) diff --git a/po/de_DE.po b/po/de_DE.po new file mode 100755 index 0000000..fc24a00 --- /dev/null +++ b/po/de_DE.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB-Tethering aktiviert" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB-Debugging verbunden" diff --git a/po/el_GR.po b/po/el_GR.po new file mode 100755 index 0000000..571fc48 --- /dev/null +++ b/po/el_GR.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Ενεργοποιήθηκε το tethering USB" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Εντοπισμός σφαλμάτων USB" diff --git a/po/en.po b/po/en.po new file mode 100755 index 0000000..bd7be33 --- /dev/null +++ b/po/en.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB tethering enabled" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB debugging connected" diff --git a/po/es_ES.po b/po/es_ES.po new file mode 100755 index 0000000..4aed8f3 --- /dev/null +++ b/po/es_ES.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Anclaje a red USB activado" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Depuración USB conectada" diff --git a/po/fr_FR.po b/po/fr_FR.po new file mode 100755 index 0000000..5aac609 --- /dev/null +++ b/po/fr_FR.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Modem USB activé" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Débogage USB connecté" diff --git a/po/it_IT.po b/po/it_IT.po new file mode 100755 index 0000000..54e79a3 --- /dev/null +++ b/po/it_IT.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Tethering USB attivato" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Debug USB connesso" diff --git a/po/ja_JP.po b/po/ja_JP.po new file mode 100755 index 0000000..b1db6a5 --- /dev/null +++ b/po/ja_JP.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USBテザリングが有効です。" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USBデバッグが接続されました。" diff --git a/po/ko_KR.po b/po/ko_KR.po new file mode 100755 index 0000000..5e0bf83 --- /dev/null +++ b/po/ko_KR.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB 테더링이 실행되었습니다" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB 디버깅이 실행되었습니다" diff --git a/po/nl_NL.po b/po/nl_NL.po new file mode 100755 index 0000000..08b047f --- /dev/null +++ b/po/nl_NL.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB-tethering ingeschakeld" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB-foutopsporing aangesloten" diff --git a/po/pt_PT.po b/po/pt_PT.po new file mode 100755 index 0000000..34cf03d --- /dev/null +++ b/po/pt_PT.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Ancoragem USB activada" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Depuração de USB ligada" diff --git a/po/ru_RU.po b/po/ru_RU.po new file mode 100755 index 0000000..6e06917 --- /dev/null +++ b/po/ru_RU.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "Модем USB включен" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "Отладка USB подключена" diff --git a/po/tr_TR.po b/po/tr_TR.po new file mode 100755 index 0000000..5a2e6cc --- /dev/null +++ b/po/tr_TR.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB bağlanma etkin" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB hata ayıklama bağlandı" diff --git a/po/zh_CN.po b/po/zh_CN.po new file mode 100755 index 0000000..d569015 --- /dev/null +++ b/po/zh_CN.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "USB tethering 已启用" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB调试已连接" diff --git a/po/zh_HK.po b/po/zh_HK.po new file mode 100755 index 0000000..a50f6fe --- /dev/null +++ b/po/zh_HK.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "已啟用 USB 網絡共享" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "已連接USB除錯" diff --git a/po/zh_TW.po b/po/zh_TW.po new file mode 100755 index 0000000..3e36df0 --- /dev/null +++ b/po/zh_TW.po @@ -0,0 +1,5 @@ +msgid "IDS_ST_HEADER_USB_TETHERING_ENABLED" +msgstr "已啟用 USB 網路共享" + +msgid "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED" +msgstr "USB偵錯已連結" diff --git a/src/um_common.c b/src/um_common.c new file mode 100644 index 0000000..589fb1c --- /dev/null +++ b/src/um_common.c @@ -0,0 +1,208 @@ +/* + * Usb Server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 <vconf.h> +#include <devman.h> + +#include "um_common.h" + +int check_usb_connection() +{ + __USB_FUNC_ENTER__ ; + int status = -1; + int ret = -1; + ret = vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &status); + um_retvm_if(0 != ret, -1, "FAIL: vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS)"); + __USB_FUNC_EXIT__ ; + return status; +} + +int launch_usb_syspopup(UmMainData *ad, POPUP_TYPE _popup_type) +{ + __USB_FUNC_ENTER__ ; + if (!ad) return -1; + int ret = -1; + char syspopup_key[SYSPOPUP_PARAM_LEN]; + char syspopup_value[ACC_ELEMENT_LEN]; + + bundle *b = NULL; + b = bundle_create(); + um_retvm_if (!b, -1, "FAIL: bundle_create()\n"); + + snprintf(syspopup_key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_TYPE); + snprintf(syspopup_value, ACC_ELEMENT_LEN, "%d", _popup_type); + ret = bundle_add(b, syspopup_key, syspopup_value); + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()\n"); + return -1; + } + + if (SELECT_PKG_FOR_ACC_POPUP == _popup_type) { + int i; + char device[ACC_INFO_NUM][ACC_ELEMENT_LEN]; + snprintf(device[ACC_MANUFACTURER], ACC_ELEMENT_LEN, "%s", ad->usbAcc->manufacturer); + snprintf(device[ACC_MODEL], ACC_ELEMENT_LEN, "%s", ad->usbAcc->model); + snprintf(device[ACC_DESCRIPTION], ACC_ELEMENT_LEN, "%s", ad->usbAcc->description); + snprintf(device[ACC_VERSION], ACC_ELEMENT_LEN, "%s", ad->usbAcc->version); + snprintf(device[ACC_URI], ACC_ELEMENT_LEN, "%s", ad->usbAcc->uri); + snprintf(device[ACC_SERIAL], ACC_ELEMENT_LEN, "%s", ad->usbAcc->serial); + for ( i = 0; i < ACC_INFO_NUM ; i++) { + snprintf(syspopup_key, SYSPOPUP_PARAM_LEN, "%d", 1 + i); + snprintf(syspopup_value, ACC_ELEMENT_LEN, "%s", device[i]); + USB_LOG("key: %s, value: %s\n", syspopup_key, syspopup_value); + ret = bundle_add(b, syspopup_key, syspopup_value); + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()\n"); + return -1; + } + } + } + + ret = syspopup_launch(USB_SYSPOPUP, b); + if (0 > ret) { + USB_LOG("FAIL: syspopup_launch() returns %d\n", ret); + if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()\n"); + return -1; + } + + ret = bundle_free(b); + um_retvm_if (0 != ret, -1, "FAIL: bundle_free()\n"); + + __USB_FUNC_EXIT__ ; + return 0; +} + +void load_system_popup(UmMainData *ad, POPUP_TYPE _popup_type) +{ + __USB_FUNC_ENTER__ ; + if (!ad) return ; + int ret = -1; + ret = launch_usb_syspopup(ad, _popup_type); + if (0 != ret) { + USB_LOG("FAIL: launch_usb_syspopup(_popup_type)\n"); + } + __USB_FUNC_EXIT__ ; +} + +int ipc_request_server_init() +{ + __USB_FUNC_ENTER__ ; + int len, t; + int sockFd = -1; + struct sockaddr_un local; + + if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + perror("socket"); + USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)"); + return -1; + } + local.sun_family = AF_UNIX; + strncpy(local.sun_path, SOCK_PATH, strlen(SOCK_PATH)+1); + unlink(local.sun_path); + len = strlen(local.sun_path) + sizeof(local.sun_family); + + if (bind(sockFd, (struct sockaddr *)&local, len) == -1) { + perror("bind"); + USB_LOG("FAIL: bind((*sock_local), (struct sockaddr *)&local, len)"); + return -1; + } + chown(SOCK_PATH, 5000, 5000); + chmod(SOCK_PATH, 0777); + if (listen(sockFd, 5) == -1) { + perror("listen"); + USB_LOG("FAIL: listen((*sock_local), 5)"); + return -1; + } + __USB_FUNC_EXIT__ ; + return sockFd; +} + +int ipc_request_server_close(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + if (ad->server_sock_local > 0) + close(ad->server_sock_local); + if (ad->server_sock_remote > 0) + close(ad->server_sock_remote); + __USB_FUNC_EXIT__ ; + return 0; +} + + +/* This function initializes socket for ipc with usb-server */ +int ipc_noti_server_init() +{ + __USB_FUNC_ENTER__ ; + int len; + int sock_remote; + struct sockaddr_un remote; + if ((sock_remote = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + perror("socket"); + USB_LOG("FAIL: socket(AF_UNIX, SOCK_STREAM, 0)"); + return -1;; + } + remote.sun_family = AF_UNIX; + strncpy(remote.sun_path, ACC_SOCK_PATH, strlen(SOCK_PATH)+1); + len = strlen(remote.sun_path) + sizeof(remote.sun_family); + + if (connect(sock_remote, (struct sockaddr *)&remote, len) == -1) { + perror("connect"); + USB_LOG("FAIL: connect(sock_remote, (struct sockaddr *)&remote, len)"); + return -1; + } + __USB_FUNC_EXIT__ ; + return sock_remote; +} + +/* This function closes socket for ipc with usb-server */ +int ipc_noti_server_close(int *sock_remote) +{ + __USB_FUNC_ENTER__ ; + if (!sock_remote) return -1; + close (*sock_remote); + __USB_FUNC_EXIT__ ; + return 0; +} + +/* This function notices something to client app by ipc with socket and gets the results */ +int notice_to_client_app(int sock_remote, int request, char *answer) +{ + __USB_FUNC_ENTER__ ; + int t; + char str[SOCK_STR_LEN]; + USB_LOG("notice: %d\n", request); + snprintf(str, SOCK_STR_LEN, "%d", request); + if (send (sock_remote, str, strlen(str)+1, 0) == -1) { + USB_LOG("FAIL: send (sock_remote, str, strlen(str)+1, 0)\n"); + return -1; + } + if ((t = recv(sock_remote, answer, SOCK_STR_LEN, 0)) > 0) { + USB_LOG("[CLIENT] Received value: %s\n", answer); + } else { + USB_LOG("FAIL: recv(sock_remote, str, SOCK_STR_LEN, 0)\n"); + return -1; + } + __USB_FUNC_EXIT__ ; + return 0; +} diff --git a/src/um_customize.c b/src/um_customize.c new file mode 100644 index 0000000..f8cafe5 --- /dev/null +++ b/src/um_customize.c @@ -0,0 +1,319 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_customize.h" +#include <iniparser.h> + +#define USB_DEFAULT_MODE_CONNECTED "Default USB mode enabled" +#define USB_ACCESSORY_MODE_ENABLED "USB accessory mode enabled" + +/* If other kernel versions are added, we should modify this function */ +int check_driver_version(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + + if(!ad) return -1; + char buffer[DRIVER_VERSION_BUF_LEN]; + + FILE *fp = NULL; + + if (access(DRIVER_VERSION_PATH, F_OK) != 0) { + USB_LOG("This kernel is for C210\n"); + ad->driverVersion = USB_DRIVER_0_0; + } else { + fp = fopen(DRIVER_VERSION_PATH, "r"); + um_retvm_if(fp == NULL, -1, "FAIL: fopen(%s)\n", DRIVER_VERSION_PATH); + + if (fgets(buffer, DRIVER_VERSION_BUF_LEN, fp) == NULL) { + USB_LOG("FAIL: fgets(%s)\n", DRIVER_VERSION_PATH); + if (fclose(fp) != 0) { + USB_LOG("FAIL: fclose(fp)\n"); + } + return -1; + } + + if (fclose(fp) != 0) { + USB_LOG("FAIL: fclose(fp)\n"); + return -1; + } + + if (strncmp(buffer, DRIVER_VERSION_1_0, strlen(DRIVER_VERSION_1_0)) == 0 ) { + USB_LOG("The driver version is 1.0 \n"); + ad->driverVersion = USB_DRIVER_1_0; + } else { + USB_LOG("This kernel version is unknown\n"); + return -1; + } + } + __USB_FUNC_EXIT__ ; + return 0; +} + +int mode_set_kernel(USB_DRIVER_VERSION _version, int mode) +{ + __USB_FUNC_ENTER__ ; + + int ret = -1; + switch(_version) { + case USB_DRIVER_0_0: + USB_LOG("This target is C210 \n"); + ret = mode_set_driver_0_0(mode); + um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_0_0(mode)\n"); + break; + case USB_DRIVER_1_0: + USB_LOG("This target uses a concept which USB mode can be enabled/disabled\n"); + ret = mode_set_driver_1_0(mode); + um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_1_0(mode)\n"); + break; + + /* If other kernel versions are added, add functions here that notice USB mode to the kernel */ + + default: + USB_LOG("This version of kernel is not registered to usb-server.\n"); + __USB_FUNC_EXIT__ ; + return -1; + } + __USB_FUNC_EXIT__ ; + return 0; +} + +static int mode_set_driver_0_0(int mode) +{ + __USB_FUNC_ENTER__ ; + + char buf[DRIVER_VERSION_BUF_LEN]; + int ret = -1; + + switch(mode) + { + case SETTING_USB_DEFAULT_MODE: + case SETTING_USB_NONE_MODE: + USB_LOG("Mode : SETTING_USB_DEFAULT_MODE mode_set_kernel\n"); + snprintf(buf, KERNEL_SET_BUF_SIZE, "%d", KERNEL_DEFAULT_MODE); + break; + case SETTING_USB_DEBUG_MODE: + USB_LOG("Mode : USB_DEBUG_MODE mode_set_kernel\n"); + snprintf(buf, KERNEL_SET_BUF_SIZE, "%d", KERNEL_DEBUG_MODE); + break; + case SETTING_USB_ACCESSORY_MODE: + USB_LOG("Mode : USB accessory is not supported in USB driver 0.0(C210)\n"); + return 0; + default: + USB_LOG("ERROR : parameter is not available(mode : %d)\n", mode); + __USB_FUNC_EXIT__ ; + return -1; + } + + ret = write_file(KERNEL_SET_PATH, buf); + um_retvm_if (EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", KERNEL_SET_PATH); + + __USB_FUNC_EXIT__ ; + return 0; +} +static int driver_1_0_kernel_node_set(char *vendor_id, char *product_id, char *functions, + char *device_class, char *device_subclass, char* device_protocol) +{ + __USB_FUNC_ENTER__ ; + int ret = -1; + + if (vendor_id == NULL || product_id == NULL || functions == NULL + || device_class == NULL || device_subclass == NULL || device_protocol == NULL) { + USB_LOG("ERROR: There are parameters whose value is NULL\n"); + return -1; + } + + ret = write_file(USB_MODE_ENABLE, "0"); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE); + + ret = write_file(USB_VENDOR_ID, vendor_id); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_VENDOR_ID); + + ret = write_file(USB_PRODUCT_ID, product_id); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_PRODUCT_ID); + + ret = write_file(USB_FUNCTIONS, functions); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_FUNCTIONS); + + ret = write_file(USB_DEVICE_CLASS, device_class); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_DEVICE_CLASS); + + ret = write_file(USB_DEVICE_SUBCLASS, device_subclass); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_DEVICE_SUBCLASS); + + ret = write_file(USB_DEVICE_PROTOCOL, device_protocol); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_DEVICE_PROTOCOL); + + ret = write_file(USB_MODE_ENABLE, "1"); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE); + + __USB_FUNC_EXIT__ ; + return 0; +} + +static int mode_set_driver_1_0(int mode) +{ + __USB_FUNC_ENTER__ ; + + int ret = -1; + + switch(mode) + { + case SETTING_USB_DEFAULT_MODE: + USB_LOG("Mode : SETTING_USB_DEFAULT mode_set_kernel\n"); + ret = driver_1_0_kernel_node_set("04e8", "6860", "mtp,acm,sdb", "239", "2", "1"); + __USB_FUNC_EXIT__ ; + return ret; + + case SETTING_USB_DEBUG_MODE: + USB_LOG("Mode : USB_DEBUG_MODE mode_set_kernel\n"); + ret = driver_1_0_kernel_node_set("04e8", "6863", "rndis", "239", "2", "1"); + __USB_FUNC_EXIT__ ; + return ret; + + case SETTING_USB_ACCESSORY_MODE: + USB_LOG("Mode : USB_ACCESSORY_MODE mode_set_kernel\n"); + ret = driver_1_0_kernel_node_set("18d1", "2d00", "accessory", "0", "0", "0"); + __USB_FUNC_EXIT__ ; + return ret; + + case SETTING_USB_NONE_MODE: + USB_LOG("Mode : USB_NONE_MODE mode_set_kernel\n"); + ret = write_file(USB_MODE_ENABLE, "0"); + um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE); + __USB_FUNC_EXIT__ ; + return ret; + + default: + USB_LOG("ERROR : parameter is not available(mode : %d)\n", mode); + __USB_FUNC_EXIT__ ; + return ret; + } +} + +void start_dr(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return ; + call_cmd(CMD_DR_START); + __USB_FUNC_EXIT__ ; +} + +static Eina_Bool write_file(const char *filepath, char *content) +{ + __USB_FUNC_ENTER__ ; + + if(!filepath || !content) return EINA_FALSE; + FILE *fp; + int ret = -1; + + fp = fopen(filepath, "w"); + um_retvm_if (fp == NULL, EINA_FALSE, "FAIL: fopen(%s)\n", filepath); + + ret = fwrite(content, sizeof(char), strlen(content), fp); + if ( ret < strlen(content)) { + USB_LOG("FAIL: fwrite()\n"); + ret = fclose(fp); + if(ret != 0) USB_LOG("FAIL : fclose()\n"); + return EINA_FALSE; + } + + ret = fclose(fp); + um_retvm_if (ret != 0, EINA_FALSE, "FAIL: result of fclose() is %d\n", ret); + + __USB_FUNC_EXIT__ ; + return EINA_TRUE; +} + +void load_connection_popup(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + + if(!ad) return ; + bundle *b = NULL; + int ret = -1; + int usbCurMode = -1; + + b = bundle_create(); + um_retm_if (!b, "FAIL: bundle_create()\n"); + + ret = bundle_add(b, "0", "info"); /* "0" means tickernoti style */ + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if ( 0 != bundle_free(b) ) + USB_LOG("FAIL: bundle_free()\n"); + return; + } + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + USB_LOG("usbCurMode: %d\n", usbCurMode); + switch(usbCurMode) { + case SETTING_USB_DEFAULT_MODE: + ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, USB_DEFAULT_MODE_CONNECTED)); + break; + case SETTING_USB_DEBUG_MODE: + ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, + "IDS_HS_HEADER_USB_DEBUGGING_CONNECTED")); + break; + case SETTING_USB_MOBILE_HOTSPOT: + ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, + "IDS_ST_HEADER_USB_TETHERING_ENABLED")); + break; + case SETTING_USB_ACCESSORY_MODE: + ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, USB_ACCESSORY_MODE_ENABLED)); + break; + + default: + ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, USB_NOTICE_SYSPOPUP_FAIL)); + break; + } + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if ( 0 != bundle_free(b) ) + USB_LOG("FAIL: bundle_free()\n"); + return; + } + + ret = bundle_add(b, "2", "1"); /* "2" means orientation of tickernoti */ + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if ( 0 != bundle_free(b) ) + USB_LOG("FAIL: bundle_free()\n"); + return; + } + + ret = bundle_add(b, "3", "3"); /* "3" means timeout(second) of tickernoti */ + if (0 != ret) { + USB_LOG("FAIL: bundle_add()\n"); + if ( 0 != bundle_free(b) ) + USB_LOG("FAIL: bundle_free()\n"); + return; + } + + ret = syspopup_launch(TICKERNOTI_SYSPOPUP, b); + if (0 != ret) { + USB_LOG("FAIL: syspopup_launch()\n"); + } + + ret = bundle_free(b); + um_retm_if(0 != ret, "FAIL: bundle_free()\n"); + + __USB_FUNC_EXIT__ ; +} diff --git a/src/um_main.c b/src/um_main.c new file mode 100644 index 0000000..faee233 --- /dev/null +++ b/src/um_main.c @@ -0,0 +1,88 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_main.h" +#include <heynoti.h> + +static void fini(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + int ret = um_usb_server_release_handler(ad); + if (ret < 0) USB_LOG("FAIL: um_usb_server_release_handler(ad)\n"); + __USB_FUNC_EXIT__; +} + +static void usb_server_start_daemon() +{ + __USB_FUNC_ENTER__; + pid_t pid; + if ((pid = fork()) < 0) { + exit(0); + } else if (pid != 0) { + exit(0); + } + chdir("/"); + setsid(); /* Start a new session as a child of init process*/ + + __USB_FUNC_EXIT__; +} + +static void usb_server_init(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + usb_server_start_daemon(); + um_signal_init(); + appcore_set_i18n(PACKAGE, LOCALEDIR); + um_usb_server_init(ad); + __USB_FUNC_EXIT__; +} + +static int usb_server_main(int argc, char **argv) +{ + __USB_FUNC_ENTER__; + UmMainData ad; + memset(&ad, 0x0, sizeof(UmMainData)); + ad.usbAcc = (UsbAccessory*)malloc(sizeof(UsbAccessory)); + + usb_server_init(&ad); + + ecore_main_loop_begin(); + + fini(&ad); + ecore_shutdown(); + + __USB_FUNC_EXIT__; + return 0; +} + +static int elm_main(int argc, char **argv) +{ + __USB_FUNC_ENTER__; + __USB_FUNC_EXIT__; + return usb_server_main(argc, argv); +} + +int main(int argc, char **argv) +{ + __USB_FUNC_ENTER__; + ecore_init(); + __USB_FUNC_EXIT__; + return elm_main(argc, argv); +} diff --git a/src/um_usb_accessory_manager.c b/src/um_usb_accessory_manager.c new file mode 100644 index 0000000..26106d1 --- /dev/null +++ b/src/um_usb_accessory_manager.c @@ -0,0 +1,213 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_usb_accessory_manager.h" +#include <vconf.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <sys/stat.h> + +int initAccessory(UsbAccessory *usbAcc) +{ + __USB_FUNC_ENTER__; + if (!usbAcc) return -1; + + int acc = open(USB_ACCESSORY_NODE, O_RDONLY); + um_retvm_if(acc < 0, -1, "FAIL: open(USB_ACCESSORY_NODE, O_RDONLY)"); + + char buf[ACC_ELEMENT_LEN]; + ioctl(acc, USB_ACCESSORY_GET_MANUFACTURER, buf); + usbAcc->manufacturer = strdup(buf); + ioctl(acc, USB_ACCESSORY_GET_MODEL, buf); + usbAcc->model = strdup(buf); + ioctl(acc, USB_ACCESSORY_GET_DESCRIPTION, buf); + usbAcc->description = strdup(buf); + ioctl(acc, USB_ACCESSORY_GET_VERSION, buf); + usbAcc->version = strdup(buf); + ioctl(acc, USB_ACCESSORY_GET_URI, buf); + usbAcc->uri = strdup(buf); + ioctl(acc, USB_ACCESSORY_GET_SERIAL, buf); + usbAcc->serial = strdup(buf); + + close(acc); + + __USB_FUNC_EXIT__; + return 0; +} + +int accessoryAttached(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return -1; + load_system_popup(ad, SELECT_PKG_FOR_ACC_POPUP); + __USB_FUNC_EXIT__; + return 0; +} + +int connectAccessory(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return -1; + int ret = -1; + ret = initAccessory(ad->usbAcc); + um_retvm_if(0 != ret, -1, "FAIL: initAccessory(ad->usbAcc)"); + getCurrentAccessory(ad); + + /* Change usb mode to accessory mode */ + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_ACCESSORY_MODE); + um_retvm_if(0 != ret, -1, "FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)"); + + ret = accessoryAttached(ad); + um_retvm_if(0 > ret, -1, "FAIL: accessoryAttached(ad);"); + + __USB_FUNC_EXIT__; + return 0; +} + +int loadURIForAccessory(UsbAccessory *usbAcc) +{ + __USB_FUNC_ENTER__; + if (!usbAcc) return -1; +/* service_h service_handle = NULL; + if (service_create(&service_handle) < 0) { + USB_LOG("FAIL: service_create(&service_handle)"); + return -1; + } + um_retvm_if (!service_handle, -1, "service_handle"); + if (service_set_operation(service_handle, "http://tizen.org/appsvc/operation/view") < 0) { + USB_LOG("FAIL: service_set_operation(service_handle, http://tizen.org/appsvc/operation/view)"); + service_destroy(service_handle); + return -1; + } + if (service-set_uri(servoce_handle, usbAcc->uri) < 0) { + USB_LOG("FAIL: service-set_uri(servoce_handle, usbAcc->uri)"); + service_destroy(service_handle); + return -1; + } + service_destroy(service_handle);*/ + bundle *bd = bundle_create(); + um_retvm_if(NULL == bd, -1, "FAIL: bundle_create()"); + appsvc_set_operation(bd, APPSVC_OPERATION_VIEW); + appsvc_set_uri(bd, usbAcc->uri); + appsvc_run_service(bd, 0, NULL, NULL); + if (bundle_free(bd)) { + USB_LOG("FAIL: bundle_free()"); + } + __USB_FUNC_EXIT__; + return 0; +} + +int grantAccessoryPermission(UmMainData *ad, char *appId) +{ + __USB_FUNC_ENTER__; + if (!ad) return -1; + if (!appId) return -1; + + if (ad->permittedPkgForAcc != NULL) { + USB_LOG("Previous permitted pkg is removed\n"); + } + FREE(ad->permittedPkgForAcc); + ad->permittedPkgForAcc = strdup(appId); + USB_LOG("Permitted pkg for accessory is %s\n", ad->permittedPkgForAcc); + __USB_FUNC_EXIT__; + return 0; +} + +int launch_app(char *appId) +{ + __USB_FUNC_ENTER__; + if (appId == NULL) return -1; + bundle *b = NULL; + b = bundle_create(); + um_retvm_if(!b, -1, "FAIL: bundle_create()"); + int ret = aul_launch_app(appId, b); + bundle_free(b); + um_retvm_if(0 > ret, -1, "FAIL: aul_launch_app(appId, b)"); + __USB_FUNC_EXIT__; + return 0; +} + +Eina_Bool hasPermission(UmMainData *ad, char *appId) +{ + /* Check whether or not a package has permission to access to device/accessory */ + __USB_FUNC_ENTER__; + if (!ad) return EINA_FALSE; + if (ad->permittedPkgForAcc && appId) { + if (!strncmp(ad->permittedPkgForAcc, appId, strlen(appId))) { + __USB_FUNC_EXIT__; + return EINA_TRUE; + } + } + __USB_FUNC_EXIT__; + return EINA_FALSE; +} + +static int usbAccessoryRelease(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return -1; + FREE(ad->usbAcc->manufacturer); + FREE(ad->usbAcc->version); + FREE(ad->usbAcc->description); + FREE(ad->usbAcc->model); + FREE(ad->usbAcc->uri); + FREE(ad->usbAcc->serial); + FREE(ad->permittedPkgForAcc); + + __USB_FUNC_EXIT__; + return 0; +} + +void umAccInfoInit(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return ; + int ret = usbAccessoryRelease(ad); + if (0 != ret) USB_LOG("FAIL: usb_accessory_release(ad)\n"); + + __USB_FUNC_EXIT__; +} + +int disconnectAccessory(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return -1; + usbAccessoryRelease(ad); + __USB_FUNC_EXIT__; + return 0; +} + +void getCurrentAccessory(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!ad) return ; + if (!(ad->usbAcc)) return ; + /* Get current accessory */ + USB_LOG("** USB Accessory Info **\n"); + USB_LOG("Manufacturer: %s\n", ad->usbAcc->manufacturer); + USB_LOG("Model : %s\n", ad->usbAcc->model); + USB_LOG("Description : %s\n", ad->usbAcc->description); + USB_LOG("Version : %s\n", ad->usbAcc->version); + USB_LOG("Uri : %s\n", ad->usbAcc->uri); + USB_LOG("Serial : %s\n", ad->usbAcc->serial); + USB_LOG("************************\n"); + __USB_FUNC_EXIT__; +} diff --git a/src/um_usb_connection_manager.c b/src/um_usb_connection_manager.c new file mode 100644 index 0000000..a892d07 --- /dev/null +++ b/src/um_usb_connection_manager.c @@ -0,0 +1,380 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_usb_connection_manager.h" + +int call_cmd(char* cmd) +{ + __USB_FUNC_ENTER__ ; + int ret = system(cmd); + USB_LOG("The result of %s is %d\n",cmd, ret); + __USB_FUNC_EXIT__ ; + return ret; +} + +int connectUsb(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int ret = -1; + int mh_status = -1; + int usbSelMode = -1; + + /* If the mobile hotspot is on, USB-setting changes USB mode to mobile hotspot */ + mh_status = check_mobile_hotspot_status(); + if ((mh_status >= 0) && (mh_status & VCONFKEY_MOBILE_HOTSPOT_MODE_USB)) + { + USB_LOG("Mobile hotspot is on\n"); + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_MOBILE_HOTSPOT); + um_retvm_if (0 != ret, -1, "FAIL: vconf_set_int(VCONF_SETAPPL_USB_SEL_MODE_INT)\n"); + __USB_FUNC_EXIT__ ; + return 0; + } else { + USB_LOG("Mobile hotspot is off\n"); + } + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &usbSelMode); + if (0 != ret) { + USB_LOG("FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)\n"); + usbSelMode = SETTING_USB_DEFAULT_MODE; + } + + ret = set_USB_mode(ad, usbSelMode); + if (0 != ret) { + USB_LOG("ERROR: Cannot set USB mode \n"); + } + __USB_FUNC_EXIT__ ; + return 0; +} + +int disconnectUsb(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int ret = -1; + int usbCurMode = -1; + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + um_retvm_if(ret <0, -1, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n"); + + action_clean(ad, usbCurMode); + + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_NONE_MODE); + if (ret != 0) { + USB_LOG("ERROR: vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n"); + } + + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_DEFAULT_MODE); + if (0 != ret) { + USB_LOG("ERROR: vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)\n"); + } + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, CHANGE_COMPLETE); + if (0 != ret) { + USB_LOG("FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)\n"); + } + __USB_FUNC_EXIT__ ; + return 0; +} + +int usb_mode_change_done(UmMainData *ad, int done) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int vconf_ret = -1; + int ret = -1; + int usbSelMode = -1; + int usbCurMode = -1; + + if (VCONFKEY_SYSMAN_USB_AVAILABLE != check_usb_connection()) { + return 0; + } + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &usbSelMode); + um_retvm_if(ret < 0, -1, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)\n"); + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + um_retvm_if(ret < 0, -1, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n"); + + if(ACT_SUCCESS == done) { + /* Decide current mode */ + switch (usbSelMode) { + case SETTING_USB_MOBILE_HOTSPOT: + if (usbCurMode != SETTING_USB_NONE_MODE) { + ad->usbSelMode = usbCurMode; + break; + } + case SETTING_USB_DEFAULT_MODE: + case SETTING_USB_DEBUG_MODE: + case SETTING_USB_ACCESSORY_MODE: + default: + ad->usbSelMode = SETTING_USB_DEFAULT_MODE; + break; + } + usbCurMode = usbSelMode; + vconf_ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, usbCurMode); + um_retvm_if (0 != vconf_ret, -1, "FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n"); + if (SETTING_USB_MOBILE_HOTSPOT != usbCurMode) { + load_connection_popup(ad); + } + + } else { /* USB mode change failed */ + action_clean(ad, usbSelMode); + load_system_popup(ad, ERROR_POPUP); + } + __USB_FUNC_EXIT__ ; + return 0; +} + +void change_mode_cb(keynode_t* in_key, void *data) +{ + __USB_FUNC_ENTER__ ; + if(!data) return ; + UmMainData *ad = (UmMainData *)data; + int ret = -1; + int usbSelMode = -1; + int usbCurMode = -1; + + if (VCONFKEY_SYSMAN_USB_AVAILABLE != check_usb_connection()) { + return ; + } + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &usbSelMode); + um_retm_if (0 != ret , "ERROR: Cannot get the vconf key\n"); + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + um_retm_if (0 != ret , "ERROR: Cannot get the vconf key\n"); + um_retm_if (usbSelMode == usbCurMode, "Previous connection mode is same as the input mode\n"); + + ret = set_USB_mode(ad, usbSelMode); + um_retm_if (0 != ret, "ERROR: Cannot set USB mode \n"); + + __USB_FUNC_EXIT__ ; + return ; +} + +int set_USB_mode(UmMainData *ad, int mode) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int ret = -1; + int done = ACT_FAIL; + int usbCurMode = -1; + + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, IN_MODE_CHANGE); + if (0 != ret) { + USB_LOG("FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)"); + } + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + if (0 == ret && SETTING_USB_NONE_MODE != usbCurMode) { + action_clean(ad, usbCurMode); + } + USB_LOG("Mode change : %d\n", mode); + done = run_core_action(ad, mode); + ret = usb_mode_change_done(ad, done); + um_retvm_if(0 != ret, -1, "usb_mode_change_done(ad, done)"); + + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, CHANGE_COMPLETE); + if (0 != ret) { + USB_LOG("vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)"); + } + + __USB_FUNC_EXIT__ ; + return 0; +} + +void change_hotspot_status_cb(keynode_t* in_key, void *data) +{ + __USB_FUNC_ENTER__ ; + if(!data) return ; + + UmMainData *ad = (UmMainData *)data; + int mh_status = -1; + int ret = -1; + int usbCurMode = -1; + if (VCONFKEY_SYSMAN_USB_AVAILABLE != check_usb_connection()) { + return; + } + + mh_status = check_mobile_hotspot_status(); + USB_LOG("mobile_hotspot_status: %d\n", mh_status); + um_retm_if (0 > mh_status, "FAIL: Getting mobile hotspot status\n"); + + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + um_retm_if (0 != ret, "FAIL: vconf_get_int(VCONF_SETAPPL_USB_MODE_INT)\n"); + + if (mh_status & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) { + USB_LOG("USB Mobile hotspot is on\n"); + + if (usbCurMode != SETTING_USB_MOBILE_HOTSPOT) { + /* When mobile hotspot is on, this callabck only sets vconf key value of USB mode. + * And then, the callback function for vconf change will be called */ + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_MOBILE_HOTSPOT); + um_retm_if (0 != ret, "FAIL: vconf_set_int(VCONF_SETAPPL_USB_MODE_INT)\n"); + } + } else { + USB_LOG("USB Mobile hotspot is off\n"); + if (usbCurMode == SETTING_USB_MOBILE_HOTSPOT) { + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, ad->usbSelMode); + if (0 != ret) { + USB_LOG("FAIL: vconf_set_int(VCONF_SETAPPL_USB_SEL_MODE_INT)\n"); + return; + } + } + } + __USB_FUNC_EXIT__ ; +} + +static int check_mobile_hotspot_status() +{ + __USB_FUNC_ENTER__ ; + + int mh_status = -1; + int ret = -1; + ret = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &mh_status); + um_retvm_if (0 != ret, -1, "FAIL: vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE)\n"); + __USB_FUNC_EXIT__ ; + return mh_status; +} + +/****************************************************/ +/* Functions related to mode change */ +/****************************************************/ + +static int run_core_action(UmMainData *ad, int mode) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return ACT_FAIL; + int ret = -1; + int usbCurMode = -1; + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode); + um_retvm_if(0 != ret, ACT_FAIL, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n"); + + switch(mode) + { + case SETTING_USB_DEFAULT_MODE: + USB_LOG("Mode : SETTING_USB_DFAULT_MODE\n"); + ret = mode_set_kernel(ad->driverVersion, SETTING_USB_DEFAULT_MODE); + um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n"); + start_dr(ad); + call_cmd(SDBD_START); + break; + + case SETTING_USB_DEBUG_MODE: + USB_LOG("Mode: SETTING_USB_DEBUG_MODE\n"); + if (SETTING_USB_MOBILE_HOTSPOT != usbCurMode) { + ret = mode_set_kernel(ad->driverVersion, SETTING_USB_DEBUG_MODE); + um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n"); + call_cmd(SET_USB0_IP); + call_cmd(ADD_DEFAULT_GW); + } + call_cmd(OPENSSHD_START); + + case SETTING_USB_MOBILE_HOTSPOT: + USB_LOG("Mode : SETTING_USB_MOBILE_HOTSPOT\n"); + if (SETTING_USB_DEBUG_MODE != usbCurMode) { + ret = mode_set_kernel(ad->driverVersion, SETTING_USB_DEBUG_MODE); + um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n"); + call_cmd(SET_USB0_IP); + call_cmd(ADD_DEFAULT_GW); + } + break; + + case SETTING_USB_ACCESSORY_MODE: + USB_LOG("Mode : SETTING_USB_ACCESSORY_MODE\n"); + ret = mode_set_kernel(ad->driverVersion, SETTING_USB_ACCESSORY_MODE); + um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n"); + break; + + default: + break; + } + __USB_FUNC_EXIT__ ; + return ACT_SUCCESS; +} + +int action_clean(UmMainData *ad, int mode) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int ret = -1; + int usbSelMode = -1; + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &usbSelMode); + + switch(mode) { + case SETTING_USB_DEFAULT_MODE: + USB_LOG("Mode : SETTING_USB_DEFAULT_MODE action_clean\n"); + call_cmd(SDBD_STOP); + break; + case SETTING_USB_DEBUG_MODE: + call_cmd(OPENSSHD_STOP); + if (SETTING_USB_MOBILE_HOTSPOT == usbSelMode) { + call_cmd(OPENSSHD_STOP); + } + break; + case SETTING_USB_MOBILE_HOTSPOT: + USB_LOG("Mode : SETTING_USB_MOBILE_HOTSPOT action_clean\n"); + if (SETTING_USB_DEBUG_MODE == usbSelMode) { + call_cmd(UNSET_USB0_IP); + } + break; + case SETTING_USB_ACCESSORY_MODE: + default: + break; + } + ret = mode_set_kernel(ad->driverVersion, SETTING_USB_NONE_MODE); + um_retvm_if(0 != ret, -1, "FAIL: mode_set_kernel(SETTING_USB_SAMSUNG_KIES)"); + __USB_FUNC_EXIT__ ; + return 0; +} + +/***********************************************/ +/* Functions related to popups */ +/***********************************************/ + +void usb_connection_selected_btn(UmMainData *ad, int input) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return ; + if (VCONFKEY_SYSMAN_USB_AVAILABLE != check_usb_connection()) { + return; + } + + switch (input) { + case ERROR_POPUP_OK_BTN: + USB_LOG("The button on the error popup is selected\n"); + response_error_popup(ad); + break; + default: + break; + } + __USB_FUNC_EXIT__ ; +} + +int response_error_popup(UmMainData *ad) +{ + __USB_FUNC_ENTER__ ; + if(!ad) return -1; + int ret = -1; + ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_SAMSUNG_KIES); + um_retvm_if(0 != ret, -1, "ERROR: Cannot set the vconf key\n"); + + __USB_FUNC_EXIT__ ; + return 0; +} diff --git a/src/um_usb_server.c b/src/um_usb_server.c new file mode 100644 index 0000000..8fba52c --- /dev/null +++ b/src/um_usb_server.c @@ -0,0 +1,362 @@ +/* + * USB server + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Taeyoung Kim <ty317.kim@samsung.com> + * + * 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 "um_usb_server.h" +#include <vconf.h> +#include <signal.h> + +char *tempAppId; +static struct sigaction sig_pipe_old_act; + +static void sig_pipe_handler(int signo, siginfo_t *info, void *data) +{ +} + +void um_signal_init() +{ + __USB_FUNC_ENTER__; + struct sigaction sig_act; + sig_act.sa_handler = NULL; + sig_act.sa_sigaction = sig_pipe_handler; + sig_act.sa_flags = SA_SIGINFO; + sigemptyset(&sig_act.sa_mask); + sigaction(SIGPIPE, &sig_act, &sig_pipe_old_act); + __USB_FUNC_EXIT__; +} + +int um_heynoti_add(int *fd, char *noti, void (*cb)(void *), UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if (!fd) return -1; + if (!noti) return -1; + if (!cb) return -1; + if (!ad) return -1; + + *fd = heynoti_init(); + if (-1 == *fd) { + USB_LOG("FAIL: heynoti_init()"); + return -1; + } else { + if (-1 == heynoti_subscribe(*fd, noti, cb, ad)) { + USB_LOG("FAIL: heynoti_subscribe(fd)"); + return -1; + } else { + if (-1 == heynoti_attach_handler(*fd)) { + USB_LOG("FAIL: heynoti_attach_handler(fd)"); + return -1; + } else { + USB_LOG("Success to register heynoti"); + } + } + } + __USB_FUNC_EXIT__; + return 0; +} + +static void usb_chgdet_cb(keynode_t *in_key, void *data) +{ + __USB_FUNC_ENTER__; + if (!data) return; + UmMainData *ad = (UmMainData *)data; + int status = -1; + int ret = -1; + status = check_usb_connection(); + switch(status) { + case VCONFKEY_SYSMAN_USB_DISCONNECTED: + ret = disconnectUsb(ad); + um_retm_if(0 != ret, "FAIL: disconnectUsb(ad)"); + + /* If USB accessory is removed, the vconf value of accessory status should be updated */ + ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &status); + um_retm_if(0 != ret, "FAIL: vconf_get_int(VCONFKEY_USB_SERVER_ACCESSORY_STATUS_INT)\n"); + if (VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED == status) { + ret = vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS, + VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED); + um_retm_if(ret != 0, "FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS)"); + ret = disconnectAccessory(ad); + um_retm_if(ret != 0, "FAIL: disconnectAccessory(ad)\n"); + } + break; + case VCONFKEY_SYSMAN_USB_AVAILABLE: + ret = connectUsb(ad); + um_retm_if(0 != ret, "FAIL: connectUsb(ad)"); + break; + default: + break; + } + __USB_FUNC_EXIT__; +} + +static void acc_chgdet_cb(void *data) +{ + __USB_FUNC_ENTER__; + if (!data) return; + UmMainData *ad = (UmMainData *)data; + static int status; + int ret; + status = check_usb_connection(); + switch(status) { + case VCONFKEY_SYSMAN_USB_DISCONNECTED: + USB_LOG("ACC_DISCONNECTED %d", status); + ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &status); + um_retm_if(0 != ret, "FAIL: vconf_get_int(VCONFKEY_USB_SERVER_ACCESSORY_STATUS_INT)\n"); + if (VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED == status) { + ret = vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS, + VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED); + um_retm_if(ret != 0, "FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS)"); + ret = disconnectAccessory(ad); + um_retm_if(ret != 0, "FAIL: disconnectAccessory(ad)\n"); + } + break; + case VCONFKEY_SYSMAN_USB_AVAILABLE: + USB_LOG("ACC_CONNECTED %d", status); + ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &status); + um_retm_if(0 != ret, "FAIL: vconf_get_int(VCONFKEY_USB_SERVER_ACCESSORY_STATUS_INT)\n"); + if (VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED == status) { + ret = vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS, + VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED); + um_retm_if(ret != 0, "FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS, CONNECTED)"); + ret = connectAccessory(ad); + um_retm_if(ret != 0, "FAIL: connectAccessory(ad)\n"); + } + break; + default: + break; + } + __USB_FUNC_EXIT__; +} + +int um_vconf_key_notify(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if(!ad) return -1; + int ret = -1; + + /* USB Connection Manager */ + ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS, usb_chgdet_cb, ad); + um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS)"); + ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, change_mode_cb, ad); + um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)"); + ret = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, change_hotspot_status_cb, ad); + um_retvm_if (0 != ret, -1, "ERROR: vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE)"); + + __USB_FUNC_EXIT__; + return 0; +} + +int um_value_init(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if(!ad) return -1; + int ret = -1; + + /* USB Connection Manager */ + ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &(ad->usbSelMode)); + um_retvm_if (0 != ret, -1, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)\n"); + umAccInfoInit(ad); + + + __USB_FUNC_EXIT__; + return 0; +} + +int noti_selected_btn(UmMainData *ad, int input) +{ + __USB_FUNC_ENTER__; + int sock_remote; + char buf[SOCK_STR_LEN]; + int ret = -1; + int ipc_result = -1; + if (input == REQ_PERM_NOTI_YES_BTN) { + ret = grantAccessoryPermission(ad, tempAppId); + if (0 != ret) { + USB_LOG("FAIL: grant_permission_to_app(appId)"); + } + } + FREE(tempAppId); + sock_remote = ipc_noti_server_init(); + um_retvm_if(sock_remote < 0, -1, "FAIL: ipc_noti_server_init()\n"); + ret = notice_to_client_app(sock_remote, input, buf); + um_retvm_if(ret < 0, -1, "FAIL: notice_to_client_app(socke_remote, input, buf)\n"); + ret = ipc_noti_server_close(&sock_remote); + um_retvm_if(ret < 0, -1, "FAIL: ipc_socket_client_close(&sock_remote)\n"); + ipc_result = atoi(buf); + if (IPC_SUCCESS != ipc_result) { + return -1; + } + __USB_FUNC_EXIT__; + return 0; +} + +Eina_Bool answer_to_ipc(void *data, Ecore_Fd_Handler *fd_handler) +{ + __USB_FUNC_ENTER__; + if (!data) return ECORE_CALLBACK_CANCEL; + UmMainData *ad = (UmMainData *)data; + char str[SOCK_STR_LEN]; + int fd, input, output, t, n; + int ret = -1; + struct sockaddr_un remote; + + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ) == EINA_FALSE) + return ECORE_CALLBACK_CANCEL; + fd = ecore_main_fd_handler_fd_get(fd_handler); + + t = sizeof(remote); + if ((ad->server_sock_remote + = accept(ad->server_sock_local, (struct sockaddr *)&remote, &t)) == -1) { + perror("accept"); + USB_LOG("FAIL: accept(ad->server_sock_local, (struct sockaddr *)&remote, &t)\n"); + return ; + } + n = recv(ad->server_sock_remote, str, SOCK_STR_LEN, 0); + if (n <= 0) { + snprintf(str, SOCK_STR_LEN, "ERROR"); + } else { + USB_LOG("[SERVER] Received value: %s", str); + char *appId = str; + if (str) { + while (*appId++) { + if('|' == *appId) { + *appId = '\0'; + appId++; + break; + } + USB_LOG("#"); + } + } + USB_LOG("input: %s, appId: %s\n", str, appId); + + input = atoi(str); + switch(input) { + case LAUNCH_APP: + ret = grantAccessoryPermission(ad, appId); + if (0 != ret) { + USB_LOG("FAIL: grant_permission_to_app(appId)"); + snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR); + } + ret = launch_app(ad->permittedPkgForAcc); + if (0 != ret) { + USB_LOG("FAIL: launch_app(appId)"); + snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR); + break; + } + snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS); + break; + case REQUEST_PERMISSION: + tempAppId = strdup(appId); + USB_LOG("tempAppId: %s\n", tempAppId); + load_system_popup(ad, REQUEST_PERM_POPUP); + snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS); + break; + case HAS_PERMISSION: + if (EINA_TRUE == hasPermission(ad, appId)) { + snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS); + } else { + snprintf(str, SOCK_STR_LEN, "%d", IPC_FAIL); + } + break; + case REQ_PERM_NOTI_YES_BTN: + case REQ_PERM_NOTI_NO_BTN: + snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS); + ret = noti_selected_btn(ad, input); + if (ret < 0) USB_LOG("FAIL: noti_selected_btn(input)\n"); + break; + case GET_ACC_INFO: + snprintf(str, SOCK_STR_LEN, "%s|%s|%s|%s|%s|%s", + ad->usbAcc->manufacturer, + ad->usbAcc->model, + ad->usbAcc->description, + ad->usbAcc->version, + ad->usbAcc->uri, + ad->usbAcc->serial); + break; + case ERROR_POPUP_OK_BTN: + usb_connection_selected_btn(ad, input); + snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS); + break; + default: + snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR); + break; + } + } + USB_LOG("str: %s", str); + + if(send(ad->server_sock_remote, str, strlen(str)+1, 0) < 0) { + USB_LOG("FAIL: end(ad->server_sock_remote, str, strlen(str)+1, 0)\n"); + } + + __USB_FUNC_EXIT__; + return ECORE_CALLBACK_RENEW; +} + +int um_usb_server_init(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + if(!ad) return -1; + um_value_init(ad); + int ret = -1; + + ret = check_driver_version(ad); + um_retvm_if(0 != ret, -1, "FAIL: check_driver_version(ad)"); + + ad->server_sock_local = ipc_request_server_init(); + um_retvm_if(0 > ad->server_sock_local, -1, "FAIL: ipc_request_server_init()\n"); + + ad->ipcRequestServerFdHandler = ecore_main_fd_handler_add(ad->server_sock_local, + ECORE_FD_READ, answer_to_ipc, ad, NULL, NULL); + um_retvm_if(NULL == ad->ipcRequestServerFdHandler, -1, "FAIL: ecore_main_fd_handler_add()"); + + ret = um_vconf_key_notify(ad); + um_retvm_if(0 != ret, -1, "FAIL: um_vconf_key_notify(ad)"); + + ret = um_heynoti_add(&(ad->acc_noti_fd), "device_usb_accessory", acc_chgdet_cb, ad); + um_retvm_if(0 != ret, -1, "FAIL: um_heynoti_add(ad->acc_noti_fd)"); + + usb_chgdet_cb(NULL, ad); + + __USB_FUNC_EXIT__; + return 0; +} + +int um_usb_server_release_handler(UmMainData *ad) +{ + __USB_FUNC_ENTER__; + int ret = -1; + + if (ad->ipcRequestServerFdHandler != NULL) { + ecore_main_fd_handler_del(ad->ipcRequestServerFdHandler); + ad->ipcRequestServerFdHandler == NULL; + } + + ipc_request_server_close(ad); + + ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, usb_chgdet_cb); + if (0 != ret) USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS)"); + + ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, change_mode_cb); + if (0 != ret) USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)"); + + ret = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, change_hotspot_status_cb); + if (0 != ret) USB_LOG("ERROR: vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE)"); + + __USB_FUNC_EXIT__; + return 0; +} diff --git a/start_dr.sh b/start_dr.sh new file mode 100755 index 0000000..bff365d --- /dev/null +++ b/start_dr.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# start data-router +if (/bin/ps -e | /bin/grep data-router); then + /bin/echo "Already DR activated. No need launch DR" +else + /bin/echo "Launch DR" + /usr/bin/data-router & +fi diff --git a/udev-rules/91-usb-server.rules.in b/udev-rules/91-usb-server.rules.in new file mode 100644 index 0000000..8be057d --- /dev/null +++ b/udev-rules/91-usb-server.rules.in @@ -0,0 +1 @@ +ACTION=="change" DEVPATH=="/devices/virtual/misc/usb_accessory", ENV{ACCESSORY}=="START" RUN+="/usr/bin/sys_event device_usb_accessory" diff --git a/usb-server.sh b/usb-server.sh new file mode 100644 index 0000000..405a776 --- /dev/null +++ b/usb-server.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/bin/usb-server & |