src/um_common.c
src/um_customize.c
src/um_main.c
+ src/um_usb_uevent_handler.c
src/um_usb_accessory_manager.c
src/um_usb_connection_manager.c
src/um_usb_host_manager.c
+ src/um_usb_notification.c
src/um_usb_server.c)
-
+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(PACKAGE ${PROJECT_NAME})
+SET(BINDIR "${PREFIX}/bin")
+SET(DATADIR "${PREFIX}/share/${PACKAGE}/data")
+SET(LOCALEDIR "${PREFIX}/share/locale")
+
INCLUDE(FindPkgConfig)
pkg_check_modules(pkgs REQUIRED
appcore-common
ecore
vconf
- heynoti
dlog
syspopup-caller
devman
pmapi
appsvc
+ libudev
libusb-1.0
+ notification
+ capi-system-usb-accessory
)
FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -g")
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g -Wall")
MESSAGE("FLAGS: ${CMAKE_C_FLAGS}")
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
+ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"")
+
IF("${SIMULATOR}" STREQUAL "yes")
ADD_DEFINITIONS("-DSIMULATOR")
ENDIF()
-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(FILES ${CMAKE_CURRENT_SOURCE_DIR}/set_usb_debug.sh DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/set_usb_debug.sh DESTINATION ${BINDIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/direct_set_debug.sh DESTINATION ${BINDIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/usb_icon.png DESTINATION ${DATADIR})
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/start_dr.sh DESTINATION bin)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/start_dr.sh DESTINATION ${BINDIR})
ADD_SUBDIRECTORY(po)
Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
Except as noted, This software is licensed under Apache License, Version 2.
-Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
+Please, see the LICENSE.Apache_v2 file for Apache License terms and conditions.
--- /dev/null
+#!/bin/sh
+
+VERSION=
+
+check_driver_version() {
+ if [ -f /sys/class/usb_mode/version ]
+ then
+ VERSION=`cat /sys/class/usb_mode/version`
+ else
+ VERSION="0.0"
+ fi
+}
+
+load_usb_gadget_0_0() {
+ echo 4 > /sys/devices/platform/usb_mode/UsbMenuSel
+}
+
+load_usb_gadget_1_0() {
+ echo 0 > /sys/class/usb_mode/usb0/enable
+ echo 04e8 > /sys/class/usb_mode/usb0/idVendor
+ echo $1 > /sys/class/usb_mode/usb0/idProduct
+ echo $2 > /sys/class/usb_mode/usb0/functions
+ echo 239 > /sys/class/usb_mode/usb0/bDeviceClass
+ echo 2 > /sys/class/usb_mode/usb0/bDeviceSubClass
+ echo 1 > /sys/class/usb_mode/usb0/bDeviceProtocol
+ echo 1 > /sys/class/usb_mode/usb0/enable
+}
+
+load_usb_gadget_1_1() {
+ echo 0 > /sys/class/usb_mode/usb0/enable
+ echo 04e8 > /sys/class/usb_mode/usb0/idVendor
+ echo $1 > /sys/class/usb_mode/usb0/idProduct
+ echo " " > /sys/class/usb_mode/usb0/functions
+ echo $2 > /sys/class/usb_mode/usb0/funcs_fconf
+ echo $3 > /sys/class/usb_mode/usb0/funcs_sconf
+ echo 239 > /sys/class/usb_mode/usb0/bDeviceClass
+ echo 2 > /sys/class/usb_mode/usb0/bDeviceSubClass
+ echo 1 > /sys/class/usb_mode/usb0/bDeviceProtocol
+ echo 1 > /sys/class/usb_mode/usb0/enable
+}
+
+unload_usb_gadget_1() {
+ echo 0 > /sys/class/usb_mode/usb0/enable
+}
+
+sdb_set() {
+ case "$VERSION" in
+ "1.0")
+ load_usb_gadget_1_0 "6860" "mtp,acm,sdb"
+ ;;
+ "1.1")
+ load_usb_gadget_1_1 "6860" "mtp" "mtp,acm,sdb"
+ ;;
+ *)
+ echo "USB driver version $VERSION is not supported"
+ return
+ ;;
+ esac
+
+ /etc/init.d/sdbd start
+ echo "SDB enabled"
+}
+
+ssh_set() {
+ case "$VERSION" in
+ "0.0")
+ load_usb_gadget_0_0
+ ;;
+ "1.0")
+ load_usb_gadget_1_0 "6864" "rndis"
+ ;;
+ "1.1")
+ load_usb_gadget_1_1 "6864" "rndis" " "
+ ;;
+ *)
+ echo "USB driver version $VERSION is not supported"
+ return
+ ;;
+ esac
+
+ /sbin/ifconfig usb0 192.168.129.3 up
+ /sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0
+ /etc/init.d/ssh start
+ echo "SSH enabled"
+}
+
+usb_unset() {
+ case "$VERSION" in
+ "1.0" | "1.1")
+ unload_usb_gadget_1
+ ;;
+ *)
+ echo "USB driver version $VERSION is not supported"
+ return
+ ;;
+ esac
+}
+
+sdb_unset() {
+ usb_unset
+ /etc/init.d/sdbd stop
+ echo "SDB disabled"
+}
+
+ssh_unset() {
+ usb_unset
+ /sbin/ifconfig usb0 down
+ /etc/init.d/ssh stop
+ echo "SSH disabled"
+}
+
+show_options() {
+ echo "direct_set_debug.sh: usage:"
+ echo " --help This message"
+ echo " --sdb-set Load sdb without usb-manager"
+ echo " --sdb-unset Unload sdb without usb-manager"
+ echo " --ssh-set Load ssh without usb-manager"
+ echo " --ssh-unset Unload ssh without usb-manager"
+}
+
+check_driver_version
+
+case "$1" in
+"--sdb-set")
+ sdb_set
+ /usr/bin/set_usb_debug.sh --mtp-sdb &
+ ;;
+
+"--ssh-set")
+ ssh_set
+ /usr/bin/set_usb_debug.sh --rndis &
+ ;;
+
+"--sdb-unset")
+ sdb_unset
+ ;;
+
+"--ssh-unset")
+ ssh_unset
+ ;;
+
+"--help")
+ show_options
+ ;;
+
+*)
+ echo "Wrong parameters. Please use option --help to check options "
+ ;;
+esac
#ifndef __UM_COMMON_H__
#define __UM_COMMON_H__
+#define _GNU_SOURCE
+
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <appcore-common.h>
-#include <heynoti.h>
#include <vconf.h>
#include <devman.h>
#include <sys/types.h>
#include <libusb.h>
#include <sys/utsname.h>
#include <pmapi.h>
+#include <assert.h>
+#include <libudev.h>
+#include <notification.h>
#include "um_data.h"
#include <errno.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 SOCK_STR_LEN 1542 /* 6 elements + 5 separators + 1 NULL terminator
= 256 * 6 + 5 * 1 + 1 = 1542 */
-#define ACC_INFO_NUM 6
-#define HOST_INFO_NUM 5
-#define HOST_MAX_NUM 127
-
-#define VCONFKEY_SYSMAN_ADDED_STORAGE_UEVENT \
- "memory/private/sysman/added_storage_uevent"
-#define VCONFKEY_SYSMAN_REMOVED_STORAGE_UEVENT \
- "memory/private/sysman/removed_storage_uevent"
-
-#define PACKAGE "usb-server" /* for i18n */
-#define LOCALEDIR PREFIX"/share/locale"
-#define SYSPOPUP_PARAM_LEN 3
-#define USB_SYSPOPUP "usb-syspopup"
+#define USB_ICON_PATH PREFIX"/share/usb-server/data/usb_icon.png"
#include <dlog.h>
-
-#define USB_TAG "USB_SERVER"
-
-#define USB_LOG(format, args...) \
- LOG(LOG_DEBUG, 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__)
+#undef LOG_TAG
+#define LOG_TAG "USB_SERVER"
+#define USB_LOG(fmt, args...) SLOGD(fmt, ##args)
+#define USB_LOG_ERROR(fmt, args...) SLOGE(fmt, ##args)
+#define __USB_FUNC_ENTER__ USB_LOG("ENTER")
+#define __USB_FUNC_EXIT__ USB_LOG("EXIT")
#define FREE(arg) \
do { \
} \
} while (0);
+int call_cmd(char* cmd);
int check_usbclient_connection();
int check_usbhost_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 launch_usb_syspopup(UmMainData *ad, POPUP_TYPE _popup_type, void *device);
+int notice_to_client_app(int sock_remote, int request, char *answer, int answer_len);
int ipc_request_server_init();
int ipc_request_server_close(UmMainData *ad);
* limitations under the License.
*/
-#ifndef __USB_SETTING_CUSTOMIZE_H__
-#define __USB_SETTING_CUSTOMIZE_H__
+#ifndef __UM_CUSTOMIZE_H__
+#define __UM_CUSTOMIZE_H__
#include <string.h>
#include <vconf.h>
"/sys/class/usb_mode/usb0/bDeviceSubClass"
#define USB_DEVICE_PROTOCOL \
"/sys/class/usb_mode/usb0/bDeviceProtocol"
+#define USB_DIAG_CLIENT \
+ "/sys/class/usb_mode/usb0/f_diag/clients"
#define DRIVER_VERSION_BUF_LEN 64
#define FILE_PATH_BUF_SIZE 256
#define KERNEL_SET_BUF_SIZE 3
#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(UmMainData *ad, int mode);
-static int mode_set_driver_1_1(UmMainData *ad, int mode);
-static Eina_Bool write_file(const char *filepath, char *content);
-
int check_driver_version(UmMainData *ad);
int mode_set_kernel(UmMainData *ad, int mode);
-void start_dr(UmMainData *ad);
-void load_connection_popup(UmMainData *ad, char *msg, int orientation);
+void load_connection_popup(char *msg);
+bool is_device_supported(int class);
+int get_default_usb_device(UmMainData *ad);
#endif
#include <Ecore.h>
#include <unistd.h>
#include <libusb.h>
-#define ACC_ELEMENT_LEN 256
-#define HOST_ELEMENT_LEN 256
+#define DEVICE_ELEMENT_LEN 256
#define APP_ID_LEN 1024
#define BUF_MAX 256
typedef enum {
+ USB_HOST_REF_INTERFACE = 0x0,
USB_HOST_CDC = 0x2,
USB_HOST_HID = 0x3,
USB_HOST_CAMERA = 0x6,
USB_HOST_PRINTER = 0x7,
USB_HOST_MASS_STORAGE = 0x8,
- USB_HOST_HUB = 0x9
+ USB_HOST_HUB = 0x9,
+ USB_HOST_MISCELLANEOUS = 0xef,
+ USB_HOST_VENDOR_SPECIFIC = 0xff
} USB_HOST_CLASS_SUPPORTED;
typedef enum {
} USB_CONNECTION_STATUS;
typedef enum {
+ USB_NOTI_ACC_ADDED = 0,
+ USB_NOTI_ACC_REMOVED,
+ USB_NOTI_HOST_ADDED,
+ USB_NOTI_HOST_REMOVED,
+ USB_NOTI_MASS_STORAGE_ADDED,
+ USB_NOTI_MASS_STORAGE_REMOVED
+} USB_NOTIFICATION_TYPE;
+
+typedef enum {
TICKERNOTI_ORIENTATION_TOP = 0,
TICKERNOTI_ORIENTATION_BOTTOM
} TICKERNOTI_ORIENTATION;
} 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,
SELECT_PKG_FOR_HOST_POPUP,
HAS_HOST_PERMISSION,
REQ_HOST_PERM_NOTI_YES_BTN,
REQ_HOST_PERM_NOTI_NO_BTN,
- REQ_HOST_CONNECTION
+ REQ_HOST_CONNECTION,
+
+ /* for usb storage */
+ UNMOUNT_USB_STORAGE = 60
+
} REQUEST_TO_USB_MANGER;
typedef enum {
char *serial;
} UsbAccessory;
-typedef struct _UsbHost {
- char *permittedAppId;
- int deviceClass;
- int deviceSubClass;
- int deviceProtocol;
- int idVendor;
- int idProduct;
- int bus;
- int deviceAddress;
-} UsbHost;
+typedef struct _UsbInterface {
+ int ifClass;
+ int ifSubClass;
+ int ifProtocol;
+ int ifIdVendor;
+ int ifIdProduct;
+ int ifBus;
+ int ifAddress;
+ int ifNumber;
+ char *ifIManufacturer;
+ char *ifIProduct;
+ char *permAppId;
+} UsbInterface;
+
+typedef struct _MassStorageDevName {
+ char *devName;
+} MSDevName;
+
+typedef struct _UsbNotification {
+ int privId;
+ char *title;
+ char *content;
+ char *iconPath;
+ int applist;
+ char *devName; /* for Mass storage */
+ UsbInterface *devIf; /* for usb host interface except Mass storage */
+ UsbAccessory *accDev; /* for usb accessory device */
+
+} UsbNotification;
typedef struct _UmMainData {
Ecore_Fd_Handler *ipcRequestServerFdHandler;
- int server_sock_local;
- int server_sock_remote;
-
- int usb_noti_fd;
- int acc_noti_fd;
- int host_add_noti_fd;
- int host_remove_noti_fd;
- int keyboard_add_noti_fd;
- int keyboard_remove_noti_fd;
- int mouse_add_noti_fd;
- int mouse_remove_noti_fd;
- int camera_add_noti_fd;
- int camera_remove_noti_fd;
-
- UsbAccessory *usbAcc;
- UsbHost *usbHost;
- char *permittedPkgForAcc;
- char *launchedApp;
-
- libusb_context *usbctx;
- GList *devList;
- GList *defaultDevList;
+ int serverSock;
+
+ UsbAccessory *usbAcc;
+ char *permAccAppId;
+ char *launchedApp;
+
+ libusb_context *usbctx;
+ GList *devList;
+ GList *defaultDevList;
+ GList *devMSList;
+ Ecore_Timer *addHostTimer;
+ Ecore_Timer *rmHostTimer;
+ bool tmpfsMounted;
/* System status */
- USB_DRIVER_VERSION driverVersion;
- int isHostOrClient;
+ USB_DRIVER_VERSION driverVersion;
+ int isHostOrClient;
/* USB connection */
#ifndef SIMULATOR
bool prevDebugMode;
#endif
+ /* Notification */
+ GList *notiAccList; /* Accessory device */
+ GList *notiHostList; /* Host device */
+ GList *notiMSList; /* Mass storage device */
+
+ /* Uevent monitoring */
+ Ecore_Fd_Handler *udevFdHandler;
+ struct udev_monitor *udevMon;
+ struct udev *udev;
+ int udevFd;
+
} UmMainData;
#endif /* __UM_DATA_H__ */
* limitations under the License.
*/
+#ifndef __UM_USB_ACCESSORY_MANAGER_H__
+#define __UM_USB_ACCESSORY_MANAGER_H__
+
#include "um_customize.h"
#include <vconf.h>
#include <appsvc.h>
#define USB_ACCESSORY_GET_URI _IOW('M', 5, char[256])
#define USB_ACCESSORY_GET_SERIAL _IOW('M', 6, char[256])
-int getAccessoryInfo(UsbAccessory *usbAcc);
-int connectAccessory(UmMainData *ad);
-int disconnectAccessory(UmMainData *ad);
-void getCurrentAccessory();
-void umAccInfoInit(UmMainData *ad);
+void disconnect_accessory(UmMainData *ad);
+void accessory_info_init(UmMainData *ad);
+void get_current_accessory();
+int grant_accessory_permission(UmMainData *ad, char *appId);
+bool has_accessory_permission(UmMainData *ad, char *appId);
+void um_uevent_usb_accessory_added(UmMainData *ad);
+
+#endif /* __UM_USB_ACCESSORY_MANAGER_H__ */
* limitations under the License.
*/
-#include "um_customize.h"
+#ifndef __UM_USB_CONNECTION_MANAGER_H__
+#define __UM_USB_CONNECTION_MANAGER_H__
-#define SDBD_START "/etc/init.d/sdbd start"
-#define SDBD_STOP "/etc/init.d/sdbd stop"
-#define SET_USB0_IP \
- "/sbin/ifconfig usb0 192.168.129.3 up"
-#define UNSET_USB0_IP \
- "/sbin/ifconfig usb0 down"
-#define ADD_DEFAULT_GW \
- "/sbin/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"
+#include "um_customize.h"
-int action_clean(UmMainData *ad, int mode);
-int call_cmd(char* cmd);
int connectUsbClient(UmMainData *ad);
-int disconnectUsbClient(UmMainData *ad);
+void disconnectUsbClient(UmMainData *ad);
+void action_clean(UmMainData *ad, int mode);
void debug_mode_cb(keynode_t* in_key, void *data);
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);
-int set_USB_mode(UmMainData *ad, int mode);
+void change_prev_mode_cb(keynode_t* in_key, void *data);
void change_hotspot_status_cb(keynode_t* in_key, void *data);
void usb_connection_selected_btn(UmMainData *ad, int input);
+int launch_acc_app(char *appId);
+Eina_Bool hasAccPermission(UmMainData *ad, char *appId);
+
+#endif /* __UM_USB_CONNECTION_MANAGER_H__ */
* limitations under the License.
*/
+#ifndef __UM_USB_HOST_MANAGER_H__
+#define __UM_USB_HOST_MANAGER_H__
+
#include <vconf.h>
#include <sys/mount.h>
#include <mntent.h>
#include <string.h>
#include "um_customize.h"
+#include "um_usb_notification.h"
#define MTAB_FILE "/etc/mtab"
#define MOUNT_POINT "/opt/storage/usb"
-
-
-int umGetDeviceInfo(UmMainData *ad);
+int um_get_device_info(UmMainData *ad);
void destroy_device(gpointer data);
-int umReleaseAllDevice(UmMainData *ad);
void usb_host_added_cb(UmMainData *ad);
void usb_host_removed_cb(UmMainData *ad);
int find_host_fd(UmMainData *ad, char *appId);
-int grantHostPermission(UmMainData *ad, char *appId, int vendor, int product);
+int grant_host_permission(UmMainData *ad, char *appId, int vendor, int product);
int launch_host_app(char *appId);
-Eina_Bool hasHostPermission(UmMainData *ad, char *appId, int vendor, int product);
-int show_all_usb_devices(GList *devList, int option);
-void free_func(gpointer data);
-static int um_usb_storage_added();
-static int um_usb_storage_removed();
-int disconnectUsbHost(UmMainData *ad);
+Eina_Bool has_host_permission(UmMainData *ad, char *appId, int vendor, int product);
+void disconnect_usb_host(UmMainData *ad);
+void show_all_usb_devices(GList *devList);
+Eina_Bool is_host_connected(UmMainData *ad, int vendor, int product);
+bool is_mass_storage_mounted(UmMainData *ad, char *devname);
+
+void um_uevent_usb_host_added(UmMainData *ad);
+void um_uevent_usb_host_removed(UmMainData *ad);
+void um_uevent_mass_storage_added(UmMainData *ad, char *devname, char *fstype);
+void um_uevent_mass_storage_removed(UmMainData *ad, char *devname);
-void add_host_noti_cb(void *data);
-void remove_host_noti_cb(void *data);
-void add_mass_storage_cb(keynode_t *in_key, void *data);
-void remove_mass_storage_cb(keynode_t *in_key, void *data);
+#endif /* __UM_USB_HOST_MANAGER_H__ */
--- /dev/null
+/*
+ * usb-manager
+ * Copyright (c) 2012 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 __UM_USB_NOTIFICATION_H__
+#define __UM_USB_NOTIFICATION_H__
+
+#include "um_common.h"
+
+int um_append_host_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *_title,
+ char *_content,
+ char *_iconPath);
+
+int um_append_client_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *title,
+ char *content,
+ char *iconPath);
+
+int um_remove_host_notification(UmMainData *ad,
+ int notiType,
+ void *device);
+
+int um_remove_client_notification(UmMainData *ad,
+ int notiType,
+ void *device);
+
+int um_remove_all_client_notification(UmMainData *ad);
+
+int um_remove_all_host_notification(UmMainData *ad);
+
+#endif /* __UM_USB_NOTIFICATION_H__ */
+
* limitations under the License.
*/
+#ifndef __UM_USB_SERVER_H__
+#define __UM_USB_SERVER_H__
+
#include <vconf.h>
-#include "um_main.h"
#include "um_usb_accessory_manager.h"
#include "um_usb_connection_manager.h"
#include "um_usb_host_manager.h"
+#include "um_usb_uevent_handler.h"
void um_signal_init();
int um_usb_server_init();
-Eina_Bool answer_to_ipc(void *data, Ecore_Fd_Handler *fd_handler);
+
+#endif /* __UM_USB_SERVER_H__ */
--- /dev/null
+/*
+ * usb-manager
+ * Copyright (c) 2012 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 __UM_USB_UEVENT_HANDLER_H__
+#define __UM_USB_UEVENT_HANDLER_H__
+
+#include "um_usb_host_manager.h"
+#include "um_usb_accessory_manager.h"
+
+int um_uevent_control_start(UmMainData *ad, int mode);
+void um_uevent_control_stop(UmMainData *ad);
+
+#endif /* __UM_UEVENT_HANDLER_H__ */
Name: usb-server
Summary: USB server
-Version: 0.0.11
+Version: 0.0.24
Release: 1
-Group: framework-system
-License: APLv2
+Group: framework/system
+License: Apache License, Version 2.0
Source0: usb-server-%{version}.tar.gz
Source1: usb-server.manifest
BuildRequires: gettext-devel
BuildRequires: pkgconfig(appcore-common)
BuildRequires: pkgconfig(ecore)
-BuildRequires: pkgconfig(heynoti)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(devman)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(pmapi)
BuildRequires: pkgconfig(appsvc)
BuildRequires: pkgconfig(libusb-1.0)
+BuildRequires: pkgconfig(notification)
+BuildRequires: pkgconfig(libudev)
+BuildRequires: pkgconfig(edbus)
BuildRequires: pkgconfig(capi-system-usb-accessory)
%description
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_ethernet "0" -f
-vconftool set -t int memory/usb/libusb_status "0" -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
+vconftool set -t int memory/usb/cur_mode "0" -u 0 -i -f
+vconftool set -t int db/usb/sel_mode "1" -f
+vconftool set -t int memory/usb/libusb_status "0" -u 0 -i -f
%files
/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
+/usr/bin/direct_set_debug.sh
/usr/bin/set_usb_debug.sh
+%attr(440,app,app) /usr/share/usb-server/data/usb_icon.png
<manifest>
-<define>
- <domain name="usb-server" policy="restrict" plist="com.samsung.usb-syspopup,com.samsung.setting,system-server"/>
- <provide>
- <label name="usb-server::usb-rx"/>
- <label name="usb-server::usb-r"/>
- <label name="usb-server::usb-rw"/>
- </provide>
-</define>
-<assign>
- <filesystem path="/usr/bin/start_dr.sh" label="usb-server::usb-rx"/>
- <filesystem path="/usr/bin/set_usb_debug.sh" label="usb-server::usb-rx"/>
- <filesystem path="/usr/bin/usb-server" label="usb-server::usb-rx"/>
- <filesystem path="/usr/share/usb-server/udev-rules/91-usb-server.rules" label="usb-server::usb-r"/>
- <filesystem path="/opt/share/noti/device_usb_accessory" label="usb-server::usb-rw"/>
-</assign>
-<request>
- <domain name="usb-server"/>
-</request>
+ <define>
+ <domain name="usb-server"/>
+ </define>
+ <assign>
+ <filesystem path="/usr/bin/start_dr.sh" label="usb-server"/>
+ <filesystem path="/usr/bin/set_usb_debug.sh" label="usb-server"/>
+ <filesystem path="/usr/bin/direct_set_debug.sh" label="usb-server"/>
+ <filesystem path="/usr/bin/usb-server" label="usb-server"/>
+ </assign>
+ <request>
+ <domain name="usb-server"/>
+ </request>
</manifest>
# for i18n
#SET(POFILES en_US.po en_GB.po ja.po ko.po zh_CN.po)
-SET(POFILES ar.po az.po bg.po ca.po cs.po da.po de_DE.po el_GR.po en.po en_PH.po en_US.po es_ES.po es_US.po et.po eu.po fi.po fr_CA.po fr_FR.po ga.po gl.po hi.po hr.po hu.po hy.po is.po it_IT.po ja_JP.po ka.po kk.po ko_KR.po lt.po lv.po mk.po nb.po nl_NL.po pl.po pt_BR.po pt_PT.po ro.po ru_RU.po sk.po sl.po sr.po sv.po tr_TR.po uk.po uz.po zh_CN.po zh_HK.po zh_SG.po zh_TW.po)
+SET(POFILES ar.po az.po bg.po ca.po cs.po da.po de_DE.po el_GR.po en.po en_PH.po en_US.po es_ES.po es_MX.po et.po eu.po fi.po fr_CA.po fr_FR.po ga.po gl.po hi.po hr.po hu.po hy.po is.po it_IT.po ja_JP.po ka.po kk.po ko_KR.po lt.po lv.po mk.po nb.po nl_NL.po pl.po pt_BR.po pt_PT.po ro.po ru_RU.po sk.po sl.po sr.po sv.po tr_TR.po uk.po uz.po zh_CN.po zh_HK.po zh_SG.po zh_TW.po)
SET(MSGFMT "/usr/bin/msgfmt")
FOREACH(pofile ${POFILES})
#!/bin/sh
-if [ "$1" = "--set" ]
-then
- vconftool set -t bool db/setting/debug_mode "1" -f
- echo "Debug mode is loaded"
-
-elif [ "$1" = "--unset" ]
-then
- vconftool set -t bool db/setting/debug_mode "0" -f
- echo "USB default mode is loaded"
+case "$1" in
-elif [ "$1" = "--debug" ]
-then
- vconftool set -t bool db/setting/debug_mode "1" -f
- echo "Debug mode is loaded"
+"--debug")
+ vconftool set -t int db/usb/sel_mode "2" -f
vconftool set -t int db/setting/lcd_backlight_normal "600" -f
echo "The backlight time of the display is set to 10 minutes"
vconftool set -t bool db/setting/brightness_automatic "1" -f
echo "Brightness is set automatic"
+ ;;
+
+"--default" | "--sshoff" | "--unset")
+ vconftool set -t int db/usb/sel_mode "1" -f
+ vconftool set -t bool db/setting/debug_mode "0" -f
+ ;;
-elif [ "$1" = "--sshon" ]
-then
- vconftool set -t int memory/setting/usb_sel_mode "3" -f
- vconftool set -t int db/usb/keep_ethernet "1" -f
- echo "SSH is enabled"
+"--sdb" | "--set")
+ vconftool set -t int db/usb/sel_mode "2" -f
+ vconftool set -t bool db/setting/debug_mode "1" -f
+ ;;
+
+"--sdb-diag")
+ vconftool set -t int db/usb/sel_mode "3" -f
+ vconftool set -t bool db/setting/debug_mode "1" -f
+ ;;
-elif [ "$1" = "--sshoff" ]
-then
- vconftool set -t int memory/setting/usb_sel_mode "0" -f
- vconftool set -t int db/usb/keep_ethernet "0" -f
- echo "SSH is disabled"
+"--rndis-tethering")
+ vconftool set -t int db/usb/sel_mode "4" -f
+ ;;
+"--rndis" | "--sshon")
+ vconftool set -t int db/usb/sel_mode "5" -f
+ vconftool set -t bool db/setting/debug_mode "0" -f
+ ;;
+
+"--rndis-sdb")
+ vconftool set -t int db/usb/sel_mode "6" -f
+ vconftool set -t bool db/setting/debug_mode "1" -f
+ ;;
-elif [ "$1" = "--help" ]
-then
+"--help")
echo "set_usb_debug.sh: usage:"
- echo " --help this message "
- echo " --set load Debug mode"
- echo " --unset unload Debug mode"
- echo " --debug load debug mode with 10 minutes backlight time and automatic brightness"
- echo " --sshon load SSH mode"
- echo " --sshoff unload SSH mode"
-
-else
+ echo " --help This message "
+ echo " --set Load Debug mode"
+ echo " --unset Unload Debug mode"
+ echo " --debug Load debug mode with 10 minutes backlight time"
+ echo " and automatic brightness"
+ echo " --sshon Load SSH mode"
+ echo " --sshoff Unload SSH mode"
+ echo " --default Charging mode"
+ echo " --sdb Load sdb"
+ echo " --sdb-diag Load sdb, and diag"
+ echo " If diag is not supported, charging mode is loaded"
+ echo " --rndis Load rndis only"
+ ;;
+
+*)
echo "Wrong parameters. Please use option --help to check options "
+ ;;
-fi
+esac
#include <devman.h>
#include "um_common.h"
+#define SOCK_PATH "/tmp/usb_server_sock"
+#define ACC_SOCK_PATH "/tmp/usb_acc_sock"
+
+#define USB_SYSPOPUP "usb-syspopup"
+#define SYSPOPUP_TYPE "_SYSPOPUP_TYPE"
+
+#define ACC_MANUFACTURER "_ACC_MANUFACTURER"
+#define ACC_MODEL "_ACC_MODEL"
+#define ACC_DESCRIPTION "_ACC_DESCRIPTION"
+#define ACC_VERSION "_ACC_VERSION"
+#define ACC_URI "_ACC_URI"
+#define ACC_SERIAL "_ACC_SERIAL"
+
+#define HOST_CLASS "_HOST_CLASS"
+#define HOST_SUBCLASS "_HOST_SUBCLASS"
+#define HOST_PROTOCOL "_HOST_PROTOCOL"
+#define HOST_IDVENDOR "_HOST_IDVENDOR"
+#define HOST_IDPRODUCT "_HOST_IDPRODUCT"
+
+#define LAUNCH_RETRY 10
+
int check_usbclient_connection()
{
__USB_FUNC_ENTER__ ;
return USB_HOST_DISCONNECTED;
}
-int launch_usb_syspopup(UmMainData *ad, POPUP_TYPE _popup_type)
+static int add_acc_element_to_bundle(bundle *b, void *device)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
- int ret = -1;
- char syspopup_key[SYSPOPUP_PARAM_LEN];
- char syspopup_value[ACC_ELEMENT_LEN];
+ assert(b);
+ assert(device);
- bundle *b = NULL;
- b = bundle_create();
- um_retvm_if (!b, -1, "FAIL: bundle_create()\n");
+ int ret;
+ UsbAccessory *usbAcc = (UsbAccessory *)device;
- 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");
+ if (!(usbAcc->manufacturer) || !(usbAcc->model) || !(usbAcc->description)
+ || !(usbAcc->version) || !(usbAcc->uri) || !(usbAcc->serial)) {
+ USB_LOG("ERROR: Input parameters are NULL");
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 = bundle_add(b, ACC_MANUFACTURER, usbAcc->manufacturer);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_MANUFACTURER);
+ return -1;
+ }
+ ret = bundle_add(b, ACC_MODEL, usbAcc->model);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_MODEL);
+ return -1;
+ }
+ ret = bundle_add(b, ACC_DESCRIPTION, usbAcc->description);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_DESCRIPTION);
+ return -1;
+ }
+ ret = bundle_add(b, ACC_VERSION, usbAcc->version);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_VERSION);
+ return -1;
+ }
+ ret = bundle_add(b, ACC_URI, usbAcc->uri);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_URI);
+ return -1;
}
+ ret = bundle_add(b, ACC_SERIAL, usbAcc->serial);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", ACC_SERIAL);
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+static int add_integer_to_bundle(bundle *b, char *key, int value)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(b);
+ assert(key);
+
+ int ret;
+ char str[DEVICE_ELEMENT_LEN];
- ret = syspopup_launch(USB_SYSPOPUP, b);
+ ret = snprintf(str, sizeof(str), "%d", value);
if (0 > ret) {
- USB_LOG("FAIL: syspopup_launch() returns %d\n", ret);
- if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()\n");
+ USB_LOG("FAIL: snprintf(): %d", ret);
+ return -1;
+ }
+ ret = bundle_add(b, key, str);
+ if (0 != ret) {
+ USB_LOG("FAIL: bundle_add(%s)", str);
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)
+static int add_host_element_to_bundle(bundle *b, void *device)
{
__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");
+ assert(b);
+ assert(device);
+
+ int ret;
+ UsbInterface *devIf = (UsbInterface *)device;
+
+ ret = add_integer_to_bundle(b, HOST_CLASS, devIf->ifClass);
+ if (0 > ret) {
+ USB_LOG("FAIL: add_integer_to_bundle(): %d", ret);
+ return -1;
+ }
+ ret = add_integer_to_bundle(b, HOST_SUBCLASS, devIf->ifSubClass);
+ if (0 > ret) {
+ USB_LOG("FAIL: add_integer_to_bundle(): %d", ret);
+ return -1;
+ }
+ ret = add_integer_to_bundle(b, HOST_PROTOCOL, devIf->ifProtocol);
+ if (0 > ret) {
+ USB_LOG("FAIL: add_integer_to_bundle(): %d", ret);
+ return -1;
+ }
+ ret = add_integer_to_bundle(b, HOST_IDVENDOR, devIf->ifIdVendor);
+ if (0 > ret) {
+ USB_LOG("FAIL: add_integer_to_bundle(): %d", ret);
+ return -1;
+ }
+ ret = add_integer_to_bundle(b, HOST_IDPRODUCT, devIf->ifIdProduct);
+ if (0 > ret) {
+ USB_LOG("FAIL: add_integer_to_bundle(): %d", ret);
+ return -1;
}
+
__USB_FUNC_EXIT__ ;
+ return 0;
}
-int load_system_popup_with_deviceinfo(UmMainData *ad,
- POPUP_TYPE _popup_type,
- int class,
- int subClass,
- int protocol,
- int vendor,
- int product)
+int launch_usb_syspopup(UmMainData *ad, POPUP_TYPE popupType, void *device)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
- int ret = -1;
- char syspopup_key[SYSPOPUP_PARAM_LEN];
- char syspopup_value[ACC_ELEMENT_LEN];
+ assert(ad);
+ int i;
+ int ret;
+ char type[DEVICE_ELEMENT_LEN];
bundle *b = NULL;
b = bundle_create();
- um_retvm_if (!b, -1, "FAIL: bundle_create()\n");
+ um_retvm_if (!b, -1, "FAIL: bundle_create()");
- 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);
+ snprintf(type, sizeof(type), "%d", popupType);
+ ret = bundle_add(b, SYSPOPUP_TYPE, type);
if (0 != ret) {
- USB_LOG("FAIL: bundle_add()\n");
- if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()\n");
+ USB_LOG("FAIL: bundle_add()");
+ if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()");
return -1;
}
- if (SELECT_PKG_FOR_HOST_POPUP == _popup_type) {
- if (ad->devList != NULL) {
- int i;
- char device[HOST_INFO_NUM][HOST_ELEMENT_LEN];
- snprintf(device[HOST_CLASS - HOST_CLASS], HOST_ELEMENT_LEN, "%d", class);
- snprintf(device[HOST_SUBCLASS - HOST_CLASS], HOST_ELEMENT_LEN, "%d", subClass);
- snprintf(device[HOST_PROTOCOL - HOST_CLASS], HOST_ELEMENT_LEN, "%d", protocol);
- snprintf(device[HOST_IDVENDOR - HOST_CLASS], HOST_ELEMENT_LEN, "%d", vendor);
- snprintf(device[HOST_IDPRODUCT - HOST_CLASS], HOST_ELEMENT_LEN, "%d", product);
- for (i = 0; i < HOST_INFO_NUM ; i++) {
- snprintf(syspopup_key, SYSPOPUP_PARAM_LEN, "%d", HOST_CLASS + i);
- snprintf(syspopup_value, ACC_ELEMENT_LEN, "%s", device[i]);
- 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;
- }
- }
- }
+ switch (popupType) {
+ case SELECT_PKG_FOR_ACC_POPUP:
+ ret = add_acc_element_to_bundle(b, device);
+ break;
+ case SELECT_PKG_FOR_HOST_POPUP:
+ ret = add_host_element_to_bundle(b, device);
+ break;
+ default:
+ ret = 0;
+ break;
}
-
- 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");
+ USB_LOG("FAIL: add_acc/host_element_to_bundle()");
+ if (0 != bundle_free(b)) USB_LOG("FAIL: bundle_free()");
return -1;
}
+ i = 0;
+ do {
+ ret = syspopup_launch(USB_SYSPOPUP, b);
+ if (0 <= ret) break;
+ USB_LOG("FAIL: syspopup_launch() returns %d", ret);
+ } while (i++ < LAUNCH_RETRY);
+
ret = bundle_free(b);
- um_retvm_if (0 != ret, -1, "FAIL: bundle_free()\n");
+ um_retvm_if (0 != ret, -1, "FAIL: bundle_free()");
__USB_FUNC_EXIT__ ;
return 0;
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)");
+ USB_LOG("FAIL: socket()");
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)");
+ if (bind(sockFd, (struct sockaddr *)&local, sizeof(local)) == -1) {
+ USB_LOG("FAIL: bind()");
+ close(sockFd);
+ return -1;
+ }
+ if (0 != chown(SOCK_PATH, 5000, 5000)) {
+ USB_LOG("FAIL: chown(%s, 5000, 5000)", SOCK_PATH);
+ close(sockFd);
+ return -1;
+ }
+ if (0 != chmod(SOCK_PATH, 0777)) {
+ USB_LOG("FAIL: chmod(%s, 0777)", SOCK_PATH);
close(sockFd);
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)");
close(sockFd);
return -1;
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;
+ int sockFd;
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)");
+ if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ USB_LOG("FAIL: socket()");
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)");
- close(sock_remote);
+ if (connect(sockFd, (struct sockaddr *)&remote, sizeof(remote)) == -1) {
+ USB_LOG("FAIL: connect()");
+ close(sockFd);
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;
+ return sockFd;
}
/* 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)
+int notice_to_client_app(int sockFd, int request, char *answer, int answerLen)
{
__USB_FUNC_ENTER__ ;
+ assert(answer);
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");
+ if (send (sockFd, str, strlen(str)+1, 0) == -1) {
+ USB_LOG("FAIL: send (sockFd, str, strlen(str)+1, 0)\n");
return -1;
}
- if ((t = recv(sock_remote, answer, SOCK_STR_LEN, 0)) > 0) {
- if (t < SOCK_STR_LEN) {
+ if ((t = recv(sockFd, answer, answerLen, 0)) > 0) {
+ if (t < answerLen) {
answer[t] = '\0';
- } else { /* t == SOCK_STR_LEN */
- answer[SOCK_STR_LEN-1] = '\0';
+ } else { /* t == answerLen */
+ answer[answerLen-1] = '\0';
}
- USB_LOG("[CLIENT] Received value: %s\n", answer);
+ USB_LOG("[CLIENT] Received value: %s", answer);
} else {
- USB_LOG("FAIL: recv(sock_remote, str, SOCK_STR_LEN, 0)\n");
+ USB_LOG("FAIL: recv(sockFd, str, SOCK_STR_LEN, 0)");
return -1;
}
__USB_FUNC_EXIT__ ;
if (ret < 0) {
__USB_FUNC_EXIT__ ;
return true;
- } else {
- USB_LOG("Machine name: %s", name.machine);
- if (strcasestr(name.machine, "emul")) {
- __USB_FUNC_EXIT__ ;
- return true;
- } else {
- __USB_FUNC_EXIT__ ;
- return false;
- }
}
+
+ USB_LOG("Machine name: %s", name.machine);
+ if (strcasestr(name.machine, "emul")) {
+ __USB_FUNC_EXIT__ ;
+ return true;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return false;
}
#include "um_customize.h"
+#define UNLOAD_WAIT 1000000 /* Wait for 1 sec */
+#define LAUNCH_WAIT 100000 /* Wait for 0.1 sec */
+#define LAUNCH_RETRY 10
+
+int call_cmd(char* cmd)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(cmd);
+ int ret = system(cmd);
+ USB_LOG("The result of %s is %d\n",cmd, ret);
+ __USB_FUNC_EXIT__ ;
+ return ret;
+}
+
/* If other kernel versions are added, we should modify this function */
int check_driver_version(UmMainData *ad)
{
__USB_FUNC_ENTER__ ;
+ assert(ad);
- if(!ad) return -1;
char buffer[DRIVER_VERSION_BUF_LEN];
-
- FILE *fp = NULL;
+ FILE *fp;
if (access(DRIVER_VERSION_PATH, F_OK) != 0) {
- USB_LOG("This kernel is for C210\n");
+ USB_LOG("This kernel is for version 2.6x");
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;
- }
+ __USB_FUNC_EXIT__ ;
+ return 0;
+ }
+ fp = fopen(DRIVER_VERSION_PATH, "r");
+ um_retvm_if(fp == NULL, -1, "FAIL: fopen(%s)", DRIVER_VERSION_PATH);
+
+ if (fgets(buffer, sizeof(buffer), fp) == NULL) {
+ USB_LOG("FAIL: fgets(%s)", DRIVER_VERSION_PATH);
if (fclose(fp) != 0) {
USB_LOG("FAIL: fclose(fp)\n");
- return -1;
}
+ 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 if (strncmp(buffer, DRIVER_VERSION_1_1, strlen(DRIVER_VERSION_1_1)) == 0) {
- USB_LOG("The driver version is 1.1 \n");
- ad->driverVersion = USB_DRIVER_1_1;
- } else {
- USB_LOG("This kernel version is unknown\n");
- return -1;
- }
+ if (fclose(fp) != 0) {
+ USB_LOG("FAIL: fclose(fp)");
+ return -1;
}
+
+ if (!strncmp(buffer, DRIVER_VERSION_1_0, strlen(DRIVER_VERSION_1_0))) {
+ USB_LOG("The driver version is 1.0");
+ ad->driverVersion = USB_DRIVER_1_0;
+ __USB_FUNC_EXIT__ ;
+ return 0;
+ }
+
+ if (!strncmp(buffer, DRIVER_VERSION_1_1, strlen(DRIVER_VERSION_1_1))) {
+ USB_LOG("The driver version is 1.1");
+ ad->driverVersion = USB_DRIVER_1_1;
+ __USB_FUNC_EXIT__ ;
+ return 0;
+ }
+
+ USB_LOG("This kernel version is unknown");
__USB_FUNC_EXIT__ ;
- return 0;
+ return -1;
}
-int mode_set_kernel(UmMainData *ad, int mode)
+static int write_file(const char *filepath, char *content)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
- int ret = -1;
- switch(ad->driverVersion) {
- case USB_DRIVER_0_0:
- USB_LOG("USB driver version is 0.0");
- 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("USB driver version is 1.0");
- ret = mode_set_driver_1_0(ad, mode);
- um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_1_0(mode)\n");
- break;
- case USB_DRIVER_1_1:
- USB_LOG("USB driver version is 1.1");
- ret = mode_set_driver_1_1(ad, mode);
- um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_1_1(mode)\n")
- break;
+ assert(filepath);
+ assert(content);
- /* If other kernel versions are added, add functions here that notice USB mode to the kernel */
+ FILE *fp;
+ int ret;
- default:
- USB_LOG("This version of kernel is not registered to usb-server.\n");
- __USB_FUNC_EXIT__ ;
+ fp = fopen(filepath, "w");
+ um_retvm_if(!fp, -1, "FAIL: fopen(%s)", filepath);
+
+ ret = fwrite(content, sizeof(char), strlen(content), fp);
+ if (ret < strlen(content)) {
+ USB_LOG("FAIL: fwrite(): %d", ret);
+ ret = fclose(fp);
+ if(0 != ret)
+ USB_LOG("FAIL : fclose()");
return -1;
}
+
+ ret = fclose(fp);
+ um_retvm_if(0 != ret, -1, "FAIL: result of fclose() is %d", ret);
+
__USB_FUNC_EXIT__ ;
return 0;
}
__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");
+ int ret;
+
+ switch(mode) {
+ case SET_USB_DEFAULT:
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ case SET_USB_NONE:
+ USB_LOG("Mode : SET_USB_DEFAULT mode_set_kernel");
snprintf(buf, KERNEL_SET_BUF_SIZE, "%d", KERNEL_DEFAULT_MODE);
break;
- case SETTING_USB_ETHERNET_MODE:
- USB_LOG("Mode : USB_ETHERNET_MODE mode_set_kernel\n");
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_TETHERING:
+ case SET_USB_RNDIS_SDB:
+ USB_LOG("Mode : USB_ETHERNET_MODE mode_set_kernel");
snprintf(buf, KERNEL_SET_BUF_SIZE, "%d", KERNEL_ETHERNET_MODE);
break;
- case SETTING_USB_ACCESSORY_MODE:
- USB_LOG("Mode : USB accessory is not supported in USB driver 0.0(C210)\n");
+ case SET_USB_ACCESSORY:
+ USB_LOG("Mode : USB accessory is not supported in USB driver 0.0");
return 0;
default:
- USB_LOG("ERROR : parameter is not available(mode : %d)\n", mode);
+ USB_LOG("ERROR : parameter is not available(mode : %d)", 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);
+ um_retvm_if (0 > ret, -1, "FAIL: write_file(%s)", KERNEL_SET_PATH);
__USB_FUNC_EXIT__ ;
return 0;
char *functions,
char *device_class,
char *device_subclass,
- char *device_protocol)
+ char *device_protocol,
+ char *opt_diag)
{
__USB_FUNC_ENTER__ ;
- if (vendor_id == NULL || product_id == NULL || device_class == NULL
- || functions == NULL || device_subclass == NULL || device_protocol == NULL) {
- USB_LOG("ERROR: There are parameters whose value is NULL\n");
- return -1;
- }
+ assert(vendor_id);
+ assert(product_id);
+ assert(functions);
+ assert(device_class);
+ assert(device_subclass);
+ assert(device_protocol);
+
int ret = -1;
ret = write_file(USB_MODE_ENABLE, "0");
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_PRODUCT_ID);
ret = write_file(USB_FUNCTIONS, functions);
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_FUNCTIONS);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_DEVICE_PROTOCOL);
+
+ if (opt_diag) {
+ ret = write_file(USB_DIAG_CLIENT, opt_diag);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_DIAG_CLIENT);
+ }
ret = write_file(USB_MODE_ENABLE, "1");
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_MODE_ENABLE);
__USB_FUNC_EXIT__ ;
return 0;
static int mode_set_driver_1_0(UmMainData *ad, int mode)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
- int ret = -1;
+ assert(ad);
+ int ret;
- switch(mode)
- {
- case SETTING_USB_DEFAULT_MODE:
- USB_LOG("Mode : SETTING_USB_DEFAULT_MODE mode_set_kernel\n");
+ switch(mode) {
+ case SET_USB_DEFAULT:
#ifndef SIMULATOR
- if (ad->curDebugMode) {
- ret = driver_1_0_kernel_node_set("04e8", "6860", "mtp,acm,sdb",
- "239", "2", "1");
- } else {
- ret = driver_1_0_kernel_node_set("04e8", "6860", "mtp,acm",
- "239", "2", "1");
- }
+ ret = driver_1_0_kernel_node_set("04e8", "6860",
+ "mtp,acm", "239", "2", "1", NULL);
#else
- ret = driver_1_0_kernel_node_set("04e8", "6860", "mtp,acm,sdb",
- "239", "2", "1");
+ ret = driver_1_0_kernel_node_set("04e8", "6860",
+ "mtp,acm,sdb", "239", "2", "1", NULL);
#endif
__USB_FUNC_EXIT__ ;
return ret;
- case SETTING_USB_ETHERNET_MODE:
- case SETTING_USB_TETHERING_MODE:
- USB_LOG("Mode : USB_ETHERNET or TETHERING_MODE mode_set_kernel\n");
- ret = driver_1_0_kernel_node_set("04e8", "6864", "rndis", "239", "2", "1");
+ case SET_USB_SDB:
+ ret = driver_1_0_kernel_node_set("04e8", "6860",
+ "mtp,acm,sdb", "239", "2", "1", NULL);
+ __USB_FUNC_EXIT__ ;
+ return ret;
+
+ case SET_USB_SDB_DIAG:
+ ret = driver_1_0_kernel_node_set("04e8", "6860", "mtp,acm,sdb,diag",
+ "239", "2", "1", "diag_mdm");
__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");
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_TETHERING:
+ ret = driver_1_0_kernel_node_set("04e8", "6864",
+ "rndis", "239", "2", "1", NULL);
__USB_FUNC_EXIT__ ;
return ret;
- case SETTING_USB_NONE_MODE:
- USB_LOG("Mode : USB_NONE_MODE mode_set_kernel\n");
+ case SET_USB_RNDIS_SDB:
+ ret = driver_1_0_kernel_node_set("04e8", "6864",
+ "rndis,sdb", "239", "2", "1", NULL);
+ __USB_FUNC_EXIT__ ;
+ return ret;
+
+ case SET_USB_ACCESSORY:
+ ret = driver_1_0_kernel_node_set("18d1", "2d00",
+ "accessory", "0", "0", "0", NULL);
+ __USB_FUNC_EXIT__ ;
+ return ret;
+
+ case SET_USB_NONE:
ret = write_file(USB_MODE_ENABLE, "0");
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_MODE_ENABLE);
__USB_FUNC_EXIT__ ;
return 0;
default:
- USB_LOG("ERROR : parameter is not available(mode : %d)\n", mode);
+ USB_LOG("ERROR : parameter is not available(mode : %d)", mode);
__USB_FUNC_EXIT__ ;
- return ret;
+ return -1;
}
}
char *funcs_sconf,
char *device_class,
char *device_subclass,
- char *device_protocol)
+ char *device_protocol,
+ char *opt_diag)
{
__USB_FUNC_ENTER__ ;
- if (vendor_id == NULL || product_id == NULL || funcs_fconf == NULL
- || funcs_sconf == NULL || device_class == NULL
- || device_subclass == NULL || device_protocol == NULL) {
- USB_LOG("ERROR: There are parameters whose value is NULL\n");
- return -1;
- }
- int ret = -1;
+ assert(vendor_id);
+ assert(product_id);
+ assert(funcs_fconf);
+ assert(funcs_sconf);
+ assert(device_class);
+ assert(device_subclass);
+ assert(device_protocol);
+
+ int ret;
ret = write_file(USB_MODE_ENABLE, "0");
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_PRODUCT_ID);
ret = write_file(USB_FUNCS_FCONF, funcs_fconf);
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_FUNCS_FCONF);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_FUNCS_FCONF);
ret = write_file(USB_FUNCS_SCONF, funcs_sconf);
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_FUNCS_SCONF);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_FUNCS_SCONF);
ret = write_file(USB_DEVICE_CLASS, device_class);
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_DEVICE_CLASS);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", 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);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_DEVICE_PROTOCOL);
+
+ if (opt_diag) {
+ ret = write_file(USB_DIAG_CLIENT, opt_diag);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_DIAG_CLIENT);
+ }
ret = write_file(USB_MODE_ENABLE, "1");
- um_retvm_if(EINA_FALSE == ret, -1, "FAIL: write_file(%s)\n", USB_MODE_ENABLE);
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_MODE_ENABLE);
__USB_FUNC_EXIT__ ;
return 0;
static int mode_set_driver_1_1(UmMainData *ad, int mode)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
- int ret = -1;
+ assert(ad);
+ int ret;
switch(mode)
{
- case SETTING_USB_DEFAULT_MODE:
- USB_LOG("Mode : SETTING_USB_DEFAULT mode_set_kernel\n");
+ case SET_USB_DEFAULT:
#ifndef SIMULATOR
- if (ad->curDebugMode) {
- ret = driver_1_1_kernel_node_set("04e8", "6860", "mtp", "mtp,acm,sdb",
- "239", "2", "1");
- } else {
- ret = driver_1_1_kernel_node_set("04e8", "6860", "mtp", "mtp,acm",
- "239", "2", "1");
- }
+ ret = driver_1_1_kernel_node_set("04e8", "6860",
+ "mtp", "mtp,acm", "239", "2", "1", NULL);
#else
- ret = driver_1_1_kernel_node_set("04e8", "6860", "mtp", "mtp,acm,sdb",
- "239", "2", "1");
+ ret = driver_1_1_kernel_node_set("04e8", "6860",
+ "mtp", "mtp,acm,sdb", "239", "2", "1", NULL);
#endif
__USB_FUNC_EXIT__ ;
return ret;
- case SETTING_USB_ETHERNET_MODE:
- case SETTING_USB_TETHERING_MODE:
- USB_LOG("Mode : USB_ETHERNET or TETHERING_MODE mode_set_kernel\n");
- ret = driver_1_1_kernel_node_set("04e8", "6864", "rndis", " ",
- "239", "2", "1");
+ case SET_USB_SDB:
+ ret = driver_1_1_kernel_node_set("04e8", "6860",
+ "mtp", "mtp,acm,sdb", "239", "2", "1", NULL);
__USB_FUNC_EXIT__ ;
return ret;
- case SETTING_USB_ACCESSORY_MODE:
- USB_LOG("Mode : USB_ACCESSORY_MODE mode_set_kernel\n");
- ret = driver_1_1_kernel_node_set("18d1", "2d00", "accessory", " ",
- "0", "0", "0");
+ case SET_USB_SDB_DIAG:
+ ret = driver_1_1_kernel_node_set("04e8", "6860", "mtp", "mtp,acm,sdb,diag",
+ "239", "2", "1", "diag_mdm");
__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);
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_TETHERING:
+ ret = driver_1_1_kernel_node_set("04e8", "6864",
+ "rndis", " ", "239", "2", "1", NULL);
__USB_FUNC_EXIT__ ;
return ret;
- default:
- USB_LOG("ERROR : parameter is not available(mode : %d)\n", mode);
+ case SET_USB_RNDIS_SDB:
+ ret = driver_1_1_kernel_node_set("04e8", "6864",
+ "rndis,sdb", " ", "239", "2", "1", NULL);
__USB_FUNC_EXIT__ ;
return ret;
+
+ case SET_USB_ACCESSORY:
+ ret = driver_1_1_kernel_node_set("18d1", "2d00",
+ "accessory", " ", "0", "0", "0", NULL);
+ __USB_FUNC_EXIT__ ;
+ return ret;
+
+ case SET_USB_NONE:
+ ret = write_file(USB_MODE_ENABLE, "0");
+ um_retvm_if(0 > ret, -1, "FAIL: write_file(%s)", USB_MODE_ENABLE);
+ __USB_FUNC_EXIT__ ;
+ return 0;
+
+ default:
+ USB_LOG("ERROR : parameter is not available(mode : %d)", mode);
+ __USB_FUNC_EXIT__ ;
+ return -1;
}
}
-void start_dr(UmMainData *ad)
+int mode_set_kernel(UmMainData *ad, int mode)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return ;
- call_cmd(CMD_DR_START);
- __USB_FUNC_EXIT__ ;
-}
+ assert(ad);
-static Eina_Bool write_file(const char *filepath, char *content)
-{
- __USB_FUNC_ENTER__ ;
+ int ret;
- if(!filepath || !content) return EINA_FALSE;
- FILE *fp;
- int ret = -1;
+ switch(ad->driverVersion) {
+ case USB_DRIVER_0_0:
+ USB_LOG("USB driver version is 0.0");
+ ret = mode_set_driver_0_0(mode);
+ um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_0_0(mode)");
+ break;
+ case USB_DRIVER_1_0:
+ USB_LOG("USB driver version is 1.0");
+ ret = mode_set_driver_1_0(ad, mode);
+ um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_1_0(mode)");
+ break;
+ case USB_DRIVER_1_1:
+ USB_LOG("USB driver version is 1.1");
+ ret = mode_set_driver_1_1(ad, mode);
+ um_retvm_if (0 != ret, -1, "FAIL: mode_set_driver_1_1(mode)")
+ break;
- fp = fopen(filepath, "w");
- um_retvm_if (fp == NULL, EINA_FALSE, "FAIL: fopen(%s)\n", filepath);
+ /* If other driver versions are added,
+ * add functions here that notice USB mode to the kernel */
- 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;
+ default:
+ USB_LOG("This version of driver is not registered to usb-server");
+ __USB_FUNC_EXIT__ ;
+ return -1;
}
-
- ret = fclose(fp);
- um_retvm_if (ret != 0, EINA_FALSE, "FAIL: result of fclose() is %d\n", ret);
-
__USB_FUNC_EXIT__ ;
- return EINA_TRUE;
+ return 0;
}
-static int get_device_desc_info(char *buf, char *descType, int *descValue)
+static int get_device_desc_info(char *buf, char *descType)
{
__USB_FUNC_ENTER__ ;
- if (!buf || !descType || !descValue) return -1;
- char *found = NULL;
- char *tmp = NULL;
+ assert(buf);
+ assert(descType);
+
+ char *found;
+ char *tmp;
+ int descValue;
found = strstr(buf, descType);
- if (found == NULL) {
+ if (!found) {
USB_LOG("FAIL: strnstr(%s)", descType);
return -1;
}
+
found = found + strlen(descType);
while(*found == ' ') {
found++;
}
+
tmp = strstr(found, " ");
- if (tmp != NULL) *tmp = '\0';
+ if (tmp) *tmp = '\0';
+
+ descValue = strtoul(found, &tmp, 16);
+ USB_LOG("%s: %d", descType, descValue);
- *descValue = strtoul(found, &tmp, 16);
__USB_FUNC_EXIT__ ;
- return 0;
+ return descValue;
}
-int store_default_device_info( UmMainData *ad,
- int class,
- int subClass,
- int protocol,
- int vendor,
- int product,
- int bus,
- int devAddress)
+static int store_default_device_info(UmMainData *ad, UsbInterface *devIf)
{
__USB_FUNC_ENTER__ ;
- UsbHost *device = (UsbHost *)malloc(sizeof(UsbHost));
- device->permittedAppId = NULL;
- device->deviceClass = class;
- device->deviceSubClass = subClass;
- device->deviceProtocol = protocol;
- device->idVendor = vendor;
- device->idProduct = product;
- device->bus = bus;
- device->deviceAddress = devAddress;
+ assert(ad);
+ assert(devIf);
+
+ UsbInterface *device = (UsbInterface *)malloc(sizeof(UsbInterface));
+ if (!device) {
+ USB_LOG("FAIL: malloc()");
+ return -1;
+ }
+
+ device->permAppId = NULL;
+ device->ifClass = devIf->ifClass;
+ device->ifSubClass = devIf->ifSubClass;
+ device->ifProtocol = devIf->ifProtocol;
+ device->ifIdVendor = devIf->ifIdVendor;
+ device->ifIdProduct = devIf->ifIdProduct;
+ device->ifBus = devIf->ifBus;
+ device->ifAddress = devIf->ifAddress;
+ device->ifNumber = devIf->ifNumber;
+
ad->defaultDevList = g_list_append(ad->defaultDevList, device);
+
__USB_FUNC_EXIT__ ;
return 0;
}
+static void get_device_info_from_device_desc(char *buf, UsbInterface *devIf)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(buf);
+ assert(devIf);
+
+ /* Getting Protocol */
+ devIf->ifProtocol = get_device_desc_info(buf, "Prot=");
+ if (devIf->ifProtocol < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ /* Getting SubClass */
+ devIf->ifSubClass = get_device_desc_info(buf, "Sub=");
+ if (devIf->ifSubClass < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ /* Getting Class */
+ devIf->ifClass = get_device_desc_info(buf, "Cls=");
+ if (devIf->ifClass < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ /* Getting Interface number */
+ devIf->ifNumber = get_device_desc_info(buf, "If#=");
+ if (devIf->ifNumber < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ __USB_FUNC_EXIT__ ;
+}
+
+static void get_device_info_from_product_desc(char *buf, UsbInterface *devIf)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(buf);
+ assert(devIf);
+
+ /* Getting Product ID */
+ devIf->ifIdProduct = get_device_desc_info(buf, "ProdID=");
+ if (devIf->ifIdProduct < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ /* Getting Vendor ID */
+ devIf->ifIdVendor = get_device_desc_info(buf, "Vendor=");
+ if (devIf->ifIdVendor < 0) USB_LOG("FAIL: get_device_desc_info(Vendor)");
+
+ __USB_FUNC_EXIT__ ;
+}
+
+static void get_device_info_from_topology_desc(char *buf, UsbInterface *devIf)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(buf);
+ assert(devIf);
+
+ /* Getting device number */
+ devIf->ifAddress = get_device_desc_info(buf, "Dev#=");
+ if (devIf->ifAddress < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ /* Getting bus address */
+ devIf->ifBus = get_device_desc_info(buf, "Bus=");
+ if (devIf->ifBus < 0) USB_LOG("FAIL: get_device_desc_info()");
+
+ __USB_FUNC_EXIT__ ;
+}
+
int get_default_usb_device(UmMainData *ad)
{
__USB_FUNC_ENTER__ ;
- if (!ad) return -1;
+ assert(ad);
FILE *fp;
- int ret = -1;
+ int ret;
char buf[BUF_MAX];
- bool checkIF = false;
- char *found = NULL;
- int defClass = -1;
- int defSubClass = -1;
- int defProtocol = -1;
- int defVendor = -1;
- int defProduct = -1;
- int defBus = -1;
- int defDevAddress = -1;
+ UsbInterface devIf;
ret = access("/tmp/usb_default", F_OK);
/* The file does not exist if default usb device does not exist */
um_retvm_if(ret < 0, 0, "usb_default file does not exist.");
fp = fopen("/tmp/usb_default", "r");
- um_retvm_if(fp == NULL, -1, "FAIL: fopen()");
-
- FREE(ad->defaultDevList);
+ um_retvm_if(!fp, -1, "FAIL: fopen()");
- while(fgets(buf, BUF_MAX, fp)) {
+ while(fgets(buf, sizeof(buf), fp)) {
USB_LOG("BUF: %s", buf);
- /* 'D' means device descriptor which has information of class, subclass, and protocol */
- /* 'P' also means device descriptor which has information of vendor and product */
- /* 'I' means interface descriptor which has information of class, subclass, and protocol */
- /* 'T' means Topology of devices which has information of bus number and device address */
- if (*buf == 'D' || *buf == 'I') {
- if (*buf == 'I' && checkIF == false) {
- USB_LOG("Device class is located in the device descriptor");
- continue;
- }
-
- USB_LOG("Found the information of class, subclass, and protocol");
- /* Getting Protocol */
- ret = get_device_desc_info(buf, "Prot=", &defProtocol);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(Protocol)");
-
- /* Getting SubClass */
- ret = get_device_desc_info(buf, "Sub=", &defSubClass);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(SubClass)");
-
- /* Getting Class */
- ret = get_device_desc_info(buf, "Cls=", &defClass);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(Class)");
-
- /* Deciding whether or not checking interface */
- if (*buf == 'D' && defClass <= 0) {
- USB_LOG("Device class is located in the interface decsriptor");
- checkIF = true;
- } else if (*buf == 'I' && checkIF == true) {
- USB_LOG("Device class is stored from interface descriptor");
- checkIF = false;
- }
- } else if (*buf == 'T') {
- USB_LOG("Found the information of bus number and device address");
-
- /* Getting Bus number */
- ret = get_device_desc_info(buf, "Dev#=", &defDevAddress);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(devAddress)");
+ /* 'P' means device descriptor which has information of vendor and product */
+ /* 'I' means interface descriptor which has information of class, subclass, and protocol */
+ /* 'T' means Topology of devices which has information of bus number and device address */
+ if (*buf == 'I') {
+ get_device_info_from_device_desc(buf, &devIf);
+ USB_LOG("interface number: %d, class: %d", devIf.ifNumber, devIf.ifClass);
+ USB_LOG("subclass: %d, protocol: %d", devIf.ifSubClass, devIf.ifProtocol);
- /* Getting device address */
- ret = get_device_desc_info(buf, "Bus=", &defBus);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(bus)");
+ } else if (*buf == 'T') {
+ get_device_info_from_topology_desc(buf, &devIf);
+ USB_LOG("bus: %d, devaddress: %d", devIf.ifBus, devIf.ifAddress);
+ continue;
} else if (*buf == 'P') {
- USB_LOG("Found the information of vendor and product");
- /* Getting Product ID */
- ret = get_device_desc_info(buf, "ProdID=", &defProduct);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(ProductID)");
-
- /* Getting Vendor ID */
- ret = get_device_desc_info(buf, "Vendor=", &defVendor);
- if (ret < 0) USB_LOG("FAIL: get_device_desc_info(Vendor)");
+ get_device_info_from_product_desc(buf, &devIf);
+ USB_LOG("vendor: %d, product: %d", devIf.ifIdVendor, devIf.ifIdProduct);
+ continue;
} else {
USB_LOG("Cannot find device information");
+ continue;
}
- if (defClass > 0 && defVendor >= 0) {
- ret = store_default_device_info(ad, defClass, defSubClass, defProtocol,
- defVendor, defProduct, defBus, defDevAddress);
- if (ret < 0) {
- USB_LOG("FAIL: store_default_device_info()");
- }
- defClass = -1;
- defSubClass = -1;
- defProtocol = -1;
- defVendor = -1;
- defProduct = -1;
- defBus = -1;
- defDevAddress = -1;
+ ret = store_default_device_info(ad, &devIf);
+ if (ret < 0) {
+ USB_LOG("FAIL: store_default_device_info()");
}
}
{
__USB_FUNC_ENTER__ ;
switch (class) {
+ case USB_HOST_REF_INTERFACE:
case USB_HOST_CDC:
case USB_HOST_HID:
case USB_HOST_CAMERA:
case USB_HOST_PRINTER:
case USB_HOST_MASS_STORAGE:
case USB_HOST_HUB:
+ case USB_HOST_MISCELLANEOUS:
+ case USB_HOST_VENDOR_SPECIFIC:
__USB_FUNC_EXIT__ ;
return true;
default:
}
}
-void load_connection_popup(UmMainData *ad, char *msg, int orientation)
+void load_connection_popup(char *msg)
{
__USB_FUNC_ENTER__ ;
-
- if(!ad) return ;
- if(!msg) return ;
- bundle *b = NULL;
- int ret = -1;
- int usbCurMode = -1;
- const int arrSize = 2;
- char str_orientation[arrSize];
-
- USB_LOG("msg: %s", msg);
-
- b = bundle_create();
- um_retm_if (!b, "FAIL: bundle_create()\n");
-
- /* Set tickernoti style */
- 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;
- }
-
- /* Set tickernoti text */
- ret = bundle_add(b, "1", dgettext(USB_SERVER_MESSAGE_DOMAIN, msg)); /* "1" means popup text */
- if (0 != ret) {
- USB_LOG("FAIL: bundle_add()\n");
- if ( 0 != bundle_free(b) )
- USB_LOG("FAIL: bundle_free()\n");
- return;
- }
-
- /* Set tickernoti orientation */
- snprintf(str_orientation, arrSize, "%d", orientation);
- ret = bundle_add(b, "2", str_orientation); /* "2" means orientation of tickernoti(1: bottom) */
- if (0 != ret) {
- USB_LOG("FAIL: bundle_add()\n");
- if ( 0 != bundle_free(b) )
- USB_LOG("FAIL: bundle_free()\n");
- return;
- }
-
- /* Set tickernoti timeout */
- 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);
- USB_LOG("ret: %d", ret);
- if (0 > ret) {
- USB_LOG("FAIL: syspopup_launch()\n");
- }
-
- ret = bundle_free(b);
- um_retm_if(0 != ret, "FAIL: bundle_free()\n");
-
- usleep(1000000);
-
+ assert(msg);
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+ noti_err = notification_status_message_post(gettext(msg));
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_status_message_post(msg)");
__USB_FUNC_EXIT__ ;
}
* limitations under the License.
*/
+#include <sys/file.h>
#include "um_main.h"
-#include <heynoti.h>
-static void fini(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- __USB_FUNC_EXIT__;
-}
+#define LOCK_USB_MANAGER "/tmp/lock_usb_manager"
static void usb_server_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
+ assert(ad);
um_signal_init();
appcore_set_i18n(PACKAGE, LOCALEDIR);
um_usb_server_init(ad);
ecore_init();
usb_server_init(&ad);
- if (USB_DEVICE_CLIENT == ad.isHostOrClient) {
- ad.usbAcc = (UsbAccessory*)malloc(sizeof(UsbAccessory));
- }
ecore_main_loop_begin();
- fini(&ad);
ecore_shutdown();
- FREE(ad.usbAcc);
if (USB_DEVICE_HOST == ad.isHostOrClient) {
if (USB_HOST_CONNECTED == check_usbhost_connection())
return 0;
}
+static int um_lock_usb_manager(void)
+{
+ __USB_FUNC_ENTER__ ;
+ int fd;
+ int ret;
+
+ fd = open(LOCK_USB_MANAGER, O_CREAT | O_RDWR | O_CLOEXEC, 0600);
+ if (fd == -1) {
+ USB_LOG("FAIL: open(%s)", LOCK_USB_MANAGER);
+ return -1;
+ }
+
+ ret = flock(fd, LOCK_EX | LOCK_NB);
+ if (ret == -1) {
+ USB_LOG("FAIL: flock(fd, LOCK_EX | LOCK_NB), errno: %d", errno);
+ close(fd);
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return fd;
+}
+
+static int um_unlock_usb_manager(int fd)
+{
+ __USB_FUNC_ENTER__ ;
+ int ret;
+
+ if (fd == -1) return -1;
+
+ ret = flock(fd, LOCK_UN);
+ if (ret == -1) {
+ USB_LOG("FAIL: flock(fd, LOCK_UN)");
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+
static int elm_main(int argc, char **argv)
{
__USB_FUNC_ENTER__;
- int ret = 0;
+ int ret;
+ int fd;
+
+ fd = um_lock_usb_manager();
+ if (fd == -1) {
+ USB_LOG("FAIL: um_lock_usb_manager()");
+ return -1;
+ }
+
+ if (pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0) != 0)
+ USB_LOG("FAIL: pm_lock_state(LCD_OFF, STAY_CUR_STATE)");
+
while(1) {
ret = usb_server_main(argc, argv);
if (ret == 0) break;
}
+
+ if (pm_unlock_state(LCD_OFF, STAY_CUR_STATE) != 0)
+ USB_LOG("FAIL:pm_unlock_state(LCD_OFF, STAY_CUR_STATE)");
+
+ ret = um_unlock_usb_manager(fd);
+ if (ret < 0) USB_LOG("FAIL: um_unlock_usb_manager(fd)");
+
__USB_FUNC_EXIT__;
return 0;
}
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <aul.h>
-int getAccessoryInfo(UsbAccessory *usbAcc)
+#define USB_ACCESSORY_NODE "/dev/usb_accessory"
+
+static void show_cur_accessory(UsbAccessory *acc)
{
__USB_FUNC_ENTER__;
- if (!usbAcc) return -1;
+ assert(acc);
+
+ /* Get current accessory */
+ USB_LOG("** USB Accessory Info **");
+ USB_LOG("Manufacturer: %s", acc->manufacturer);
+ USB_LOG("Model : %s", acc->model);
+ USB_LOG("Description : %s", acc->description);
+ USB_LOG("Version : %s", acc->version);
+ USB_LOG("Uri : %s", acc->uri);
+ USB_LOG("Serial : %s", acc->serial);
+ USB_LOG("************************");
+ __USB_FUNC_EXIT__;
+}
- int acc = open(USB_ACCESSORY_NODE, O_RDONLY);
+static int get_accessory_info(UsbAccessory *usbAcc)
+{
+ __USB_FUNC_ENTER__;
+ assert(usbAcc);
+ int acc;
+ char buf[DEVICE_ELEMENT_LEN];
+
+ 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);
return 0;
}
-int accessoryAttached(UmMainData *ad)
+static int accessory_attached(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- //load_system_popup(ad, SELECT_PKG_FOR_ACC_POPUP);
+ assert(ad);
+ assert(ad->usbAcc);
+ /* TODO
+ * Manifest should be used to find all related apps for usb accessory */
+ /*
+ int ret;
+
+ ret = launch_usb_syspopup(ad, SELECT_PKG_FOR_ACC_POPUP, ad->usbAcc);
+ if (0 > ret) {
+ USB_LOG("FAIL: launch_usb_syspopup(SELECT_PKG_FOR_ACC_POPUP)");
+ return -1;
+ }
+ */
+
__USB_FUNC_EXIT__;
return 0;
}
-int connectAccessory(UmMainData *ad)
+static int connect_accessory(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
- ret = getAccessoryInfo(ad->usbAcc);
+ assert(ad);
+ int ret;
+
+ ret = get_accessory_info(ad->usbAcc);
um_retvm_if(0 != ret, -1, "FAIL: getAccessoryInfo(ad->usbAcc)");
- getCurrentAccessory(ad);
+
+ show_cur_accessory(ad->usbAcc);
/* 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);
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, SET_USB_ACCESSORY);
+ um_retvm_if(0 != ret, -1, "FAIL: vconf_set_int(USB_SEL_MODE, ACCESSORY)");
+
+ ret = accessory_attached(ad);
um_retvm_if(0 > ret, -1, "FAIL: accessoryAttached(ad);");
__USB_FUNC_EXIT__;
return 0;
}
-int loadURIForAccessory(UsbAccessory *usbAcc)
+int load_uri_for_accessory(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);*/
+ assert(usbAcc);
+ /* TODO When unknown USB accessory is connected, URI should be shown */
bundle *bd = bundle_create();
um_retvm_if(NULL == bd, -1, "FAIL: bundle_create()");
appsvc_set_operation(bd, APPSVC_OPERATION_VIEW);
return 0;
}
-int grantAccessoryPermission(UmMainData *ad, char *appId)
+int grant_accessory_permission(UmMainData *ad, char *appId)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- if (!appId) return -1;
+ assert(ad);
+ assert(appId);
- if (ad->permittedPkgForAcc != NULL) {
- USB_LOG("Previous permitted pkg is removed\n");
+ FREE(ad->permAccAppId);
+
+ ad->permAccAppId = strdup(appId);
+ if (!(ad->permAccAppId)) {
+ USB_LOG("FAIL: strdup()");
+ return -1;
}
- FREE(ad->permittedPkgForAcc);
- ad->permittedPkgForAcc = strdup(appId);
- USB_LOG("Permitted pkg for accessory is %s\n", ad->permittedPkgForAcc);
+
+ USB_LOG("Permitted App id for accessory is %s", ad->permAccAppId);
__USB_FUNC_EXIT__;
return 0;
}
int launch_acc_app(char *appId)
{
__USB_FUNC_ENTER__;
- if (appId == NULL) return -1;
- bundle *b = NULL;
+ assert(appId);
+
+ bundle *b;
+ int ret;
+
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)");
+ um_retvm_if(!b, -1, "FAIL: bundle_create()");
+
+ ret = aul_launch_app(appId, b);
+ if (0 > ret) {
+ USB_LOG("FAIL: aul_launch_app(appId, b)");
+ if (0 > bundle_free(b))
+ USB_LOG("FAIL: bundle_free(b)");
+ return -1;
+ }
+
+ if (0 > bundle_free(b))
+ USB_LOG("FAIL: bundle_free(b)");
__USB_FUNC_EXIT__;
return 0;
}
-Eina_Bool hasAccPermission(UmMainData *ad, char *appId)
+bool has_accessory_permission(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))) {
+ assert(ad);
+ assert(appId);
+ if (ad->permAccAppId) {
+ if (!strncmp(ad->permAccAppId, appId, strlen(appId))) {
__USB_FUNC_EXIT__;
- return EINA_TRUE;
+ return true;
}
}
__USB_FUNC_EXIT__;
- return EINA_FALSE;
+ return false;
}
-static int usbAccessoryRelease(UmMainData *ad)
+void accessory_info_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- if (ad->usbAcc == NULL) 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);
+ assert(ad);
- __USB_FUNC_EXIT__;
- return 0;
-}
+ ad->permAccAppId = NULL;
+
+ if (!(ad->usbAcc)) return;
-void umAccInfoInit(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if (!ad) return ;
- if (ad->usbAcc == NULL) return;
ad->usbAcc->manufacturer = NULL;
ad->usbAcc->version = NULL;
ad->usbAcc->description = NULL;
ad->usbAcc->model = NULL;
ad->usbAcc->uri = NULL;
ad->usbAcc->serial = NULL;
- ad->permittedPkgForAcc = NULL;
__USB_FUNC_EXIT__;
}
-int disconnectAccessory(UmMainData *ad)
+void disconnect_accessory(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- usbAccessoryRelease(ad);
+ assert(ad);
+
+ FREE(ad->permAccAppId);
+
+ if (!(ad->usbAcc)) return;
+
+ FREE(ad->usbAcc->manufacturer);
+ FREE(ad->usbAcc->version);
+ FREE(ad->usbAcc->description);
+ FREE(ad->usbAcc->model);
+ FREE(ad->usbAcc->uri);
+ FREE(ad->usbAcc->serial);
+
__USB_FUNC_EXIT__;
- return 0;
}
-void getCurrentAccessory(UmMainData *ad)
+void um_uevent_usb_accessory_added(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");
+ assert(ad);
+
+ int status;
+ int ret;
+
+ status = check_usbclient_connection();
+ if (USB_CLIENT_CONNECTED != status)
+ return;
+
+ ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &status);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS)");
+ return;
+ }
+
+ if (VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED != status) {
+ __USB_FUNC_EXIT__;
+ return;
+ }
+
+ ret = connect_accessory(ad);
+ if (ret != 0) {
+ USB_LOG("FAIL: connect_accessory(ad)");
+ return ;
+ }
+
+ ret = vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS,
+ VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED);
+ if (ret != 0)
+ USB_LOG("FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS)");
+
__USB_FUNC_EXIT__;
}
+
#include "um_usb_connection_manager.h"
-int call_cmd(char* cmd)
+/* brad.t.peters@intel.com - todo - move away from sys-v init */
+#define SDBD_START "/etc/init.d/sdbd start"
+#define SDBD_STOP "/etc/init.d/sdbd stop"
+#define SET_USB0_IP_ETHERNET "/sbin/ifconfig usb0 192.168.129.3 up"
+#define SET_USB0_IP_TETHERING SET_USB0_IP_ETHERNET /* This IP setting can be changed */
+#define UNSET_USB0_IP "/sbin/ifconfig usb0 down"
+#define ADD_NETWORK_ID "/sbin/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"
+
+#define USB_NOTICE_SYSPOPUP_FAIL "USB system popup failed"
+
+static int run_core_action(UmMainData *ad, int mode);
+static int set_USB_mode(UmMainData *ad, int mode);
+
+static bool get_current_debug_mode(void)
{
__USB_FUNC_ENTER__ ;
- int ret = system(cmd);
- USB_LOG("The result of %s is %d\n",cmd, ret);
+
+ int ret;
+ int debugMode;
+
+ ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
+ if (ret == 0 && debugMode == 1) {
+ __USB_FUNC_EXIT__ ;
+ return true;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return false;
+}
+
+static int get_default_mode(void)
+{
+ __USB_FUNC_ENTER__ ;
+
+ if (get_current_debug_mode()) {
+ __USB_FUNC_EXIT__ ;
+ return SET_USB_SDB;
+ }
+
+ __USB_FUNC_EXIT__ ;
+ return SET_USB_DEFAULT;
+}
+
+static int check_mobile_hotspot_status(void)
+{
+ __USB_FUNC_ENTER__ ;
+
+ int mh_status;
+ int ret;
+
+ ret = vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &mh_status);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE)");
+ return -1;
+ }
+
__USB_FUNC_EXIT__ ;
- return ret;
+ return mh_status;
}
int connectUsbClient(UmMainData *ad)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return -1;
- int ret = -1;
- int mh_status = -1;
- int usbSelMode = -1;
- int keep_ethernet = -1;
+ assert(ad);
+
+ int ret;
+ int mh_status;
+ int usbSelMode;
+ bool debugMode = get_current_debug_mode();
/* 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_TETHERING_MODE);
- um_retvm_if (0 != ret, -1, "FAIL: vconf_set_int(VCONF_SETAPPL_USB_SEL_MODE_INT)\n");
+ if ((mh_status >= 0) && (mh_status & VCONFKEY_MOBILE_HOTSPOT_MODE_USB)) {
+ USB_LOG("Mobile hotspot is on");
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, SET_USB_RNDIS_TETHERING);
+ um_retvm_if (0 != ret, -1, "FAIL: vconf_set_int(VCONFKEY_USB_SEL_MODE)");
__USB_FUNC_EXIT__ ;
return 0;
- } else {
- USB_LOG("Mobile hotspot is off\n");
}
- /********************************************************************/
- /* Turn on ethernet mode if developers want to turn on the ethernet */
- ret = vconf_get_int(VCONFKEY_USB_KEEP_ETHERNET, &keep_ethernet);
- if (ret == 0 && keep_ethernet == VCONFKEY_USB_KEEP_ETHERNET_SET) {
- USB_LOG("Ethernet mode is loading");
- ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_ETHERNET_MODE);
- if (ret < 0) USB_LOG("FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT)");
- __USB_FUNC_EXIT__ ;
- return 0;
+ ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &usbSelMode);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT)");
+ usbSelMode = SET_USB_DEFAULT;
}
- /********************************************************************/
- 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;
+ switch (usbSelMode) {
+ case SET_USB_DEFAULT:
+ if (debugMode)
+ usbSelMode = SET_USB_SDB;
+ break;
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ if (!debugMode)
+ usbSelMode = SET_USB_DEFAULT;
+ break;
+ case SET_USB_RNDIS:
+ if (debugMode)
+ usbSelMode = SET_USB_RNDIS_SDB;
+ break;
+ case SET_USB_RNDIS_SDB:
+ if (!debugMode)
+ usbSelMode = SET_USB_RNDIS;
+ break;
+ case SET_USB_RNDIS_TETHERING:
+ case SET_USB_ACCESSORY:
+ default:
+ break;
}
- ret = set_USB_mode(ad, usbSelMode);
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, usbSelMode);
if (0 != ret) {
- USB_LOG("ERROR: Cannot set USB mode \n");
+ USB_LOG("FAIL: vconf_set_int()");
+ return -1;
}
+
+ change_mode_cb(NULL, ad);
+
__USB_FUNC_EXIT__ ;
return 0;
}
-int disconnectUsbClient(UmMainData *ad)
+void disconnectUsbClient(UmMainData *ad)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return -1;
- int ret = -1;
- int usbCurMode = -1;
+ assert(ad);
- 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");
+ int ret;
+ int usbCurMode;
+ int usbSelMode;
- action_clean(ad, usbCurMode);
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (ret == 0)
+ 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_USB_CUR_MODE, SET_USB_NONE);
+ if (ret != 0)
+ USB_LOG("ERROR: vconf_set_int(VCONFKEY_USB_CUR_MODE)");
+
+ ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &usbSelMode);
+ if (ret == 0) {
+ switch (usbSelMode) {
+ case SET_USB_RNDIS_TETHERING:
+ case SET_USB_ACCESSORY:
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, get_default_mode());
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ break;
+ default:
+ break;
+ }
}
- 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");
- }
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE)");
+
__USB_FUNC_EXIT__ ;
- return 0;
}
-char *get_usb_connection_msg()
+static char *get_usb_connection_msg(int mode)
{
__USB_FUNC_ENTER__ ;
- char *msg = NULL;
- int usbCurMode = -1;
- int ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode);
- um_retvm_if(0 != ret, NULL, "FAIL: vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT)");
- USB_LOG("usbCurMode: %d\n", usbCurMode);
- switch(usbCurMode) {
- case SETTING_USB_DEFAULT_MODE:
+ char *msg;
+
+ switch(mode) {
+ case SET_USB_DEFAULT:
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
msg = "IDS_COM_BODY_USB_CONNECTED";
break;
- case SETTING_USB_ETHERNET_MODE:
+
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_SDB:
msg = "SSH enabled";
break;
- case SETTING_USB_ACCESSORY_MODE:
+
+ case SET_USB_RNDIS_TETHERING:
+ return NULL;
+
+ case SET_USB_ACCESSORY:
msg = "IDS_COM_BODY_CONNECTED_TO_A_USB_ACCESSORY";
break;
+
default:
msg = USB_NOTICE_SYSPOPUP_FAIL;
break;
return strdup(msg);
}
-int usb_mode_change_done(UmMainData *ad, int done)
+#ifndef SIMULATOR
+static void update_debug_mode_status(UmMainData *ad, int selMode)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+
+ switch (selMode) {
+ case SET_USB_DEFAULT:
+ case SET_USB_RNDIS:
+ if (0 != vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 0))
+ USB_LOG("FAIL: vconf_set_bool()");
+ ad->curDebugMode = false;
+ ad->prevDebugMode = false;
+ break;
+
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ case SET_USB_RNDIS_SDB:
+ if (0 != vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, 1))
+ USB_LOG("FAIL: vconf_set_bool()");
+ ad->curDebugMode = true;
+ ad->prevDebugMode = true;
+ break;
+
+ case SET_USB_RNDIS_TETHERING:
+ case SET_USB_ACCESSORY:
+ USB_LOG("No change with debug mode");
+ break;
+
+ default:
+ USB_LOG("ERROR: selMode(%d)", selMode);
+ break;
+ }
+ __USB_FUNC_EXIT__ ;
+}
+#endif
+
+static 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;
- char *msg = NULL;
+ assert(ad);
+ int ret;
+ int usbSelMode;
+ int usbCurMode;
+ char *msg;
if (USB_CLIENT_DISCONNECTED == check_usbclient_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");
+ ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &usbSelMode);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_USB_SEL_MODE)");
+ return -1;
+ }
+
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_USB_CUR_MODE)");
+ return -1;
+ }
USB_LOG("CurMode: %d, SelMode: %d", usbCurMode, usbSelMode);
- if(ACT_SUCCESS == done) {
- vconf_ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, usbSelMode);
- um_retvm_if (0 != vconf_ret, -1, "FAIL: vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT)\n");
+ if (ACT_SUCCESS != done) { /* USB mode change failed */
+ action_clean(ad, usbSelMode);
+ ret = vconf_set_int(VCONFKEY_USB_CUR_MODE, SET_USB_NONE);
+ if (0 > ret)
+ USB_LOG("ERROR: vconf_set_int(VCONFKEY_USB_CUR_MODE)");
+ launch_usb_syspopup(ad, ERROR_POPUP, NULL);
+ return 0;
+ }
+
+ ret = vconf_set_int(VCONFKEY_USB_CUR_MODE, usbSelMode);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_set_int(VCONFKEY_USB_CUR_MODE)");
+ return -1;
+ }
+
#ifndef SIMULATOR
- ad->prevDebugMode = ad->curDebugMode;
+ update_debug_mode_status(ad, usbSelMode);
#endif
- if (SETTING_USB_TETHERING_MODE == usbSelMode) {
+ switch (usbSelMode) {
+ case SET_USB_DEFAULT:
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_DEFAULT_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_DEFAULT_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+
+ if (usbCurMode == SET_USB_DEFAULT
+ || usbCurMode == SET_USB_SDB
+ || usbCurMode == SET_USB_SDB_DIAG)
return 0;
- } else if (SETTING_USB_DEFAULT_MODE == usbSelMode
- && SETTING_USB_DEFAULT_MODE == usbCurMode) {
+ break;
+
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_SDB:
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_ETHERNET_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_ETHERNET_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+
+ if (usbCurMode == SET_USB_RNDIS
+ || usbCurMode == SET_USB_RNDIS_SDB)
return 0;
- } else {
- msg = get_usb_connection_msg();
- load_connection_popup(ad, msg, TICKERNOTI_ORIENTATION_TOP);
- FREE(msg);
- }
+ break;
- } else { /* USB mode change failed */
- action_clean(ad, usbSelMode);
- load_system_popup(ad, ERROR_POPUP);
+ case SET_USB_RNDIS_TETHERING:
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_TETHERING_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_TETHERING_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+
+ /* USB tethering does not need noti popup, thus return directly */
+ return 0;
+
+ case SET_USB_ACCESSORY:
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_ACCESSORY_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_ACCESSORY_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ break;
+
+ case SET_USB_NONE:
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, SETTING_USB_NONE_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, SETTING_USB_NONE_MODE);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
+ break;
+
+ default:
+ USB_LOG("usbSelMode is improper(%d)", usbSelMode);
+ return 0;
}
+
+ msg = get_usb_connection_msg(usbSelMode);
+ load_connection_popup(msg);
+ FREE(msg);
+
__USB_FUNC_EXIT__ ;
return 0;
}
-#ifndef SIMULATOR
-void debug_mode_cb(keynode_t* in_key, void *data)
+void change_prev_mode_cb(keynode_t* in_key, void *data)
{
__USB_FUNC_ENTER__ ;
- if(!data) return ;
+ assert(data);
+
+ UmMainData *ad = (UmMainData *)data;
+ int ret;
+ int usbSelMode;
+ int usbCurMode;
+ int mode;
+ bool debugMode = get_current_debug_mode();
+
+ if (USB_CLIENT_DISCONNECTED == check_usbclient_connection()) {
+ return ;
+ }
+
+ ret = vconf_get_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, &usbSelMode);
+ if (0 > ret) {
+ USB_LOG("ERROR: Cannot get the vconf key");
+ return;
+ }
+
+ ret = vconf_get_int(VCONFKEY_SETAPPL_USB_MODE_INT, &usbCurMode);
+ if (0 > ret) {
+ USB_LOG("ERROR: Cannot get the vconf key");
+ return;
+ }
+
+ if (usbCurMode == usbSelMode) {
+ USB_LOG("Selected mode is same as current mode");
+ return;
+ }
+
+ switch (usbSelMode) {
+ case SETTING_USB_DEFAULT_MODE:
+ if (debugMode)
+ mode = SET_USB_SDB;
+ else /* debugMode == false */
+ mode = SET_USB_DEFAULT;
+ break;
+
+ case SETTING_USB_ETHERNET_MODE:
+ if (debugMode)
+ mode = SET_USB_RNDIS_SDB;
+ else /* debugMode == false */
+ mode = SET_USB_RNDIS;
+ break;
- change_mode_cb(in_key, data);
+ case SETTING_USB_TETHERING_MODE:
+ mode = SET_USB_RNDIS_TETHERING;
+ break;
+
+ case SETTING_USB_ACCESSORY_MODE:
+ mode = SET_USB_ACCESSORY;
+ break;
+
+ default:
+ USB_LOG("FAIL: usbSelMode: %d", usbSelMode);
+ return;
+ }
+
+#ifndef SIMULATOR
+ ad->curDebugMode = debugMode;
+#endif
+
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, mode);
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_int()");
__USB_FUNC_EXIT__ ;
- return ;
}
-#endif
#ifndef SIMULATOR
-void change_mode_cb(keynode_t* in_key, void *data)
+void debug_mode_cb(keynode_t* in_key, void *data)
{
__USB_FUNC_ENTER__ ;
- if(!data) return ;
+ assert(data);
+
UmMainData *ad = (UmMainData *)data;
- int ret = -1;
- int usbSelMode = -1;
- int usbCurMode = -1;
- int debugMode = 0;
+ int ret;
+ int usbCurMode;
+ int usbSelMode;
- if (USB_CLIENT_DISCONNECTED == check_usbclient_connection()) {
+ ad->curDebugMode = get_current_debug_mode();
+ if (ad->curDebugMode == ad->prevDebugMode) {
+ USB_LOG("Debug mode is not changed");
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");
- ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
- um_retm_if (0 != ret , "ERROR: Cannot get the vconf key\n");
- USB_LOG("debugMode: %d", debugMode);
- if (debugMode == 1) ad->curDebugMode = true;
- else if (debugMode == 0) ad->curDebugMode = false;
- else {
- USB_LOG("ERROR: debugMode value is improper");
- return;
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_get_int()");
+ return ;
}
- if (usbSelMode == SETTING_USB_DEFAULT_MODE
- && usbCurMode == SETTING_USB_DEFAULT_MODE) {
- um_retm_if (ad->curDebugMode == ad->prevDebugMode, "Previous usb mode is same as the input mode");
- } else {
- um_retm_if (usbSelMode == usbCurMode, "Previous connection mode is same as the input mode");
+ switch (usbCurMode) {
+ case SET_USB_DEFAULT:
+ usbSelMode = SET_USB_SDB;
+ break;
+
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ usbSelMode = SET_USB_DEFAULT;
+ break;
+
+ case SET_USB_RNDIS:
+ usbSelMode = SET_USB_RNDIS_SDB;
+ break;
+
+ case SET_USB_RNDIS_SDB:
+ usbSelMode = SET_USB_RNDIS;
+ break;
+
+ case SET_USB_RNDIS_TETHERING:
+ case SET_USB_ACCESSORY:
+ USB_LOG("Do nothing");
+ return;
+
+ default:
+ USB_LOG("ERROR: usbCurMode: %d", usbCurMode);
+ return ;
}
- um_retm_if (usbSelMode == usbCurMode, "Previous connection mode is same as the input mode");
- ret = set_USB_mode(ad, usbSelMode);
- um_retm_if (0 != ret, "ERROR: Cannot set USB mode \n");
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, usbSelMode);
+ if (0 > ret)
+ USB_LOG("FAIL: vconf_set_int()");
__USB_FUNC_EXIT__ ;
- return ;
}
-#else
+#endif
+
void change_mode_cb(keynode_t* in_key, void *data)
{
__USB_FUNC_ENTER__ ;
- if(!data) return ;
+ assert(data);
+
UmMainData *ad = (UmMainData *)data;
- int ret = -1;
- int usbSelMode = -1;
- int usbCurMode = -1;
+ int ret;
+ int usbSelMode;
+ int usbCurMode;
if (USB_CLIENT_DISCONNECTED == check_usbclient_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");
+#ifndef SIMULATOR
+ ad->curDebugMode = get_current_debug_mode();
+#endif
+
+ ret = vconf_get_int(VCONFKEY_USB_SEL_MODE, &usbSelMode);
+ if (0 > ret) {
+ USB_LOG("ERROR: Cannot get the vconf key");
+ return ;
+ }
+
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (0 > ret) {
+ USB_LOG("ERROR: Cannot get the vconf key");
+ return;
+ }
+
+ if (usbSelMode == usbCurMode) {
+ USB_LOG("Previous connection mode is same as the input mode");
+ return ;
+ }
ret = set_USB_mode(ad, usbSelMode);
- um_retm_if (0 != ret, "ERROR: Cannot set USB mode \n");
+ if (0 != ret) {
+ USB_LOG("ERROR: Cannot set USB mode");
+ return ;
+ }
__USB_FUNC_EXIT__ ;
return ;
}
-#endif
-int set_USB_mode(UmMainData *ad, int mode)
+static 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;
+ assert(ad);
+
+ int ret;
+ int done;
+ int usbCurMode;
ret = vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, IN_MODE_CHANGE);
- if (0 != ret) {
+ 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) {
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (0 == ret && SET_USB_NONE != 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)");
+ if(0 != ret) {
+ USB_LOG("usb_mode_change_done(ad, done)");
+ return -1;
+ }
ret = vconf_set_int(VCONFKEY_SETAPPL_USB_IN_MODE_CHANGE, CHANGE_COMPLETE);
- if (0 != ret) {
+ 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;
+ int mh_status;
+ int ret;
+ int usbCurMode;
+
if (USB_CLIENT_DISCONNECTED == check_usbclient_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");
+ USB_LOG("mobile_hotspot_status: %d", mh_status);
+ if (0 > mh_status) {
+ USB_LOG("FAIL: Getting mobile hotspot status");
+ return ;
+ }
- 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");
+ ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &usbCurMode);
+ if (0 > ret) {
+ USB_LOG("FAIL: vconf_get_int(VCONFKEY_USB_CUR_MODE)");
+ return ;
+ }
if (mh_status & VCONFKEY_MOBILE_HOTSPOT_MODE_USB) {
- USB_LOG("USB Mobile hotspot is on\n");
+ USB_LOG("USB Mobile hotspot is on");
+ if (usbCurMode == SET_USB_RNDIS_TETHERING)
+ return;
- if (usbCurMode != SETTING_USB_TETHERING_MODE) {
- /* When mobile hotspot is on, this callabck function 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_TETHERING_MODE);
- 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_TETHERING_MODE) {
- ret = vconf_set_int(VCONFKEY_SETAPPL_USB_SEL_MODE_INT,
- SETTING_USB_DEFAULT_MODE);
- if (0 != ret) {
- USB_LOG("FAIL: vconf_set_int(VCONF_SETAPPL_USB_SEL_MODE_INT)\n");
- return;
- }
- }
- }
- __USB_FUNC_EXIT__ ;
-}
+ /* When mobile hotspot is on, this callabck function only sets
+ * vconf key value of USB mode. And then, the callback function
+ * for vconf change will be called */
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, SET_USB_RNDIS_TETHERING);
+ if (0 > ret)
+ USB_LOG("FAIL: vconf_set_int(VCONFKEY_USB_SEL_MODE)");
-static int check_mobile_hotspot_status()
-{
- __USB_FUNC_ENTER__ ;
+ } else {
+ USB_LOG("USB Mobile hotspot is off");
+ if (usbCurMode != SET_USB_RNDIS_TETHERING)
+ return;
- 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");
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, get_default_mode());
+ if (0 > ret)
+ USB_LOG("FAIL: vconf_set_int(VCONF_USB_SEL_MODE)");
+ }
__USB_FUNC_EXIT__ ;
- return mh_status;
}
/****************************************************/
static int run_core_action(UmMainData *ad, int mode)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return ACT_FAIL;
- int ret = -1;
+ assert(ad);
+ int ret;
+
+ ret = mode_set_kernel(ad, mode);
+ if (0 != ret) {
+ USB_LOG("FAIL : mode_set_kernel()");
+ return ACT_FAIL;
+ }
switch(mode)
{
- case SETTING_USB_DEFAULT_MODE:
- USB_LOG("Mode : SETTING_USB_DFAULT_MODE\n");
- ret = mode_set_kernel(ad, SETTING_USB_DEFAULT_MODE);
- um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n");
- start_dr(ad);
+ case SET_USB_DEFAULT:
+ USB_LOG("Mode: SET_USB_DEFAULT (%d)", mode);
+ call_cmd(CMD_DR_START);
+ break;
+
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ USB_LOG("Mode: SET_USB_SDB(_DIAG) (%d)", mode);
+ call_cmd(CMD_DR_START);
+
#ifndef SIMULATOR
- if (ad->curDebugMode) {
- USB_LOG("Current Debug mode is on");
- call_cmd(SDBD_START);
- }
+ call_cmd(SDBD_START);
#endif
+
break;
- case SETTING_USB_ETHERNET_MODE:
- USB_LOG("Mode: SETTING_USB_ETHERNET_MODE\n");
- ret = mode_set_kernel(ad, SETTING_USB_ETHERNET_MODE);
- um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n");
- call_cmd(SET_USB0_IP);
- call_cmd(ADD_DEFAULT_GW);
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_SDB:
+ USB_LOG("Mode: SET_USB_RNDIS(_DIAG) (%d)", mode);
+ call_cmd(SET_USB0_IP_ETHERNET);
+ call_cmd(ADD_NETWORK_ID);
call_cmd(OPENSSHD_START);
break;
- case SETTING_USB_TETHERING_MODE:
- USB_LOG("Mode : SETTING_USB_TETHERING_MODE\n");
- ret = mode_set_kernel(ad, SETTING_USB_TETHERING_MODE);
- um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n");
- call_cmd(SET_USB0_IP);
- call_cmd(ADD_DEFAULT_GW);
+ case SET_USB_RNDIS_TETHERING:
+ USB_LOG("Mode: SET_USB_RNDIS_TETHERING (%d)", mode);
+ call_cmd(SET_USB0_IP_TETHERING);
+ call_cmd(ADD_NETWORK_ID);
break;
- case SETTING_USB_ACCESSORY_MODE:
- USB_LOG("Mode : SETTING_USB_ACCESSORY_MODE\n");
- ret = mode_set_kernel(ad, SETTING_USB_ACCESSORY_MODE);
- um_retvm_if(0 != ret, ACT_FAIL, "FAIL : mode_set_kernel()\n");
+ case SET_USB_ACCESSORY:
+ USB_LOG("Mode: SET_USB_ACCESSORY (%d)", mode);
break;
default:
break;
}
+
__USB_FUNC_EXIT__ ;
return ACT_SUCCESS;
}
-int action_clean(UmMainData *ad, int mode)
+void action_clean(UmMainData *ad, int mode)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return -1;
- int ret = -1;
+ assert(ad);
+ int ret;
+
+ switch(mode)
+ {
+ case SET_USB_DEFAULT:
+ USB_LOG("Mode: clean SET_USB_DEFAULT (%d)", mode);
+ break;
+
+ case SET_USB_SDB:
+ case SET_USB_SDB_DIAG:
+ USB_LOG("Mode: clean SET_USB_SDB(_DIAG) (%d)", mode);
- switch(mode) {
- case SETTING_USB_DEFAULT_MODE:
- USB_LOG("Mode : SETTING_USB_DEFAULT_MODE action_clean\n");
#ifndef SIMULATOR
- if (ad->prevDebugMode) {
- USB_LOG("Previous debug mode was on");
- call_cmd(SDBD_STOP);
- }
+ call_cmd(SDBD_STOP);
#endif
+
break;
- case SETTING_USB_ETHERNET_MODE:
- USB_LOG("Mode : SETTING_USB_ETHERNET_MODE action_clean\n");
+
+ case SET_USB_RNDIS:
+ case SET_USB_RNDIS_SDB:
+ USB_LOG("Mode: clean SET_USB_RNDIS(_DIAG) (%d)", mode);
call_cmd(OPENSSHD_STOP);
call_cmd(UNSET_USB0_IP);
break;
- case SETTING_USB_TETHERING_MODE:
- USB_LOG("Mode : SETTING_USB_TETHERING_MODE action_clean\n");
+
+ case SET_USB_RNDIS_TETHERING:
+ USB_LOG("Mode: clean SET_USB_RNDIS_TETHERING (%d)", mode);
call_cmd(UNSET_USB0_IP);
break;
- case SETTING_USB_ACCESSORY_MODE:
+
+ case SET_USB_ACCESSORY:
+ USB_LOG("Mode: clean SET_USB_ACCESSORY (%d)", mode);
+ break;
+
default:
break;
}
- ret = mode_set_kernel(ad, SETTING_USB_NONE_MODE);
- um_retvm_if(0 != ret, -1, "FAIL: mode_set_kernel(SETTING_USB_NONE_MODE)");
+
+ ret = mode_set_kernel(ad, SET_USB_NONE);
+ if(0 != ret)
+ USB_LOG("FAIL: mode_set_kernel(SET_USB_NONE)");
+
__USB_FUNC_EXIT__ ;
- return 0;
}
/***********************************************/
/* Functions related to popups */
/***********************************************/
+static void response_error_popup(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ int ret;
+
+ ret = vconf_set_int(VCONFKEY_USB_SEL_MODE, get_default_mode());
+ if(0 > ret)
+ USB_LOG("ERROR: Cannot set the vconf key");
+
+ __USB_FUNC_EXIT__ ;
+}
+
void usb_connection_selected_btn(UmMainData *ad, int input)
{
__USB_FUNC_ENTER__ ;
- if(!ad) return ;
+ assert(ad);
+
if (USB_CLIENT_DISCONNECTED == check_usbclient_connection()) {
return;
}
switch (input) {
case ERROR_POPUP_OK_BTN:
- USB_LOG("The button on the error popup is selected\n");
+ USB_LOG("The button on the error popup is selected");
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_DEFAULT_MODE);
- um_retvm_if(0 != ret, -1, "ERROR: Cannot set the vconf key\n");
-
- __USB_FUNC_EXIT__ ;
- return 0;
-}
* limitations under the License.
*/
+#define _GNU_SOURCE
+#include <string.h>
+
#include <vconf.h>
#include <dirent.h>
+#include <aul.h>
+#include <ctype.h>
#include "um_usb_host_manager.h"
-int tmpfs_mounted = 0;
-int added_noti_value = 0;
-int removed_noti_value = 0;
+#define TIMER_WAIT 0.5 /* Wait for 0.5 sec */
+#define FS_TMPFS "tmpfs"
+
+#define USBOTG_SYSPOPUP "usbotg-syspopup"
+#define STORAGE_ADD "storage_add"
+#define STORAGE_REMOVE "storage_remove"
+#define CAMERA_ADD "camera_add"
+#define CAMERA_REMOVE "camera_remove"
+
+#define DEV_STR_UNSUPPORTED "Unsupported Device"
+#define DEV_STR_PRINTER "Printer"
+#define DEV_STR_KEYBOARD "Keyboard"
+#define DEV_STR_MOUSE "Mouse"
+#define DEV_STR_CAMERA "Camera"
+
+#define VENDOR_HP_1 "Hewlett-Packard"
+#define VENDOR_HP_2 "Hewlett Packard"
+#define VENDOR_HP_3 "HP"
+
+static int um_usb_storage_added(UmMainData *ad, char *devpath, char *devname, char *fstype);
+static int um_usb_storage_removed(UmMainData *ad, char *devname);
+static int um_connect_known_device(UmMainData *ad, UsbInterface *device);
+static void um_disconnect_usb_device_mass_storage(UmMainData *ad, char *devname);
+static int um_disconnect_usb_device(UmMainData *ad, UsbInterface *device);
+static int um_connect_unknown_device(UmMainData *ad, UsbInterface *device);
+
+static void free_dev_list(gpointer data)
+{
+ __USB_FUNC_ENTER__;
+ assert(data);
+ UsbInterface *devIf = (UsbInterface *)data;
+ FREE(devIf->permAppId);
+ FREE(devIf->ifIProduct);
+ FREE(devIf->ifIManufacturer);
+ __USB_FUNC_EXIT__;
+}
-void free_func(gpointer data)
+static void free_ms_list(gpointer data)
{
__USB_FUNC_ENTER__;
- UsbHost *device = (UsbHost *)data;
- FREE(device->permittedAppId);
+ assert(data);
+ MSDevName *msDevice = (MSDevName *)data;
+ FREE(msDevice->devName);
__USB_FUNC_EXIT__;
}
-int retrieve_device_info(libusb_device *device,
- int *deviceClass,
- int *deviceSubClass,
- int *deviceProtocol,
- int *idVendor,
- int *idProduct,
- int *bus,
- int *devAddress)
+void show_all_usb_devices(GList *devList)
{
__USB_FUNC_ENTER__;
- if (device == NULL) return -1;
- struct libusb_device_descriptor desc;
- int ret = -1;
- libusb_device_handle *handle = NULL;
- ret = libusb_get_device_descriptor(device, &desc);
+
+ UsbInterface *devIf;
+ GList *l;
+
+ USB_LOG("***********************************");
+ USB_LOG("** USB devices list ");
+ USB_LOG("** ");
+
+ for (l = devList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+ USB_LOG("** Permitted app : %s", devIf->permAppId);
+ USB_LOG("** Device Bus: %u", devIf->ifBus);
+ USB_LOG("** Device Address: %u", devIf->ifAddress);
+ USB_LOG("** Interface number : %u", devIf->ifNumber);
+ USB_LOG("** Interface Class : %u", devIf->ifClass);
+ USB_LOG("** Interface Subclass : %u", devIf->ifSubClass);
+ USB_LOG("** Interface Protocol : %u", devIf->ifProtocol);
+ USB_LOG("** Interface Vendor ID : %u", devIf->ifIdVendor);
+ USB_LOG("** Interface Product ID: %u", devIf->ifIdProduct);
+ USB_LOG("*************************************** ");
+ }
+
+ __USB_FUNC_EXIT__;
+}
+
+static int get_ifs_from_device(libusb_device *device, GList **ifList)
+{
+ __USB_FUNC_ENTER__;
+ assert(device);
+ assert(ifList);
+
+ int i;
+ int ret;
+ int numIf;
+ struct libusb_config_descriptor *config = NULL;
+ const struct libusb_interface_descriptor *descIf;
+ UsbInterface *devIf;
+
+ ret = libusb_get_active_config_descriptor(device, &config);
if (ret != 0) {
- USB_LOG("FAIL: libusb_get_device_descriptor()\n");
+ USB_LOG("FAIL: libusb_get_active_config_descriptor()");
+ libusb_free_config_descriptor(config);
return -1;
}
- /* If device class of device descriptor is 0,
- * the real device class information would be located in the interface descriptor */
- if (0 == desc.bDeviceClass) {
- struct libusb_config_descriptor *config = NULL;
- ret = libusb_get_active_config_descriptor(device, &config);
- if (ret != 0) {
- USB_LOG("FAIL: libusb_get_active_config_descriptor(device, &config)");
+ numIf = config->bNumInterfaces;
+ USB_LOG("number of interfaces: %d", numIf);
+
+ for (i = 0 ; i < numIf ; i++) {
+ descIf = &(config->interface[i].altsetting[0]);
+ devIf = (UsbInterface *)malloc(sizeof(UsbInterface));
+ if (!devIf) {
+ USB_LOG("FAIL: malloc()");
libusb_free_config_descriptor(config);
- return -1;
+ g_list_free(*ifList);
}
- *deviceClass = config->interface->altsetting[0].bInterfaceClass;
- *deviceSubClass = config->interface->altsetting[0].bInterfaceSubClass;
- *deviceProtocol = config->interface->altsetting[0].bInterfaceProtocol;
- libusb_free_config_descriptor(config);
- } else {
- *deviceClass = desc.bDeviceClass;
- *deviceSubClass = desc.bDeviceSubClass;
- *deviceProtocol = desc.bDeviceProtocol;
+
+ devIf->ifClass = descIf->bInterfaceClass;
+ devIf->ifSubClass = descIf->bInterfaceSubClass;
+ devIf->ifProtocol = descIf->bInterfaceProtocol;
+ devIf->ifNumber = descIf->bInterfaceNumber;
+
+ *ifList = g_list_append(*ifList, devIf);
}
- *idVendor = desc.idVendor;
- *idProduct = desc.idProduct;
- *bus = libusb_get_bus_number(device);
- *devAddress = libusb_get_device_address(device);
+ libusb_free_config_descriptor(config);
__USB_FUNC_EXIT__;
return 0;
}
-int umReleaseAllDevice(UmMainData *ad)
+static int get_device_i_manufacturer_product(libusb_device *device,
+ char **manufacturer,
+ char **product)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- if (ad->devList) {
- int cnt = g_list_length(ad->devList);
- int i;
- int ret;
- for ( i = cnt-1 ; i >= 0 ; i--) {
- ret = um_disconnect_usb_device(ad,
- ((UsbHost *)(g_list_nth_data(ad->devList, i)))->deviceClass);
- if (ret < 0) USB_LOG("FAIL: um_disconnect_usb_device()");
- ad->devList = g_list_delete_link(ad->devList, g_list_nth(ad->devList, i));
- }
+ assert(device);
+ assert(manufacturer);
+ assert(product);
- if (ad->devList) {
- g_list_free_full(ad->devList, free_func);
- ad->devList = NULL;
- }
+ int ret = -1;
+ libusb_device_handle *handle = NULL;
+ struct libusb_device_descriptor desc;
+ unsigned char devIProduct[BUF_MAX];
+ unsigned char devIManufacturer[BUF_MAX];
+
+ ret = libusb_get_device_descriptor(device, &desc);
+ if (ret != 0) {
+ USB_LOG("FAIL: libusb_get_device_descriptor()");
+ return -1;
}
- load_connection_popup(ad, "IDS_COM_POP_USB_CONNECTOR_DISCONNECTED", TICKERNOTI_ORIENTATION_TOP);
+
+ ret = libusb_open(device, &handle);
+ if (ret != 0) {
+ USB_LOG("FAIL: libusb_open()");
+ return -1;
+ }
+
+ ret = libusb_get_string_descriptor_ascii(handle,
+ desc.iProduct,
+ devIProduct,
+ sizeof(devIProduct));
+ if (ret < 0) {
+ USB_LOG("FAIL: libusb_get_string_descriptor_ascii(): %d", ret);
+ libusb_close(handle);
+ return -1;
+ }
+
+ ret = libusb_get_string_descriptor_ascii(handle,
+ desc.iManufacturer,
+ devIManufacturer,
+ sizeof(devIManufacturer));
+ if (ret < 0) {
+ USB_LOG("FAIL: libusb_get_string_descriptor_ascii(): %d", ret);
+ libusb_close(handle);
+ return -1;
+ }
+
+ libusb_close(handle);
+ USB_LOG("iManufacturer: %s, iProduct: %s", devIManufacturer, devIProduct);
+ *manufacturer = strdup((const char *)devIManufacturer);
+ *product = strdup((const char *)devIProduct);
__USB_FUNC_EXIT__;
return 0;
}
-int compareTwoDevices(libusb_device *usbDevice, UsbHost *listedDevice)
+static int retrieve_interface_info(libusb_device *device, GList **ifList)
{
__USB_FUNC_ENTER__;
- if (usbDevice == NULL || listedDevice == NULL) return -1;
- int ret = -1;
- int deviceClass;
- int deviceSubClass;
- int deviceProtocol;
- int idVendor;
- int idProduct;
- int bus;
- int devAddress;
- ret = retrieve_device_info(usbDevice,
- &deviceClass,
- &deviceSubClass,
- &deviceProtocol,
- &idVendor,
- &idProduct,
- &bus,
- &devAddress);
+ assert(device);
+ assert(ifList);
+
+ struct libusb_device_descriptor desc;
+ GList *l;
+ int ret;
+ UsbInterface *devIf;
+
+ ret = libusb_get_device_descriptor(device, &desc);
+ if (ret != 0) {
+ USB_LOG("FAIL: libusb_get_device_descriptor()");
+ return -1;
+ }
+
+ ret = get_ifs_from_device(device, ifList);
if (ret < 0) {
- USB_LOG("FAIL: retrieve_device_info()\n");
+ USB_LOG("FAIL: get_ifs_from_device()");
return -1;
}
- if (listedDevice->deviceClass == deviceClass
- && listedDevice->deviceSubClass == deviceSubClass
- && listedDevice->deviceProtocol == deviceProtocol
- && listedDevice->idVendor == idVendor
- && listedDevice->idProduct == idProduct
- && listedDevice->bus == bus
- && listedDevice->deviceAddress == devAddress)
- {
- USB_LOG("Two devices are same\n");
- __USB_FUNC_EXIT__;
- return 0;
- } else {
- USB_LOG("Two devices are different\n");
- __USB_FUNC_EXIT__;
- return 1;
+
+ for (l = *ifList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+ devIf->ifIdVendor = desc.idVendor;
+ devIf->ifIdProduct = desc.idProduct;
+ devIf->ifBus = libusb_get_bus_number(device);
+ devIf->ifAddress = libusb_get_device_address(device);
+ devIf->permAppId = NULL;
+
+ ret = get_device_i_manufacturer_product(device,
+ &(devIf->ifIManufacturer),
+ &(devIf->ifIProduct));
+ if (0 > ret) {
+ USB_LOG("FAIL: get_device_i_manufacturer_product");
+ devIf->ifIManufacturer = NULL;
+ devIf->ifIProduct = NULL;
+ }
}
+
+ __USB_FUNC_EXIT__;
+ return 0;
}
-bool is_device_driver_active(libusb_device *device, int devClass)
+static void um_release_all_device(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!device) return false;
+ assert(ad);
+
int ret = -1;
- bool result;
- libusb_device_handle *handle;
+ UsbInterface *dev = NULL;
+ MSDevName *msDev = NULL;
+ GList *l = NULL;
- switch (devClass) {
- case USB_HOST_CAMERA:
- /* Camera is supported by libgphpoto2, not by kernel
- * The directory is made When camera is connected, and removed when camera is removed */
- if (0 == access("/tmp/camera", F_OK)) {
- result = true;
- } else {
- result = false;
+ if (ad->devList) {
+ for (l = ad->devList ; l ; l = g_list_next(l)) {
+ dev = (UsbInterface *)(l->data);
+ ret = um_disconnect_usb_device(ad, dev);
+ if (ret < 0)
+ USB_LOG("FAIL: um_disconnect_usb_device()");
+ }
+
+ g_list_free_full(ad->devList, free_dev_list);
+ ad->devList = NULL;
+ }
+
+ if (ad->devMSList) {
+ for (l = ad->devMSList ; l ; l = g_list_next(l)) {
+ msDev = (MSDevName *)(l->data);
+ um_disconnect_usb_device_mass_storage(ad, msDev->devName);
}
+
+ g_list_free_full(ad->devMSList, free_ms_list);
+ ad->devMSList = NULL;
+ }
+
+ ret = um_remove_all_host_notification(ad);
+ if (ret < 0) USB_LOG("FAIL: um_remove_all_host_notification(ad)");
+
+ if (ad->addHostTimer) {
+ ecore_timer_del(ad->addHostTimer);
+ ad->addHostTimer = NULL;
+ }
+
+ if (ad->rmHostTimer) {
+ ecore_timer_del(ad->rmHostTimer);
+ ad->rmHostTimer = NULL;
+ }
+
+ load_connection_popup("IDS_COM_POP_USB_CONNECTOR_DISCONNECTED");
+
+ __USB_FUNC_EXIT__;
+}
+
+static bool find_same_device_interface(UsbInterface *dev1, UsbInterface *dev2)
+{
+ __USB_FUNC_ENTER__;
+ assert(dev1);
+ assert(dev2);
+
+ if (dev1->ifBus != dev2->ifBus)
+ return false;
+ if (dev1->ifAddress != dev2->ifAddress)
+ return false;
+ if (dev1->ifClass != dev2->ifClass)
+ return false;
+ if (dev1->ifSubClass != dev2->ifSubClass)
+ return false;
+ if (dev1->ifProtocol != dev2->ifProtocol)
+ return false;
+ if (dev1->ifIdVendor != dev2->ifIdVendor)
+ return false;
+ if (dev1->ifIdProduct != dev2->ifIdProduct)
+ return false;
+
+ __USB_FUNC_EXIT__;
+ return true;
+}
+
+static int check_device_in_device_list(GList *devList, GList *ifList, bool *found)
+{
+ __USB_FUNC_ENTER__;
+ assert(found);
+ assert(ifList);
+
+ bool local;
+ GList *l;
+ UsbInterface *devIf;
+ UsbInterface *tmpIf;
+
+ if (!devList) {
+ USB_LOG("Device list is empty");
+ return 0;
+ }
+
+ local = false;
+ devIf = (UsbInterface *)(ifList->data);
+ for (l = devList ; l ; l = g_list_next(l)) {
+ /* If two device have same bus and address,
+ * these devices are same device */
+ tmpIf = (UsbInterface *)(l->data);
+ if (!find_same_device_interface(devIf, tmpIf))
+ continue;
+
+ USB_LOG("Device is found at device list");
+ local = true;
break;
- case USB_HOST_CDC:
- case USB_HOST_HID:
- case USB_HOST_PRINTER:
- case USB_HOST_MASS_STORAGE:
- case USB_HOST_HUB:
- ret = libusb_open(device, &handle);
- if (ret != 0) {
- USB_LOG("FAIL: libusb_open()");
- return false;
+ }
+
+ *found = local;
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_add_device_popup_noti(UmMainData *ad,
+ UsbInterface *devIf,
+ bool isSupported)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(devIf);
+
+ int ret;
+ int i;
+ GList *l;
+ UsbInterface *tmpIf;
+
+ /* Mounting Mass storage takes time,
+ * so the next procedure is proceeded in the add_mass_storage_cb() */
+ if (devIf->ifClass == USB_HOST_MASS_STORAGE)
+ return 0;
+
+ /* TODO If scanner and fax are supported by kernel,
+ * These codes should be modified */
+ /* If A Usb device has more than two printer interfaces,
+ * only the first popup is displayed */
+ i = 0;
+ if (devIf->ifClass == USB_HOST_PRINTER) {
+ for (l = ad->devList ; l ; l = g_list_next(l)) {
+ tmpIf = (UsbInterface *)(l->data);
+ if (tmpIf->ifClass != USB_HOST_PRINTER)
+ continue;
+ if (devIf->ifBus != tmpIf->ifBus)
+ continue;
+ if (devIf->ifAddress != tmpIf->ifAddress)
+ continue;
+
+ i++;
+ if (i > 1) {
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
}
+ }
- /* We can check the usb device is available by checking if kernel driver is actice or not */
- ret = libusb_kernel_driver_active(handle, 0);
- if (ret == 1) {
- USB_LOG("Device driver is active");
- result = true;
- } else if (ret == 0) {
- USB_LOG("No device driver is active");
- result = false;
- } else {
- USB_LOG("FAIL: libusb_kernel_driver_active()");
- result = false;
+ if (true == isSupported) {
+ ret = um_connect_known_device(ad, devIf);
+ if (ret < 0) USB_LOG("FAIL: um_connect_known_device()");
+ } else { /* false == isSupported */
+ USB_LOG("The device is not supported");
+ ret = um_connect_unknown_device(ad, devIf);
+ if (ret < 0) USB_LOG("FAIL: um_connect_unknown_device()");
+ }
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_add_device_to_list(UmMainData *ad, GList *ifList)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(ifList);
+
+ int ret;
+ bool isSupported;
+ GList *l;
+ UsbInterface *devIf;
+
+ for (l = ifList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+
+ isSupported = is_device_supported(devIf->ifClass);
+ ad->devList = g_list_append(ad->devList, devIf);
+
+ ret = um_add_device_popup_noti(ad, devIf, isSupported);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_add_device_popup_noti()");
+ return -1;
}
- libusb_close(handle);
- break;
- default:
- USB_LOG("The device(class: %d) is not supported by kernel", devClass);
- result = false;
- break;
}
+
__USB_FUNC_EXIT__;
- return result;
+ return 0;
}
-int add_usb_device_to_list(UmMainData *ad)
+static Eina_Bool um_add_usb_host_device(void *data)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
- int i, j;
- int deviceClass;
- int deviceSubClass;
- int deviceProtocol;
- int idVendor;
- int idProduct;
- int bus;
- int devAddress;
+ assert(data);
+ UmMainData *ad = (UmMainData *)data;
+ if (ad->addHostTimer) {
+ ecore_timer_del(ad->addHostTimer);
+ ad->addHostTimer = NULL;
+ }
+
+ int ret;
+ int i;
bool found = false;
libusb_device **list = NULL;
+ GList *ifList;
+
pm_change_state(LCD_NORMAL);
+ show_all_usb_devices(ad->devList);
+
ssize_t cnt = libusb_get_device_list(ad->usbctx, &list);
+ USB_LOG("The number of USB device: %d", cnt);
+ /* Check all of connected USB devices
+ * and find which device is newly connected */
for (i = 0 ; i < cnt ; i++) {
- ret = retrieve_device_info(list[i],
- &deviceClass,
- &deviceSubClass,
- &deviceProtocol,
- &idVendor,
- &idProduct,
- &bus,
- &devAddress);
+ ifList = NULL;
+ ret = retrieve_interface_info(list[i], &ifList);
if (ret < 0) {
- USB_LOG("FAIL: retrieve_device_info()\n");
- libusb_free_device_list(list, 1);
+ USB_LOG("FAIL: retrieve_interface_info()");
return -1;
}
- USB_LOG("Device class: %d", deviceClass);
-
- /* Check default device list */
- if (ad->defaultDevList) {
- for (j = 0 ; j < g_list_length(ad->defaultDevList) ; j++) {
- if (0 == compareTwoDevices(list[i],
- ((UsbHost *)(g_list_nth_data(ad->defaultDevList, j))))) {
- found = true;
- break;
- }
- }
- if (found == true) USB_LOG("Device is found at default device list");
+
+ found = false;
+ /* Check default device list whether or not the device exists */
+ ret = check_device_in_device_list(ad->defaultDevList, ifList, &found);
+ if (ret < 0) {
+ USB_LOG("FAIL: check_device_in_device_list()");
+ libusb_free_device_list(list, 1);
+ return EINA_FALSE;
}
- /* Check device list */
- if (found == false && ad->devList) {
- for (j = 0 ; j < g_list_length(ad->devList) ; j++) {
- if (0 == compareTwoDevices(list[i],
- ((UsbHost *)(g_list_nth_data(ad->devList, j))))) {
- found = true;
- break;
- }
- }
- if (found == true) USB_LOG("Device is found at device list");
+ if (found)
+ continue;
+
+ /* Check device list whether or not the device exists */
+ ret = check_device_in_device_list(ad->devList, ifList, &found);
+ if (ret < 0) {
+ USB_LOG("FAIL: check_device_in_device_list()");
+ libusb_free_device_list(list, 1);
+ return EINA_FALSE;
+ }
+
+ if (found)
+ continue;
+
+ /* 'found == false' means that the device is newly connected
+ * because the device cannot find in the list of devices
+ * which are previously connected */
+ ret = um_add_device_to_list(ad, ifList);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_add_device_to_list()");
+ libusb_free_device_list(list, 1);
+ return EINA_FALSE;
+ }
+
+ show_all_usb_devices(ad->devList);
+ }
+ libusb_free_device_list(list, 1);
+
+ show_all_usb_devices(ad->devList);
+
+ __USB_FUNC_EXIT__;
+ return EINA_TRUE;
+}
+
+static int check_and_remove_usb_device(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(ad->devList);
+ int j;
+ int ret;
+ ssize_t cnt;
+ bool found;
+ GList *l;
+ GList *tmpl;
+ UsbInterface *devIf;
+ libusb_device **list = NULL;
+ int devAddr;
+ int devBus;
+
+ cnt = libusb_get_device_list(ad->usbctx, &list);
+ if (list == NULL) {
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+
+ USB_LOG("g_list_length(ad->devList): %d, libusb: %d", g_list_length(ad->devList), cnt);
+ for (l = g_list_last(ad->devList) ; l ;) {
+ found = false;
+ for (j = 0 ; j < cnt ; j++) { /* current device list */
+ devIf = (UsbInterface *)(l->data);
+ devBus = libusb_get_bus_number(list[j]);
+ devAddr = libusb_get_device_address(list[j]);
+
+ if (devIf->ifBus != devBus)
+ continue;
+ if (devIf->ifAddress != devAddr)
+ continue;
+
+ found = true;
+ break;
+ }
+
+ tmpl = l;
+ l = g_list_previous(l);
+ if (found)
+ continue;
+
+ /* Cannot find the device in connected device list
+ * Thus, the device is removed*/
+ USB_LOG("found == FALSE");
+ ret = um_disconnect_usb_device(ad, (UsbInterface *)(tmpl->data));
+ if (ret < 0) {
+ USB_LOG("FAIL: um_disconnect_usb_device()");
+ }
+ ad->devList = g_list_delete_link(ad->devList, tmpl);
+ }
+
+ libusb_free_device_list(list, 1);
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static Eina_Bool um_remove_usb_host_device(void *data)
+{
+ __USB_FUNC_ENTER__;
+ assert(data);
+ UmMainData *ad = (UmMainData *)data;
+ int ret;
+
+ if (ad->rmHostTimer) {
+ ecore_timer_del(ad->rmHostTimer);
+ ad->rmHostTimer = NULL;
+ }
+ if (!(ad->devList))
+ return EINA_TRUE;
+
+ show_all_usb_devices(ad->devList);
+
+ pm_change_state(LCD_NORMAL);
+
+ ret = check_and_remove_usb_device(ad);
+ if (ret < 0) {
+ USB_LOG("FAIL: check_removed_usb_device()");
+ }
+
+ show_all_usb_devices(ad->devList);
+
+ __USB_FUNC_EXIT__;
+ return EINA_TRUE;
+}
+
+/* TODO Support unknown USB host devices */
+int grant_host_permission(UmMainData *ad, char *appId, int vendor, int product)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(appId);
+
+ UsbInterface *devIf;
+ GList *l;
+
+ for (l = ad->devList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+
+ if (devIf->ifIdVendor != vendor)
+ continue;
+ if (devIf->ifIdProduct != product)
+ continue;
+
+ FREE(devIf->permAppId);
+ devIf->permAppId = strdup(appId);
+ if (!(devIf->permAppId)) {
+ USB_LOG("FAIL: strdup()");
+ }
+ }
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+/* TODO Support unknown USB host devices */
+int launch_host_app(char *appId)
+{
+ __USB_FUNC_ENTER__;
+ assert(appId);
+
+ bundle *b;
+ int ret;
+
+ b = bundle_create();
+ um_retvm_if (!b, -1, "FAIL: bundle_create()");
+
+ 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;
+}
+
+/* TODO Support unknown USB host devices */
+Eina_Bool has_host_permission(UmMainData *ad, char *appId, int vendor, int product)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(appId);
+ UsbInterface *devIf = NULL;
+ GList *l = NULL;
+ for (l = ad->devList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+
+ if (devIf->ifIdVendor != vendor)
+ continue;
+ if (devIf->ifIdProduct != product)
+ continue;
+
+ if (!strncmp(devIf->permAppId, appId, strlen(appId))) {
+ __USB_FUNC_EXIT__;
+ return EINA_TRUE;
+ }
+ }
+
+ __USB_FUNC_EXIT__;
+ return EINA_FALSE;
+}
+
+Eina_Bool is_host_connected(UmMainData *ad, int vendor, int product)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+
+ UsbInterface *devIf;
+ GList *l;
+
+ for (l = ad->devList ; l ; l = g_list_next(l)) {
+ devIf = (UsbInterface *)(l->data);
+ if (devIf->ifIdVendor != vendor)
+ continue;
+ if (devIf->ifIdProduct != product )
+ continue;
+
+ __USB_FUNC_EXIT__;
+ return EINA_TRUE;
+ }
+
+ __USB_FUNC_EXIT__;
+ return EINA_FALSE;
+}
+
+void um_uevent_usb_host_added(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ Eina_Bool ret_bool;
+
+ if (ad->addHostTimer) {
+ ecore_timer_reset(ad->addHostTimer);
+ __USB_FUNC_EXIT__;
+ return ;
+ }
+
+ ad->addHostTimer = ecore_timer_add(TIMER_WAIT, um_add_usb_host_device, ad);
+ if (!(ad->addHostTimer)) {
+ USB_LOG("FAIL: ecore_timer_add()");
+ ret_bool = um_add_usb_host_device(ad);
+ if (ret_bool == EINA_FALSE)
+ USB_LOG("um_add_usb_host_device()");
+ }
+
+ __USB_FUNC_EXIT__;
+}
+
+void um_uevent_usb_host_removed(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ Eina_Bool ret_bool;
+
+ if (ad->rmHostTimer) {
+ ecore_timer_reset(ad->rmHostTimer);
+ __USB_FUNC_EXIT__;
+ return;
+ }
+
+ ad->rmHostTimer = ecore_timer_add(TIMER_WAIT, um_remove_usb_host_device, ad);
+ if (!(ad->rmHostTimer)) {
+ USB_LOG("FAIL: ecore_timer_add()");
+ ret_bool = um_remove_usb_host_device(ad);
+ if (ret_bool == EINA_FALSE)
+ USB_LOG("um_remove_usb_host_device()");
+ }
+
+ __USB_FUNC_EXIT__;
+}
+
+static void um_load_usbotg_popup(char *popupname, char *popuptype, char *devname)
+{
+ __USB_FUNC_ENTER__;
+ assert(popupname);
+ assert(popuptype);
+
+ bundle *b;
+ int ret;
+
+ b = bundle_create();
+ if (!b) {
+ USB_LOG("FAIL: bundle_create()");
+ return;
+ }
+
+ ret = bundle_add(b, "POPUP_TYPE", popuptype);
+ if (ret < 0) {
+ USB_LOG("FAIL: bundle_add()");
+ bundle_free(b);
+ return;
+ }
+
+ if (devname) {
+ ret = bundle_add(b, "DEVICE_PATH", devname);
+ if (ret < 0) {
+ USB_LOG("FAIL: bundle_add()");
+ bundle_free(b);
+ return ;
}
+ }
+
+ if (syspopup_launch(popupname, b) < 0) {
+ USB_LOG("FAIL: syspopup_launch()");
+ }
+
+ bundle_free(b);
+
+ __USB_FUNC_EXIT__;
+}
+
+static void camera_added_popup()
+{
+ __USB_FUNC_ENTER__;
+
+ um_load_usbotg_popup(USBOTG_SYSPOPUP, CAMERA_ADD, NULL);
+
+ __USB_FUNC_EXIT__ ;
+}
+
+bool is_mass_storage_mounted(UmMainData *ad, char *devname)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(devname);
- if (found == false) {
- UsbHost *device = (UsbHost *)malloc(sizeof(UsbHost));
- device->permittedAppId = NULL;
- device->deviceClass = deviceClass;
- device->deviceSubClass = deviceSubClass;
- device->deviceProtocol = deviceProtocol;
- device->idVendor = idVendor;
- device->idProduct = idProduct;
- device->bus = bus;
- device->deviceAddress = devAddress;
- ad->devList = g_list_append(ad->devList, device);
-
- if (true == is_device_supported(deviceClass)) {
- if (deviceClass != USB_HOST_MASS_STORAGE) {
- j = 0;
- while(false == is_device_driver_active(list[i], deviceClass)) {
- USB_LOG("Wait...");
- usleep(100000);
- j++;
- if (j > 100) break; /* Try for 10 seconds */
- }
- if (j <= 100) {
- ret = um_connect_known_device(ad, deviceClass,
- deviceSubClass, deviceProtocol);
- if (ret < 0) USB_LOG("FAIL: um_connect_known_device()");
- }
- }
- } else {
- ret = um_connect_unknown_device(ad, deviceClass, deviceSubClass,
- deviceProtocol, idVendor, idProduct);
- if (ret < 0) USB_LOG("FAIL: um_connect_unknown_device()");
- }
- } else {
- found = false;
+ FILE *file = setmntent(MTAB_FILE, "r");
+ struct mntent *mnt_entry;;
+
+ while ((mnt_entry = getmntent(file))) {
+ if (!strncmp(mnt_entry->mnt_fsname, devname, strlen(devname))) {
+ USB_LOG("%s is mounted", devname);
+ __USB_FUNC_EXIT__;
+ return true;
}
}
- libusb_free_device_list(list, 1);
+ USB_LOG("%s is unmounted", devname);
__USB_FUNC_EXIT__;
- return 0;
+ return false;
}
-int remove_usb_device_to_list(UmMainData *ad)
+static void um_show_mounted_mass_storage(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- if (!(ad->devList)) return 0;
- int i, j;
- int ret = -1;
- int recheck = 0;
- ssize_t cnt;
- bool found = false;
- libusb_device **list = NULL;
- pm_change_state(LCD_NORMAL);
-
- /* When getting the device list using libusb apis,
- * the device list would not be updated.
- * So, we should re-check when we cannot find device removed */
- do {
- cnt = libusb_get_device_list(ad->usbctx, &list);
- if (list == NULL) {
- /* USB device status is not changed */
- __USB_FUNC_EXIT__;
- return 0;
+ assert(ad);
+ GList *l = NULL;
+
+ /* Show mounted Mass storage */
+ USB_LOG("*******************************");
+ USB_LOG("** Mounted Mass Storage List ");
+ if (ad->devMSList) {
+ for (l = ad->devMSList ; l ; l = g_list_next(l)) {
+ USB_LOG("** %s", ((MSDevName *)(l->data))->devName);
}
- for (i = 0 ; i < g_list_length(ad->devList) ; i++) {
- for (j = 0 ; j < cnt ; j++) {
- if ( 0 == compareTwoDevices(list[j],
- ((UsbHost *)(g_list_nth_data(ad->devList, i)))) ) {
- found = true;
- break;
- }
- }
- if (found == true) {
- found = false;
- } else {
- ret = um_disconnect_usb_device(ad,
- ((UsbHost *)(g_list_nth_data(ad->devList, i)))->deviceClass);
- if (ret < 0) {
- USB_LOG("FAIL: um_disconnect_usb_device()");
- }
- ad->devList = g_list_delete_link(ad->devList, g_list_nth(ad->devList, i));
- found = true;
- break;
- }
- }
- recheck++;
- libusb_free_device_list(list, 1);
- USB_LOG("Wait...");
- sleep(1); /* Wait for 1 sec to get valid libusb device list */
- } while (found == false && recheck < 3); /* Try 3 times */
+ } else {
+ USB_LOG("** Mass storage None ");
+ }
+ USB_LOG("*******************************");
__USB_FUNC_EXIT__;
- return 0;
}
-int grantHostPermission(UmMainData *ad, char *appId, int vendor, int product)
+static int um_ms_list_added(UmMainData *ad, char *devName)
{
__USB_FUNC_ENTER__;
- if (!ad || !appId) return -1;
- if (ad->permittedPkgForAcc != NULL) {
- USB_LOG("Previous permitted pkg is removed\n");
+ assert(ad);
+ assert(devName);
+
+ MSDevName *msDevice;
+
+ msDevice = (MSDevName *)malloc(sizeof(MSDevName));
+ um_retvm_if(!msDevice, -1, "FAIL: malloc()");
+
+ USB_LOG("devName: %s", devName);
+ msDevice->devName = strdup(devName);
+ if (!(msDevice->devName)) {
+ USB_LOG("FAIL: strdup()");
+ FREE(msDevice);
+ return -1;
}
- int i;
- for (i = 0; i < g_list_length(ad->devList) ; i++) {
- if ( ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idVendor == vendor
- && ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idProduct == product) {
- FREE(((UsbHost *)(g_list_nth_data(ad->devList, i)))->permittedAppId);
- ((UsbHost *)(g_list_nth_data(ad->devList, i)))->permittedAppId = strdup(appId);
- USB_LOG("Permitted app for the device is %s\n", ((UsbHost *)(g_list_nth_data(ad->devList, i)))->permittedAppId);
- break;
- }
+ ad->devMSList = g_list_append(ad->devMSList, msDevice);
+ if (!(ad->devMSList)) {
+ USB_LOG("FAIL: g_list_append()");
+ FREE(msDevice);
+ return -1;
}
+
+ um_show_mounted_mass_storage(ad);
+
__USB_FUNC_EXIT__;
return 0;
}
-int launch_host_app(char *appId)
+static int um_ms_list_removed(UmMainData *ad, char *devName)
{
__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)");
+ assert(ad);
+ assert(devName);
+ assert(ad->devMSList);
+
+ GList *l;
+ GList *tmpl;
+ MSDevName *devNameList;
+
+ for (l = g_list_last(ad->devMSList) ; l ;) {
+ tmpl = l;
+ l = g_list_previous(l);
+ devNameList = (MSDevName *)(tmpl->data);
+ if (!strncmp(devNameList->devName, devName, strlen(devName))) {
+ ad->devMSList = g_list_delete_link(ad->devMSList, tmpl);
+ break;
+ }
+ }
+
+ if (ad->devMSList) {
+ if (0 == g_list_length(ad->devMSList)) {
+ g_list_free_full(ad->devMSList, free_ms_list);
+ ad->devMSList = NULL;
+ }
+ }
+
+ um_show_mounted_mass_storage(ad);
+
__USB_FUNC_EXIT__;
return 0;
}
-Eina_Bool hasHostPermission(UmMainData *ad, char *appId, int vendor, int product)
+static void um_connect_known_device_mass_storage(UmMainData *ad,
+ char *devpath, char *devname, char *fstype)
{
__USB_FUNC_ENTER__;
- if (!ad || !appId) return EINA_FALSE;
- int i;
- for (i = 0; i < g_list_length(ad->devList) ; i++) {
- if ( ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idVendor == vendor
- && ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idProduct == product ) {
- if (0 == strncmp(((UsbHost *)(g_list_nth_data(ad->devList, i)))->permittedAppId,
- appId, strlen(appId))) {
- __USB_FUNC_EXIT__;
- return EINA_TRUE;
- } else {
- break;
- }
- }
+ assert(ad);
+ assert(devpath);
+ assert(devname);
+ assert(fstype);
+
+ int ret = -1;
+ char *notiTitle = NULL;
+ char *notiContent = NULL;
+
+ USB_LOG("USB host mass storage connected");
+ ret = um_usb_storage_added(ad, devpath, devname, fstype);
+ if (ret != 0) {
+ load_connection_popup("USB mass storage mount failed");
+ return ;
}
+
+ notiTitle = "USB mass storage connected";
+ notiContent = devname;
+ ret = um_append_host_notification(ad, USB_NOTI_MASS_STORAGE_ADDED, devname,
+ notiTitle, notiContent, USB_ICON_PATH);
+ if (ret < 0) USB_LOG("FAIL: um_append_host_notification()");
+
+ load_connection_popup("IDS_COM_POP_USB_MASS_STORAGE_CONNECTED_ABB2");
+
__USB_FUNC_EXIT__;
- return EINA_FALSE;
}
-Eina_Bool is_host_connected(UmMainData *ad, int vendor, int product)
+static char *adjust_vendor_name(char *vendor)
{
__USB_FUNC_ENTER__;
- if (!ad) return EINA_FALSE;
- int i;
- for (i = 0 ; i < g_list_length(ad->devList) ; i++) {
- if ( ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idVendor == vendor
- && ((UsbHost *)(g_list_nth_data(ad->devList, i)))->idProduct == product ) {
- __USB_FUNC_EXIT__;
- return EINA_TRUE;
- }
+ if (!vendor) return NULL;
+
+ char *str;
+
+ if (!strncasecmp(vendor, VENDOR_HP_1, strlen(VENDOR_HP_1))) {
+ __USB_FUNC_EXIT__;
+ return strdup(VENDOR_HP_3);
+ }
+
+ if (!strncasecmp(vendor, VENDOR_HP_2, strlen(VENDOR_HP_2))) {
+ __USB_FUNC_EXIT__;
+ return strdup(VENDOR_HP_3);
+ }
+
+ if (!strncasecmp(vendor, VENDOR_HP_3, strlen(VENDOR_HP_3))) {
+ __USB_FUNC_EXIT__;
+ return strdup(VENDOR_HP_3);
+ }
+
+ str = vendor;
+ *str = toupper(*str);
+ while(*(++str)) {
+ *str = tolower(*str);
}
+
__USB_FUNC_EXIT__;
- return EINA_FALSE;
+ return strdup(vendor);
}
-int show_all_usb_devices(GList *devList, int option)
+static int cnt_char_of_vendor(char *product, char *vendor)
{
__USB_FUNC_ENTER__;
- if (!(devList)) {
+ assert(product);
+ assert(vendor);
+
+ int cnt;
+ char *str;
+
+ str = strcasestr(product, vendor);
+ if (!str || str != product) {
+ __USB_FUNC_EXIT__;
return 0;
}
- if (option == 1) {
- int i;
- USB_LOG("***********************************\n");
- USB_LOG("** USB devices list \n");
- USB_LOG("** \n");
- for (i = 0 ; i < g_list_length(devList) ; i++) {
- USB_LOG("** Device number: %d\n", i);
- USB_LOG("** Permitted app : %s\n", ((UsbHost *)(g_list_nth_data(devList, i)))->permittedAppId);
- USB_LOG("** Device Class : %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->deviceClass);
- USB_LOG("** Device Subclass : %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->deviceSubClass);
- USB_LOG("** Device Protocol : %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->deviceProtocol);
- USB_LOG("** Device Vendor ID : %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->idVendor);
- USB_LOG("** Device Product ID: %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->idProduct);
- USB_LOG("** Device Bus number: %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->bus);
- USB_LOG("** Device Address: %u\n", ((UsbHost *)(g_list_nth_data(devList, i)))->deviceAddress);
- USB_LOG("*************************************** ");
+
+ cnt = strlen(vendor);
+ str = str + cnt;
+ while (str) {
+ if (*str == ' ' || *str == '_' || *str == '-') {
+ cnt++;
+ str++;
+ continue;
}
- } else {
- USB_LOG("FAIL: Option is not correct\n");
+ break;
}
+ USB_LOG("Number of characters of vendor(%s) in product(%s)is %d", vendor, product, cnt);
+
__USB_FUNC_EXIT__;
- return 0;
+ return cnt;
}
-void add_host_noti_cb(void *data)
+static char *remove_vendor_from_product(char *product, char *vendor)
{
__USB_FUNC_ENTER__;
- UmMainData *ad = (UmMainData *)data;
- int ret = show_all_usb_devices(ad->devList,1);
- if (ret != 0) USB_LOG("FAIL: show_all_usb_devices(ad)\n");
+ assert(product);
+ assert(vendor);
- ret = add_usb_device_to_list(ad);
- um_retm_if(0 != ret, "FAIL: add_usb_device_to_list(ad)");
+ char *str;
+ int cnt;
+
+ cnt = cnt_char_of_vendor(product, vendor);
+ str = product + cnt;
+
+ USB_LOG("Product name: %s", str);
- ret = show_all_usb_devices(ad->devList,1);
- if (ret != 0) USB_LOG("FAIL: show_all_usb_devices(ad)\n");
__USB_FUNC_EXIT__;
+ return strdup(str);
}
-void remove_host_noti_cb(void *data)
+static char *remove_hp_from_product(char *product)
{
__USB_FUNC_ENTER__;
- UmMainData *ad = (UmMainData *)data;
- int ret = show_all_usb_devices(ad->devList,1);
- if (ret != 0) USB_LOG("FAIL: show_all_usb_devices(ad)\n");
+ assert(product);
+
+ char *str;
+ int cnt;
+
+ cnt = cnt_char_of_vendor(product, VENDOR_HP_1);
+ if (cnt > 0) {
+ str = product + cnt;
+ __USB_FUNC_EXIT__;
+ return strdup(str);
+ }
+
+ cnt = cnt_char_of_vendor(product, VENDOR_HP_2);
+ if (cnt > 0) {
+ str = product + cnt;
+ __USB_FUNC_EXIT__;
+ return strdup(str);
+ }
+
+ cnt = cnt_char_of_vendor(product, VENDOR_HP_3);
+ if (cnt > 0) {
+ str = product + cnt;
+ __USB_FUNC_EXIT__;
+ return strdup(str);
+ }
- ret = remove_usb_device_to_list(ad);
- um_retm_if(0 != ret, "FAIL: remove_usb_device_to_list(ad)");
+ str = product;
- ret = show_all_usb_devices(ad->devList,1);
- if (ret != 0) USB_LOG("FAIL: show_all_usb_devices(ad)\n");
__USB_FUNC_EXIT__;
+ return strdup(product);
}
-static void camera_added_popup()
+static char *get_interface_name(UsbInterface *device, char *content)
{
__USB_FUNC_ENTER__;
- int ret = -1;
- bundle *b = NULL;
+ assert(device);
+ assert(content);
- DIR *dp;
- struct dirent *dir;
- struct stat stat;
- char buf[255] = "unknown_camera";
+ char notiContent[BUF_MAX];
+ char *product = device->ifIProduct;
+ char *vendor = device->ifIManufacturer;
- if ((dp = opendir("/tmp/camera")) == NULL) {
- USB_LOG("Can not open directory");
- return ;
+ if (!product)
+ product = content;
+
+ if (!vendor) {
+ snprintf(notiContent, sizeof(notiContent), "%s", product);
+ __USB_FUNC_EXIT__;
+ return strdup(notiContent);
}
- chdir("/tmp/camera");
- while (dir = readdir(dp)) {
- memset(&stat, 0, sizeof(struct stat));
- lstat(dir->d_name, &stat);
- if (S_ISDIR(stat.st_mode) || S_ISLNK(stat.st_mode)) {
- if (strncmp(".", dir->d_name, 1) == 0
- || strncmp("..", dir->d_name, 2) == 0)
- continue;
- snprintf(buf, 255, "%s", dir->d_name);
- }
+ vendor = adjust_vendor_name(vendor);
+ if (!vendor)
+ vendor = strdup(device->ifIManufacturer);
+
+ if (!strncmp(vendor, VENDOR_HP_3, strlen(VENDOR_HP_3))) {
+ product = remove_hp_from_product(product);
+ } else {
+ product = remove_vendor_from_product(product, vendor);
}
- closedir(dp);
- b = bundle_create();
- bundle_add(b, "_SYSPOPUP_CONTENT_", "camera_add");
- bundle_add(b, "device_name", buf);
- ret = syspopup_launch("usbotg-syspopup", b);
- USB_LOG("ret: %d", ret);
- if (ret < 0) {
- USB_LOG("FAIL: syspopup_launch(usbotg-syspopup, b)");
+ if (!product) {
+ if (device->ifIProduct)
+ product = strdup(device->ifIProduct);
+ else
+ product = strdup(content);
}
- bundle_free(b);
- __USB_FUNC_EXIT__ ;
- return ;
-}
+ snprintf(notiContent, sizeof(notiContent), "%s %s", vendor, product);
+
+ FREE(vendor);
+ FREE(product);
-static bool is_mass_storage_mounted(UmMainData *ad, int event)
-{
- __USB_FUNC_ENTER__;
- if (!ad) return false;
- int ret;
- char *storage_path = NULL;
- char *storage = NULL;
- char storage_mount_path[BUF_MAX];
- if (event == 0) { /* 'event == 0' means that mass storage is just connected */
- storage_path = vconf_get_str(VCONFKEY_SYSMAN_ADDED_STORAGE_UEVENT);
- if (storage_path != NULL) {
- storage = strrchr(storage_path, '/');
- storage++; /* remove '/' */
- USB_LOG("storage: %s", storage);
- }
- } else if (event == 1) { /* 'event == 1' means that mass storage is just removed */
- storage = vconf_get_str(VCONFKEY_SYSMAN_REMOVED_STORAGE_UEVENT);
- }
- if (storage) {
- snprintf(storage_mount_path, BUF_MAX, "%s/%s", MOUNT_POINT, storage);
- USB_LOG("storage_mount_path: %s", storage_mount_path);
- ret = access(storage_mount_path, F_OK);
- if (ret == 0) {
- USB_LOG("This mass storage is mounted");
- __USB_FUNC_EXIT__;
- return true;
- } else {
- USB_LOG("This mass storage is unmounted");
- __USB_FUNC_EXIT__;
- return false;
- }
- }
__USB_FUNC_EXIT__;
- return false;
+ return strdup(notiContent);
+
}
-int um_connect_known_device(UmMainData *ad, int class, int subClass, int protocol)
+static int um_connect_known_device(UmMainData *ad, UsbInterface *device)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
+ assert(ad);
+ assert(device);
int ret = -1;
- char *msg = NULL;
- int i;
+ char *tickerMsg = NULL;
+ char *notiTitle = NULL;
+ char *notiContent = NULL;
- switch (class) {
+ switch (device->ifClass) {
case USB_HOST_HID:
- if (HID_KEYBOARD == protocol) {
+ if (HID_KEYBOARD == device->ifProtocol) {
USB_LOG("USB host keyboard connected");
- msg = "IDS_COM_POP_KEYBOARD_CONNECTED_ABB2";
- } else if (HID_MOUSE == protocol) {
+ tickerMsg = "IDS_COM_POP_KEYBOARD_CONNECTED_ABB2";
+ notiTitle = "Keyboard connected";
+ notiContent = get_interface_name(device, DEV_STR_KEYBOARD);
+ break;
+ }
+
+ if (HID_MOUSE == device->ifProtocol) {
USB_LOG("USB host mouse connected");
- msg = "IDS_COM_POP_MOUSE_CONNECTED_ABB2";
- } else {
- USB_LOG("USB host unknown HID device connected");
- msg = "IDS_BT_POP_CONNECTED_TO_HID_DEVICE";
+ tickerMsg = "IDS_COM_POP_MOUSE_CONNECTED_ABB2";
+ notiTitle = "Mouse connected";
+ notiContent = get_interface_name(device, DEV_STR_MOUSE);
+ break;
}
- break;
+
+ USB_LOG("USB host unknown HID device connected");
+ return 0;
+
case USB_HOST_CAMERA:
USB_LOG("USB host camera connected");
- msg = "IDS_COM_POP_CAMERA_CONNECTED_ABB2";
+ tickerMsg = "IDS_COM_POP_CAMERA_CONNECTED_ABB2";
+ notiTitle = "Camera connected";
+ notiContent = get_interface_name(device, DEV_STR_CAMERA);
camera_added_popup();
break;
case USB_HOST_PRINTER:
USB_LOG("USB host printer connected");
- msg = "IDS_COM_POP_PRINTER_CONNECTED_ABB2";
- /* We should add some operations for printer */
+ /* TODO check whether or not this is really printer. (scanner, fax, ... ) */
+ tickerMsg = "IDS_COM_POP_PRINTER_CONNECTED_ABB2";
+ notiTitle = "Printer connected";
+ notiContent = get_interface_name(device, DEV_STR_PRINTER);
break;
+ case USB_HOST_REF_INTERFACE:
case USB_HOST_MASS_STORAGE:
- USB_LOG("USB host mass storage connected");
- ret = um_usb_storage_added();
- if (0 > ret) {
- msg = "USB mass storage mount failed";
- } else {
- msg = "IDS_COM_POP_USB_MASS_STORAGE_CONNECTED_ABB2";
- }
- break;
case USB_HOST_HUB:
- USB_LOG("USB host hub connected");
- break;
+ case USB_HOST_CDC:
+ case USB_HOST_MISCELLANEOUS:
+ case USB_HOST_VENDOR_SPECIFIC:
default:
- USB_LOG("USB host unknown device connected");
- break;
+ return 0;
}
- if (msg == NULL) {
+
+ if (!tickerMsg) {
USB_LOG("msg of tickernoti is NULL");
+ FREE(notiContent);
__USB_FUNC_EXIT__;
return 0;
}
- load_connection_popup(ad, msg, TICKERNOTI_ORIENTATION_TOP);
+ if (!notiContent)
+ notiContent = strdup(DEV_STR_UNSUPPORTED);
+
+ if (notiTitle) {
+ ret = um_append_host_notification(ad, USB_NOTI_HOST_ADDED, device,
+ notiTitle, notiContent, USB_ICON_PATH);
+ if (ret < 0) USB_LOG("FAIL: um_append_host_notification()");
+ }
+
+ load_connection_popup(tickerMsg);
+
+ FREE(notiContent);
__USB_FUNC_EXIT__;
return 0;
}
-int um_connect_unknown_device(UmMainData *ad,
- int class,
- int subClass,
- int protocol,
- int vendor,
- int product)
+static int um_connect_unknown_device(UmMainData *ad, UsbInterface *device)
{
__USB_FUNC_ENTER__;
- int ret = load_system_popup_with_deviceinfo(ad, SELECT_PKG_FOR_HOST_POPUP,
- class, subClass, protocol, vendor, product);
+ assert(ad);
+ assert(device);
+ /* TODO Unknown devices should be supported */
+ /*
+ int ret;
+
+ ret = launch_usb_syspopup(ad, SELECT_PKG_FOR_HOST_POPUP, &device);
if (ret < 0) {
- USB_LOG("FAIL: load_system_popup_with_deviceinfo()");
- }
+ USB_LOG("FAIL: launch_usb_syspopup()");
+ } */
__USB_FUNC_EXIT__;
return 0;
}
-int um_disconnect_usb_device(UmMainData *ad, int class)
+static void um_disconnect_usb_device_mass_storage(UmMainData *ad, char *devname)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
+ assert(ad);
+ assert(devname);
int ret = -1;
+ char *msg = "IDS_COM_POP_USB_MASS_STORAGE_UNEXPECTEDLY_REMOVED";
+
+ USB_LOG("USB host mass storage removed");
+ ret = um_usb_storage_removed(ad, devname);
+ if (ret < 0) USB_LOG("FAIL: um_usb_storage_removed()");
+
+ ret = um_remove_host_notification(ad, USB_NOTI_MASS_STORAGE_REMOVED, devname);
+ if (ret < 0) USB_LOG("FAIL: um_remove_host_notification()");
+
+ load_connection_popup(msg);
+
+ __USB_FUNC_EXIT__;
+ return ;
+}
+
+static int um_disconnect_usb_device(UmMainData *ad, UsbInterface *devIf)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(devIf);
+
+ int ret;
char *msg = "IDS_COM_BODY_USB_DEVICE_SAFELY_REMOVED";
- int i;
- switch (class) {
+ switch (devIf->ifClass) {
case USB_HOST_MASS_STORAGE:
- USB_LOG("USB host mass storage removed");
- if (false == is_mass_storage_mounted(ad, 1)) {
- USB_LOG("Mass storage is already unmounted");
- __USB_FUNC_EXIT__;
- return 0;
- }
- msg = "IDS_COM_POP_USB_MASS_STORAGE_UNEXPECTEDLY_REMOVED";
- ret = um_usb_storage_removed();
- if (ret < 0) USB_LOG("FAIL: um_usb_storage_removed()");
- break;
+ USB_LOG("ERROR: This function is not for mass storage");
+ return 0;
case USB_HOST_HUB:
- USB_LOG("USB hub removed");
+ case USB_HOST_REF_INTERFACE:
+ case USB_HOST_CDC:
+ case USB_HOST_MISCELLANEOUS:
+ case USB_HOST_VENDOR_SPECIFIC:
__USB_FUNC_EXIT__;
return 0;
- case USB_HOST_HID:
case USB_HOST_CAMERA:
+ um_load_usbotg_popup(USBOTG_SYSPOPUP, CAMERA_REMOVE, NULL);
+ case USB_HOST_HID:
case USB_HOST_PRINTER:
default:
+ USB_LOG("USB device removed~!");
+ ret = um_remove_host_notification(ad, USB_NOTI_HOST_REMOVED, devIf);
+ if (ret < 0) USB_LOG("FAIL: um_remove_host_notification()");
break;
}
- load_connection_popup(ad, msg, TICKERNOTI_ORIENTATION_TOP);
+ load_connection_popup(msg);
__USB_FUNC_EXIT__;
return 0;
}
-void add_mass_storage_cb(keynode_t *in_key, void *data)
+static inline char *get_devname(char *devpath)
+{
+ char *r;
+ if (!devpath)
+ return NULL;
+
+ r = strrchr(devpath, '/');
+ if (r)
+ return r + 1;
+ return devpath;
+}
+
+void um_uevent_mass_storage_added(UmMainData *ad, char *devpath, char *fstype)
{
__USB_FUNC_ENTER__;
- if (!data) return ;
- UmMainData *ad = (UmMainData *)data;
+ assert(ad);
+ assert(devpath);
+ assert(fstype);
+
int ret;
- if (false == is_mass_storage_mounted(ad, 0)) {
- ret = um_connect_known_device(ad, USB_HOST_MASS_STORAGE, 0, 0);
- if (ret < 0) USB_LOG("FAIL: um_connect_known_device()");
+ char *devname = NULL;
+
+ if (true == is_mass_storage_mounted(ad, devpath)) {
+ USB_LOG("The mass storage(%s) is already mounted", devpath);
+ return;
}
+
+ devname = get_devname(devpath);
+ USB_LOG("devname: %s", devname);
+
+ um_connect_known_device_mass_storage(ad, devpath, devname, fstype);
+
+ ret = um_ms_list_added(ad, devname);
+ if (ret < 0) USB_LOG("FAIL: um_ms_list_added()");
+
__USB_FUNC_EXIT__;
}
-void remove_mass_storage_cb(keynode_t *in_key, void *data)
+void um_uevent_mass_storage_removed(UmMainData *ad, char *devpath)
{
__USB_FUNC_ENTER__;
- if (!data) return ;
- UmMainData *ad = (UmMainData *)data;
- if (true == is_mass_storage_mounted(ad, 1)) {
- int ret = um_disconnect_usb_device(ad, USB_HOST_MASS_STORAGE);
- if (ret < 0) USB_LOG("FAIL: um_disconnect_usb_device()");
+ assert(ad);
+ assert(devpath);
+ int ret;
+ char *devname = NULL;
+
+ if (false == is_mass_storage_mounted(ad, devpath)) {
+ USB_LOG("The mass storage(%s) is already unmounted", devpath);
+ return ;
}
+
+ devname = get_devname(devpath);
+ USB_LOG("devname: %s", devname);
+
+ um_disconnect_usb_device_mass_storage(ad, devname);
+
+ ret = um_ms_list_removed(ad, devname);
+ if (ret < 0) USB_LOG("FAIL: um_ms_list_removed()");
+
__USB_FUNC_EXIT__;
}
-int disconnectUsbHost(UmMainData *ad)
+void disconnect_usb_host(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = umReleaseAllDevice(ad);
- if (ret < 0) USB_LOG("FAIL: umReleaseAllDevice(ad)");
+ assert(ad);
+ um_release_all_device(ad);
__USB_FUNC_EXIT__;
- return 0;
}
/*************************************************************/
/* Mounting Mass Storage (USB storage) */
/*************************************************************/
-static int um_mount_device(char *dev)
+static int um_mount_device(char *devpath, char *devname, char *fstype)
{
__USB_FUNC_ENTER__;
- if (access(dev, F_OK) != 0) {
- USB_LOG("Failed to find device: DEVICE(%s)", dev);
+ assert(devpath);
+ assert(devname);
+ assert(fstype);
+
+ if (access(devpath, F_OK) != 0) {
+ USB_LOG("Failed to find device: DEVICE(%s)", devpath);
return -1;
}
- int fd = -1;
int r = -1;
- char *rel_mnt_point;
char buf_mnt_point[BUF_MAX];
- rel_mnt_point = strrchr(dev, '/');
- if (rel_mnt_point == NULL) {
- USB_LOG("Get Relative Mount Path Failed");
- return -1;
- }
-
- snprintf(buf_mnt_point, BUF_MAX, "%s%s", MOUNT_POINT, rel_mnt_point);
+ snprintf(buf_mnt_point, BUF_MAX, "%s/%s", MOUNT_POINT, devname);
/* Make directory to mount */
r = mkdir(buf_mnt_point, 0755);
}
}
+ /* TODO Support mounting other file systems */
/* Mount block device on mount point */
- r = mount(dev, buf_mnt_point, "vfat", 0, "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed,smackfsroot=*,smackfsdef=*");
+ if (!strncmp(fstype, "vfat", strlen(fstype))) {
+ r = mount(devpath, buf_mnt_point, "vfat", 0, "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed,smackfsroot=*,smackfsdef=*");
+ } else {
+ USB_LOG("ERROR: File system type (%s) is not supported", fstype);
+ return -1;
+ }
+
if (r < 0) {
r = rmdir(buf_mnt_point);
USB_LOG("FAIL: Mount failed: MOUNT PATH(%s)", buf_mnt_point);
static int um_unmount_device(char *mnt_point)
{
__USB_FUNC_ENTER__;
- if (mnt_point == NULL) return -1;
+ assert(mnt_point);
if (access(mnt_point, F_OK) != 0) {
USB_LOG("Failed to find path: MOUNT PATH(%s)", mnt_point);
return -1;
return -1;
}
- bundle *b = NULL;
- b = bundle_create();
- bundle_add(b, "_SYSPOPUP_CONTENT_", "otg_remove");
- ret = syspopup_launch("usbotg-syspopup", b);
- if (ret < 0) {
- USB_LOG("FAIL: popup lauch failed\n");
- }
- bundle_free(b);
+ um_load_usbotg_popup(USBOTG_SYSPOPUP, STORAGE_REMOVE, mnt_point);
/* Clean up unmounted directory */
ret = rmdir(mnt_point);
return 0;
}
-static int um_usb_storage_added()
+static int um_usb_storage_mount_tmpfs(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- int ret = -1;
- int fd = -1;
- int i;
+ assert(ad);
- char *buf_dev;
- char *mounted_check;
- char *rel_mnt_point;
- char buf_mnt_point[BUF_MAX];
- char *sd_char;
-
- do {
- i = 0;
- buf_dev = vconf_get_str(VCONFKEY_SYSMAN_ADDED_STORAGE_UEVENT);
- if (buf_dev != NULL) {
- sd_char = strstr(buf_dev, "sd");
- if (sd_char == NULL) buf_dev = NULL;
- }
- USB_LOG("Wait...");
- sleep(1);
- i++;
- if (i == 5) break;
- } while(buf_dev == NULL);
+ if (ad->tmpfsMounted) {
+ USB_LOG("tmpfs is already mounted");
+ return 0;
+ }
+
+ /* Mount tmpfs for protecting user data */
+ if (mount(FS_TMPFS, MOUNT_POINT, FS_TMPFS, 0, "") < 0) {
+ USB_LOG("FAIL: mount(%s)", MOUNT_POINT);
+ return -1;
+ }
+
+ /* Change permission to avoid to write user data on tmpfs */
+ if (chmod(MOUNT_POINT, 0755) < 0) {
+ USB_LOG("FAIL: Failed to change mode: %s", MOUNT_POINT);
+ if (umount2(MOUNT_POINT, MNT_DETACH) < 0) USB_LOG("FAIL: umount2()");
+ return -1;
+ }
+ ad->tmpfsMounted = true;
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_usb_storage_added(UmMainData *ad, char *devpath, char *devname, char *fstype)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(devpath);
+ assert(devname);
+ assert(fstype);
+
+ char *mounted_check = NULL;
+ char buf_mnt_point[BUF_MAX];
+ FILE *file = NULL;
+ struct mntent *mnt_entry = NULL;
/* Check whether mount point directory is exist */
if (access(MOUNT_POINT, F_OK) < 0) {
}
}
- /* Mount tmpfs for protecting user data */
- if (tmpfs_mounted != 1) {
- if (mount("tmpfs", MOUNT_POINT, "tmpfs", 0, "") < 0) {
- if (errno != EBUSY) {
- USB_LOG("FAIL: Failed to mount USB Storage Mount Directory: %s", MOUNT_POINT);
- return -1;
- }
- } else {
- /* Change permission to avoid to write user data on tmpfs */
- if (chmod(MOUNT_POINT, 0755) < 0) {
- USB_LOG("FAIL: Failed to change mode: %s", MOUNT_POINT);
- umount2(MOUNT_POINT, MNT_DETACH);
- return -1;
- }
- tmpfs_mounted = 1;
- }
+ if (um_usb_storage_mount_tmpfs(ad) < 0) {
+ USB_LOG("FAIL: um_usb_storage_mount_tmpfs()");
+ return -1;
}
- USB_LOG("buf_dev: %s", buf_dev);
- USB_LOG("strrchr(buf_dev): %s", strrchr(buf_dev, '/'));
- rel_mnt_point = strrchr(buf_dev, '/');
+ snprintf(buf_mnt_point, BUF_MAX, "%s/%s", MOUNT_POINT, devname);
- if (rel_mnt_point == NULL) {
- USB_LOG("FAIL: Get Relative Mount Path Failed");
- return -1;
+ if (um_mount_device(devpath, devname, fstype)) {
+ USB_LOG("FAIL: um_mount_device()");
}
- snprintf(buf_mnt_point, BUF_MAX, "%s%s", MOUNT_POINT, rel_mnt_point);
- if (um_mount_device(buf_dev)) {
- USB_LOG("FAIL: um_mount_device(%s)", buf_dev);
+ /* Check whether block deivce is mounted */
+ file = setmntent(MTAB_FILE, "r");
+ while ((mnt_entry = getmntent(file))) {
+ mounted_check = strstr(mnt_entry->mnt_fsname, devpath);
+ if (mounted_check) break;
+ }
+ endmntent(file);
+ if (!mounted_check) {
+ USB_LOG("Nothing to be mounted: DEVICE(%s)", devname);
+ return -1;
}
- FILE *file = setmntent(MTAB_FILE, "r");
- struct mntent *mnt_entry;
-
- /* Check whether block deivce is mounted */
- while (mnt_entry = getmntent(file)) {
- mounted_check = strstr(mnt_entry->mnt_fsname, buf_dev);
- if (mounted_check != NULL) {
- if (added_noti_value < INT_MAX) {
- ++added_noti_value;
- } else {
- added_noti_value = 1;
- }
- /* Broadcast mounting notification */
- if (vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, added_noti_value) < 0) {
- USB_LOG("Setting vconf value is failed: KEY(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE);
- vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, -1);
- }
+ /* Broadcast mounting notification */
+ if (vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, 1) < 0) {
+ USB_LOG("FAIL: vconf_set_int(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE);
+ return -1;
+ }
- USB_LOG("Setting vconf value: KEY(%s) DEVICE(%s)", VCONFKEY_SYSMAN_ADDED_USB_STORAGE, buf_dev);
- endmntent(file);
+ um_load_usbotg_popup(USBOTG_SYSPOPUP, STORAGE_ADD, buf_mnt_point);
- bundle *b = NULL;
- b = bundle_create();
- bundle_add(b, "_SYSPOPUP_CONTENT_", "otg_add");
- bundle_add(b, "path", buf_mnt_point);
- ret = syspopup_launch("usbotg-syspopup", b);
- if (ret < 0) {
- USB_LOG("popup lauch failed\n");
- }
- bundle_free(b);
- return 0;
- }
- }
- /* Failed to mount storage device */
- USB_LOG("Nothing to be mounted: DEVICE(%s)", buf_dev);
- endmntent(file);
__USB_FUNC_EXIT__;
- return -1;
+ return 0;
}
-static int um_usb_storage_removed()
+static int um_usb_storage_removed(UmMainData *ad, char *devname)
{
__USB_FUNC_ENTER__;
- int fd = -1;
- char *buf_dev_name = vconf_get_str(VCONFKEY_SYSMAN_REMOVED_STORAGE_UEVENT);
+ assert(ad);
+ assert(devname);
char buf_mnt_point[BUF_MAX];
- snprintf(buf_mnt_point, BUF_MAX, "%s/%s", MOUNT_POINT, buf_dev_name);
+ snprintf(buf_mnt_point, BUF_MAX, "%s/%s", MOUNT_POINT, devname);
+ USB_LOG("buf_mnt_point: %s", buf_mnt_point);
- if (um_unmount_device(buf_mnt_point) == 0) {
- if(umount2(MOUNT_POINT, MNT_DETACH) == 0)
- tmpfs_mounted = 1;
- if (removed_noti_value < INT_MAX) {
- ++removed_noti_value;
+ if (um_unmount_device(buf_mnt_point) != 0) {
+ USB_LOG("FAIL: um_unmount_device()");
+ return -1;
+ }
+
+ if (ad->devMSList && g_list_length(ad->devMSList) <= 1) {
+ if (umount2(MOUNT_POINT, MNT_DETACH) == 0) {
+ USB_LOG("tmpfs is unmounted");
+ ad->tmpfsMounted = false;
} else {
- removed_noti_value = 1;
- }
- if (vconf_set_int(VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, removed_noti_value) < 0) {
- USB_LOG("Setting vconf value is failed: KEY(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE);
- vconf_set_int(VCONFKEY_SYSMAN_ADDED_USB_STORAGE, -1);
+ USB_LOG("FAIL: umount2(%s)", MOUNT_POINT);
}
- USB_LOG("Setting vconf value: KEY(%s) DEVICE(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, buf_dev_name);
- return 0;
}
- USB_LOG("Usb storage removed fail");
+
+ if (vconf_set_int(VCONFKEY_SYSMAN_REMOVED_USB_STORAGE, 1) < 0) {
+ USB_LOG("FAIL: vconf_set_int(%s)", VCONFKEY_SYSMAN_REMOVED_USB_STORAGE);
+ }
__USB_FUNC_EXIT__;
- return -1;
+ return 0;
}
--- /dev/null
+/*
+ * usb-manager
+ * Copyright (c) 2012 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 "um_usb_notification.h"
+
+static void release_usb_notification(gpointer data)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(data);
+ UsbNotification *usbNoti = (UsbNotification *)data;
+ FREE(usbNoti->title);
+ FREE(usbNoti->content);
+ FREE(usbNoti->iconPath);
+ FREE(usbNoti->devName);
+ FREE(usbNoti->devIf);
+ FREE(usbNoti->accDev);
+
+ __USB_FUNC_EXIT__ ;
+}
+
+static int alloc_usb_notification(UsbNotification **usbNoti,
+ int privId,
+ char *title,
+ char *content,
+ char *iconPath,
+ int applist,
+ char *devName,
+ UsbInterface *devIf,
+ UsbAccessory *accDev)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(usbNoti);
+ assert(title);
+ assert(content);
+ assert(iconPath);
+
+ if (*usbNoti) release_usb_notification(*usbNoti);
+ *usbNoti = (UsbNotification *)malloc(sizeof(UsbNotification));
+ if (!(*usbNoti)) return -1;
+ (*usbNoti)->privId = privId;
+ (*usbNoti)->title = strdup(title);
+ (*usbNoti)->content = strdup(content);
+ (*usbNoti)->iconPath = strdup(iconPath);
+ (*usbNoti)->applist = applist;
+
+ if (devName) (*usbNoti)->devName = strdup(devName);
+ else (*usbNoti)->devName = NULL;
+
+ (*usbNoti)->devIf = devIf;
+ (*usbNoti)->accDev = accDev;
+
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+static int cmpTwoDev(int notiType, void *device, UsbNotification *usbNoti)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(device);
+ assert(usbNoti);
+ UsbInterface *devIf = NULL;
+ UsbInterface *notiDevIf = NULL;
+ UsbAccessory *accDev = NULL;
+ UsbAccessory *notiAccDev = NULL;
+
+ switch(notiType) {
+ case USB_NOTI_HOST_ADDED:
+ case USB_NOTI_HOST_REMOVED:
+ devIf = (UsbInterface *)device;
+ notiDevIf = usbNoti->devIf;
+ if (devIf->ifIdVendor == notiDevIf->ifIdVendor
+ && devIf->ifIdProduct == notiDevIf->ifIdProduct
+ && devIf->ifBus == notiDevIf->ifBus
+ && devIf->ifAddress == notiDevIf->ifAddress) {
+ USB_LOG("Two devices are same");
+ __USB_FUNC_EXIT__ ;
+ return 0;
+ }
+ break;
+ case USB_NOTI_ACC_ADDED:
+ case USB_NOTI_ACC_REMOVED:
+ accDev = (UsbAccessory *)device;
+ notiAccDev = usbNoti->accDev;
+ if (!strncmp(accDev->manufacturer, notiAccDev->manufacturer,
+ strlen(accDev->manufacturer))
+ && !strncmp(accDev->model, notiAccDev->model, strlen(accDev->model))
+ && !strncmp(accDev->version, notiAccDev->version, strlen(accDev->version))
+ && !strncmp(accDev->serial, notiAccDev->serial, strlen(accDev->serial))) {
+ USB_LOG("Two accessories are same");
+ __USB_FUNC_EXIT__ ;
+ return 0;
+ } else {
+ USB_LOG("device: %s, %s, %s, %s", accDev->manufacturer, accDev->model, accDev->version, accDev->serial);
+ USB_LOG("notiDev: %s, %s, %s, %s", notiAccDev->manufacturer, notiAccDev->model, notiAccDev->version, notiAccDev->serial);
+ }
+ break;
+ default:
+ break;
+ }
+ __USB_FUNC_EXIT__ ;
+ return -1;
+}
+
+static int show_noti_list(UmMainData *ad, GList *notiList)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ int cnt = 0;
+ UsbNotification *usbNoti = NULL;
+ GList *l = NULL;
+ USB_LOG("*****************************");
+ USB_LOG("** Elements of list **");
+ if (!notiList) {
+ USB_LOG("** No element in the List");
+ USB_LOG("****************************");
+ return 0;
+ }
+
+ cnt = g_list_length(notiList);
+ USB_LOG("** g_list_length(notiList): %d", cnt);
+
+ for(l = notiList ; l ; l = g_list_next(l)) {
+ usbNoti = (UsbNotification *)(l->data);
+ if (!usbNoti) continue;
+ USB_LOG("** privId: %d", usbNoti->privId);
+ USB_LOG("** title: %s", usbNoti->title);
+ USB_LOG("** content: %s", usbNoti->content);
+ USB_LOG("** iconPath %s", usbNoti->iconPath);
+ }
+ USB_LOG("****************************");
+ __USB_FUNC_EXIT__ ;
+ return 0;
+}
+
+static bool cmp_dev_noti(int notiType, UsbNotification *usbNoti, void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(usbNoti);
+ assert(device);
+
+ char *devName = NULL;
+ UsbInterface *devIf = NULL;
+ UsbInterface *hDevIf = NULL;
+ UsbAccessory *accDev = NULL;
+ UsbAccessory *aDev = NULL;
+
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_ADDED:
+ case USB_NOTI_MASS_STORAGE_REMOVED:
+ USB_LOG("Mass storage");
+ devName = (char *)device;
+ USB_LOG("%s, %s", usbNoti->devName, devName);
+ if (!strncmp(usbNoti->devName, devName, strlen(devName))) {
+ return true;
+ } else {
+ return false;
+ }
+ case USB_NOTI_HOST_ADDED:
+ case USB_NOTI_HOST_REMOVED:
+ USB_LOG("USB host");
+ devIf = (UsbInterface *)device;
+ hDevIf = usbNoti->devIf;
+
+ if (hDevIf->ifIdVendor == devIf->ifIdVendor
+ && hDevIf->ifIdProduct == devIf->ifIdProduct
+ && hDevIf->ifBus == devIf->ifBus
+ && hDevIf->ifAddress == devIf->ifAddress) {
+ USB_LOG("return true");
+ return true;
+ } else {
+ USB_LOG("return false");
+ return false;
+ }
+ case USB_NOTI_ACC_ADDED:
+ case USB_NOTI_ACC_REMOVED:
+ USB_LOG("USB accessory");
+ accDev = (UsbAccessory *)device;
+ aDev = usbNoti->accDev;
+ if ( !strncmp(aDev->manufacturer, accDev->manufacturer, strlen(accDev->manufacturer))
+ && !strncmp(aDev->model, accDev->model, strlen(accDev->model))
+ && !strncmp(aDev->version, accDev->version, strlen(accDev->version))
+ && !strncmp(aDev->serial, accDev->serial, strlen(accDev->serial))) {
+ return true;
+ } else {
+ return false;
+ }
+ default:
+ USB_LOG("notiType is invalid");
+ break;
+ }
+ return false;
+}
+
+static int um_set_notification_info(notification_h noti,
+ char *title,
+ char *content,
+ char *iconPath,
+ int applist)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(noti);
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ if (title) {
+ /* Set Title of notification */
+ noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_TITLE,
+ title,
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_set_text(): %d", noti_err);
+ return -1;
+ }
+ }
+
+ if (content) {
+ /* Set Subtitle of notification */
+ noti_err = notification_set_text(noti,
+ NOTIFICATION_TEXT_TYPE_CONTENT,
+ content,
+ NULL,
+ NOTIFICATION_VARIABLE_TYPE_NONE);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_set_text(): %d", noti_err);
+ return -1;
+ }
+ }
+
+ if (iconPath) {
+ /* Set Icon image of notification */
+ noti_err = notification_set_image(noti,
+ NOTIFICATION_IMAGE_TYPE_ICON,
+ USB_ICON_PATH);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_set_image(): %d", noti_err);
+ return -1;
+ }
+ }
+
+ if (applist > 0) {
+ /* Set apps which should receive this noftification */
+ noti_err = notification_set_display_applist(noti, applist);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_set_display_applist(): %d", noti_err);
+ return -1;
+ }
+ }
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_add_notification(UmMainData *ad,
+ int notiType,
+ char *title,
+ char *content,
+ char *iconPath,
+ int applist)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(title);
+ assert(content);
+ assert(iconPath);
+
+ notification_h noti = NULL;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+ int privId = -1;
+ int ret = -1;
+
+ /* Create new notification */
+ noti = notification_new(NOTIFICATION_TYPE_ONGOING,
+ NOTIFICATION_GROUP_ID_NONE,
+ NOTIFICATION_PRIV_ID_NONE);
+ if(!noti) {
+ USB_LOG("FAIL: notification_new()");
+ return -1;
+ }
+
+ /* Set Package name of notification */
+ noti_err = notification_set_pkgname(noti, PACKAGE);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_set_text(): %d", noti_err);
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ /* Set nofification info (title, content, icon, applist) */
+ ret = um_set_notification_info(noti, title, content, iconPath, applist);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_set_notification_info()");
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ /*************************************************/
+ /* TODO: When clicking the notification of Mass storage,
+ * Unmounting the storage should be proceeded.
+ * This feature will be added later */
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_ADDED:
+ break;
+ default:
+ break;
+ }
+ /*************************************************/
+
+ /* Insert notification and get private id */
+ noti_err = notification_insert(noti, &privId);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_insert(): %d", noti_err);
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+ USB_LOG("Private id of the notification: %d", privId);
+
+ noti_err = notification_free(noti);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_insert(): %d", noti_err);
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_update_add_notification(UmMainData *ad,
+ int privId,
+ int notiType,
+ char *title,
+ char *content,
+ char *iconPath,
+ int applist)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(title);
+ assert(content);
+ assert(iconPath);
+
+ int ret = -1;
+ notification_h noti = NULL;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ if (privId < 0) {
+ USB_LOG("This is first notification of %d", notiType);
+ ret = um_add_notification(ad, notiType, title, content, iconPath, applist);
+ if (ret < 0) USB_LOG("FAIL: um_add_notification()");
+ return ret;
+ } else { /* privId >= 0 */
+
+ /* Load notification with privId */
+ noti = notification_load(PACKAGE, privId);
+ if (!noti) {
+ USB_LOG("FAIL: notification_load()");
+ return -1;
+ }
+
+ /* Set nofification info (title, content, icon, applist) */
+ ret = um_set_notification_info(noti, title, content, iconPath, applist);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_set_notification_info()");
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ /* Update notification */
+ noti_err = notification_update(noti);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_update(): %d", noti_err);
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ noti_err = notification_free(noti);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_insert(): %d", noti_err);
+ }
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_append_separate_notification_mass_storage(UmMainData *ad,
+ int notiType,
+ char *device,
+ char *title,
+ char *content,
+ char *iconPath)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(title);
+
+ int privId = -1;
+ int ret = -1;
+ UsbNotification *usbNoti = NULL;
+
+ if (notiType != USB_NOTI_MASS_STORAGE_ADDED) {
+ USB_LOG("ERROR: notiType is improper");
+ return -1;
+ }
+
+ ret = show_noti_list(ad, ad->notiMSList);
+ if (ret < 0) USB_LOG("FAIL: show_noti_list()");
+
+ privId = um_add_notification(ad, notiType, title, content, iconPath,
+ NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+ um_retvm_if(privId < 0, -1, "FAIL: um_add_notification()");
+
+ if (alloc_usb_notification(&usbNoti, privId, title, content, iconPath,
+ NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+ device, NULL, NULL) < 0) {
+ USB_LOG("FAIL: alloc_usb_notification(&usbNoti)");
+ return -1;
+ }
+ ad->notiMSList = g_list_append(ad->notiMSList, usbNoti);
+
+ ret = show_noti_list(ad, ad->notiMSList);
+ if (ret < 0) USB_LOG("FAIL: show_noti_list()");
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_append_separate_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *title,
+ char *content,
+ char *iconPath)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(title);
+
+ int privId = -1;
+
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_ADDED:
+ privId = um_append_separate_notification_mass_storage(ad, notiType,
+ device, title, content, iconPath);
+ if (privId < 0) {
+ USB_LOG("FAIL: um_append_separate_notification_mass_storage()");
+ return -1;
+ }
+ break;
+ default:
+ USB_LOG("This noti type does not support multi notification");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_append_cumulative_notification_host_acc(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *_title,
+ char *_content,
+ char *_iconPath,
+ UsbNotification **usbNoti)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(_title);
+ assert(usbNoti);
+
+ int privId = -1;
+ UsbInterface *devIf = NULL;
+ UsbAccessory *accDev = NULL;
+ GList *notiList = NULL;
+ char titleBuf[BUF_MAX];
+ char *title = _title;
+ char *content = _content;
+ char *iconPath = _iconPath;
+ int cnt = -1;
+
+ switch (notiType) {
+ case USB_NOTI_HOST_ADDED:
+ notiList = ad->notiHostList;
+ devIf = (UsbInterface *)device;
+ break;
+ case USB_NOTI_ACC_ADDED:
+ notiList = ad->notiAccList;
+ accDev = (UsbAccessory *)device;
+ break;
+ default:
+ USB_LOG("This noti type does not support multi notification");
+ return -1;
+ }
+
+ if (notiList) {
+ privId = ((UsbNotification *)g_list_nth_data(notiList, 0))->privId;
+ cnt = (int)g_list_length(notiList);
+ USB_LOG("Number of elements of notiList: %d", cnt);
+ if (cnt >= 1) {
+ snprintf(titleBuf, sizeof(titleBuf), "%d USB devices connected", cnt+1);
+ title = titleBuf;
+ content = "Tap to show devices";
+ } else {
+ privId = -1;
+ }
+ } else {
+ privId = -1;
+ }
+ USB_LOG("privId: %d", privId);
+
+ privId = um_update_add_notification(ad, privId, notiType, title, content, iconPath,
+ NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
+ um_retvm_if(privId < 0, -1, "FAIL: um_update_add_notification()");
+
+ if (alloc_usb_notification(usbNoti, privId, _title, _content, _iconPath,
+ NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY,
+ NULL, devIf, accDev) < 0) {
+ USB_LOG("FAIL: alloc_usb_notification(&usbNoti)");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_append_cumulative_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *title,
+ char *content,
+ char *iconPath)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(title);
+
+ int privId = -1;
+ UsbNotification *usbNoti = NULL;
+
+ privId = um_append_cumulative_notification_host_acc(ad, notiType, device,
+ title, content, iconPath, &usbNoti);
+ if (privId < 0 || !usbNoti) {
+ USB_LOG("FAIL: um_append_cumulative_notification_host()");
+ return -1;
+ }
+
+ switch (notiType) {
+ case USB_NOTI_HOST_ADDED:
+ ad->notiHostList = g_list_append(ad->notiHostList, usbNoti);
+ break;
+ case USB_NOTI_ACC_ADDED:
+ ad->notiAccList = g_list_append(ad->notiAccList, usbNoti);
+ break;
+ default:
+ USB_LOG("This noti type does not support multi notification");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+int um_append_host_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *_title,
+ char *_content,
+ char *_iconPath)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(_title);
+
+ int privId = -1;
+ UsbInterface *devIf = NULL;
+ char *devName = NULL;
+ char *title = _title;
+ char *content = _content;
+ char *iconPath = _iconPath;
+
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_ADDED:
+ devName = (char *)device;
+ privId = um_append_separate_notification(ad,
+ notiType,
+ devName,
+ title,
+ content,
+ iconPath);
+ um_retvm_if(privId < 0, -1, "FAIL: um_add_notification()");
+ break;
+ case USB_NOTI_HOST_ADDED:
+ devIf = (UsbInterface *)device;
+ privId = um_append_cumulative_notification(ad,
+ notiType,
+ devIf,
+ title,
+ content,
+ iconPath);
+ um_retvm_if(privId < 0, -1, "FAIL: um_append_multi_notification()");
+ break;
+ default:
+ break;
+ }
+ USB_LOG("privId: %d", privId);
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+int um_append_client_notification(UmMainData *ad,
+ int notiType,
+ void *device,
+ char *title,
+ char *content,
+ char *iconPath)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(title);
+
+ int privId = -1;
+ if (notiType != USB_NOTI_ACC_ADDED) {
+ USB_LOG("ERROR: This function is just for usb accessory");
+ return -1;
+ }
+
+ privId = um_append_cumulative_notification(ad,
+ notiType,
+ device,
+ title,
+ content,
+ iconPath);
+ um_retvm_if(privId < 0, -1, "FAIL: um_append_multi_notification()");
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_remove_notification(UmMainData *ad,
+ int notiType,
+ int privId)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ /* Delete notification */
+ noti_err = notification_delete_by_priv_id(PACKAGE,
+ NOTIFICATION_TYPE_ONGOING,
+ privId);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_delete_by_priv_id(): %d", noti_err);
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_update_remove_notification(UmMainData *ad,
+ int notiType,
+ int privId,
+ void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ int ret = -1;
+ notification_h noti = NULL;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+ UsbNotification *usbNoti = NULL;
+ GList *notiList = NULL;
+ int cnt = -1;
+ int i = -1;
+ char title[BUF_MAX];
+ char *content;
+ char *iconPath;
+ UsbInterface *devIf = NULL;
+ UsbAccessory *accDev = NULL;
+ int applist = -1;
+
+ switch (notiType) {
+ case USB_NOTI_HOST_REMOVED:
+ notiList = ad->notiHostList;
+ devIf = (UsbInterface *)device;
+ break;
+ case USB_NOTI_ACC_REMOVED:
+ notiList = ad->notiAccList;
+ accDev = (UsbAccessory *)device;
+ break;
+ default:
+ break;
+ }
+ um_retvm_if(!notiList, -1, "ERROR: notiList == NULL");
+
+ cnt = g_list_length(notiList);
+ USB_LOG("g_list_length(notiList): %d", cnt);
+ if (cnt <= 0) {
+ USB_LOG("FAIL: g_list_length(notiList)");
+ return -1;
+ } else if (cnt == 1) {
+ privId = um_remove_notification(ad, notiType, privId);
+ um_retvm_if(privId < 0, -1, "FAIL: um_remove_notification()");
+ } else if (cnt >= 2) {
+ /* Load notification with privId */
+ noti = notification_load(PACKAGE, privId);
+ if (!noti) {
+ USB_LOG("FAIL: notification_load()");
+ return -1;
+ }
+
+ /* Set title, content, iconPath, applist of Notification */
+ if (cnt == 2) {
+ for (i = 0 ; i < cnt ; i++) {
+ usbNoti = (UsbNotification *)g_list_nth_data(notiList, i);
+ if (0 != cmpTwoDev(notiType, device, usbNoti)) {
+ break;
+ }
+ }
+ snprintf(title, BUF_MAX, "%s", usbNoti->title);
+ content = usbNoti->content;
+ iconPath = usbNoti->iconPath;
+ applist = usbNoti->applist;
+
+ } else { /* cnt >= 3 */
+ snprintf(title, BUF_MAX, "%d USB devices connected", cnt - 1);
+ USB_LOG("title: %s", title);
+ content = "Tap to show devices";
+ iconPath = USB_ICON_PATH;
+ applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY;
+ }
+
+ /* Set nofification info (title, content, icon, applist) */
+ ret = um_set_notification_info(noti, title, content, iconPath, applist);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_set_notification_info()");
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ /* Update notification */
+ noti_err = notification_update(noti);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_update(): %d", noti_err);
+ noti_err = notification_free(noti);
+ if (noti_err != NOTIFICATION_ERROR_NONE)
+ USB_LOG("FAIL: notification_free(noti)");
+ return -1;
+ }
+
+ noti_err = notification_free(noti);
+ if(noti_err != NOTIFICATION_ERROR_NONE) {
+ USB_LOG("FAIL: notification_insert(): %d", noti_err);
+ }
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_remove_separate_notification_mass_storage(UmMainData *ad,
+ int notiType,
+ void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ int privId = -1;
+ int ret = -1;
+ UsbNotification *usbNoti = NULL;
+ GList *l = NULL;
+ char *devName = (char *)device;
+
+ if (notiType != USB_NOTI_MASS_STORAGE_REMOVED) {
+ USB_LOG("ERROR: notiType (%d) is improper", notiType);
+ return -1;
+ }
+
+ ret = show_noti_list(ad, ad->notiMSList);
+ if (ret < 0) USB_LOG("FAIL: show_noti_list()");
+
+ for (l = ad->notiMSList ; l ; l = g_list_next(l)) {
+ usbNoti = (UsbNotification *)(l->data);
+ if (!usbNoti) {
+ USB_LOG("FAIL: usbNoti == NULL");
+ return -1;
+ }
+ USB_LOG("privId: %d", usbNoti->privId);
+ if (true == cmp_dev_noti(notiType, usbNoti, devName)) {
+ privId = um_remove_notification(ad, notiType, usbNoti->privId);
+ um_retvm_if(privId < 0, -1, "FAIL: um_remove_notification()");
+ ad->notiMSList = g_list_delete_link(ad->notiMSList, l);
+ break;
+ }
+ }
+
+ ret = show_noti_list(ad, ad->notiMSList);
+ if (ret < 0) USB_LOG("FAIL: show_noti_list()");
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_remove_separate_notification(UmMainData *ad, int notiType, void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ int privId = -1;
+
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_REMOVED:
+ privId = um_remove_separate_notification_mass_storage(ad, notiType, device);
+ if (privId < 0) {
+ USB_LOG("FAIL: um_remove_separate_notification_mass_storage()");
+ return -1;
+ }
+ break;
+ default:
+ USB_LOG("This noti type does not support multi notification");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_remove_cumulative_notification_host_acc(UmMainData *ad,
+ int notiType,
+ void *device,
+ GList **rmList)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+ assert(rmList);
+
+ int privId = -1;
+ UsbInterface *devIf = NULL;
+ UsbAccessory *accDev = NULL;
+ UsbNotification *usbNoti = NULL;
+ GList *notiList = NULL;
+ GList *l = NULL;
+
+ switch (notiType) {
+ case USB_NOTI_HOST_REMOVED:
+ notiList = ad->notiHostList;
+ devIf = (UsbInterface *)device;
+ if (devIf->ifClass == USB_HOST_HUB) return 0;
+ break;
+ case USB_NOTI_ACC_REMOVED:
+ notiList = ad->notiAccList;
+ accDev = (UsbAccessory *)device;
+ break;
+ default:
+ USB_LOG("This noti type does not support multi notification");
+ return -1;
+ }
+
+ for (l = notiList ; l ; l = g_list_next(l)) {
+ usbNoti = (UsbNotification *)(l->data);
+ if (true == cmp_dev_noti(notiType, usbNoti, device)) {
+ privId = um_update_remove_notification(ad,
+ notiType,
+ usbNoti->privId,
+ device);
+ um_retvm_if(privId < 0, -1, "FAIL: um_update_notification()");
+ *rmList = l;
+ break;
+ }
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+static int um_remove_cumulative_notification(UmMainData *ad, int notiType, void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ int privId = -1;
+ GList *rmList = NULL;
+
+ privId = um_remove_cumulative_notification_host_acc(ad, notiType, device, &rmList);
+ if (privId < 0 || !rmList) {
+ USB_LOG("FAIL: um_remove_cumulative_notification_host_acc()");
+ return -1;
+ }
+
+ switch (notiType) {
+ case USB_NOTI_HOST_REMOVED:
+ ad->notiHostList = g_list_delete_link(ad->notiHostList, rmList);
+ break;
+ case USB_NOTI_ACC_REMOVED:
+ ad->notiAccList = g_list_delete_link(ad->notiAccList, rmList);
+ break;
+ default:
+ break;
+ }
+
+ __USB_FUNC_EXIT__;
+ return privId;
+}
+
+int um_remove_host_notification(UmMainData *ad, int notiType, void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ int privId = -1;
+
+ switch (notiType) {
+ case USB_NOTI_MASS_STORAGE_REMOVED:
+ privId = um_remove_separate_notification(ad, notiType, device);
+ um_retvm_if(privId < 0, -1, "FAIL: um_remove_separate_notification()");
+ break;
+ case USB_NOTI_HOST_REMOVED:
+ privId = um_remove_cumulative_notification(ad, notiType, device);
+ um_retvm_if(privId < 0, -1, "FAIL: um_remove_cumulative_notification()");
+ break;
+ default:
+ break;
+ }
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+int um_remove_client_notification(UmMainData *ad, int notiType, void *device)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+ assert(device);
+
+ if (notiType != USB_NOTI_ACC_REMOVED) {
+ USB_LOG("ERROR: This function is just for usb accessory");
+ return -1;
+ }
+ int privId = -1;
+
+ privId = um_remove_cumulative_notification(ad, notiType, device);
+ um_retvm_if(privId < 0, -1, "FAIL: um_remove_cumulative_notification()");
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+int um_remove_all_client_notification(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+
+ int cnt = -1;
+ int i = -1;
+ int ret = -1;
+ UsbNotification *usbNoti = NULL;
+
+ if (ad->notiAccList) {
+ cnt = g_list_length(ad->notiAccList);
+ for (i = 0 ; i < cnt ; i++) {
+ usbNoti = (UsbNotification *)g_list_nth_data(ad->notiAccList, i);
+ ret = um_remove_client_notification(ad, 0, usbNoti->accDev);
+ if (ret < 0) USB_LOG("FAIL: um_remove_client_notification()");
+ }
+ }
+
+ g_list_free_full(ad->notiAccList, release_usb_notification);
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+int um_remove_all_host_notification(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__ ;
+ assert(ad);
+
+ int cnt = -1;
+ int i = -1;
+ int ret = -1;
+ UsbNotification *usbNoti = NULL;
+
+ if (ad->notiHostList) {
+ cnt = g_list_length(ad->notiHostList);
+ for (i = 0 ; i < cnt ; i++) {
+ usbNoti = (UsbNotification *)g_list_nth_data(ad->notiHostList, i);
+ ret = um_remove_host_notification(ad, 0, usbNoti->devIf);
+ if (ret < 0) USB_LOG("FAIL: um_remove_host_notification()");
+ }
+ }
+
+ if (ad->notiMSList) {
+ cnt = g_list_length(ad->notiMSList);
+ for (i = 0 ; i < cnt ; i++) {
+ usbNoti = (UsbNotification *)g_list_nth_data(ad->notiMSList, i);
+ ret = um_remove_host_notification(ad,
+ USB_HOST_MASS_STORAGE,
+ usbNoti->devName);
+ if (ret < 0) USB_LOG("FAIL: um_remove_host_notification()");
+ }
+ }
+
+ g_list_free_full(ad->notiHostList, release_usb_notification);
+ g_list_free_full(ad->notiMSList, release_usb_notification);
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
#include <vconf.h>
#include <signal.h>
+#define LIBUSB_WAIT 1000000 /* Wait for 1 sec */
+#define FAIL_WAIT 100000 /* Wait for 0.1 sec */
+
char *tempAppId;
int tempVendor, tempProduct;
static struct sigaction sig_pipe_old_act;
+static void um_usb_server_release_handler(UmMainData *ad);
+static void um_usbhost_vconf_key_ignore(UmMainData *ad);
+static void um_usbclient_vconf_key_ignore(UmMainData *ad);
+static Eina_Bool answer_to_ipc(void *data, Ecore_Fd_Handler *fd_handler);
+
static void sig_pipe_handler(int signo, siginfo_t *info, void *data)
{
__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;
-}
-
-int um_heynoti_remove(int fd, char *noti, void (*cb)(void *))
+static void terminate_usbclient_connection(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!noti) return -1;
- if (!cb) return -1;
- if (heynoti_unsubscribe(fd, noti, cb) < 0) {
- USB_LOG("ERROR: heynoti_unsubscribe() \n");
- }
- if (heynoti_detach_handler(fd) < 0) {
- USB_LOG("ERROR: heynoti_detach_handler() \n");
- }
- heynoti_close(fd);
- __USB_FUNC_EXIT__;
- return 0;
-}
+ assert(ad);
-static int terminate_usbclient_connection(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
- int status = -1;
+ int ret;
+ int status;
- ret = um_usb_server_release_handler(ad);
- if (0 > ret) USB_LOG("FAIL: um_usb_server_release_handler(ad)\n");
+ um_uevent_control_stop(ad);
- ret = um_usbclient_vconf_key_ignore(ad);
- if (0 > ret) USB_LOG("FAIL: um_usbclient_vconf_key_ignore(ad)");
+ um_usb_server_release_handler(ad);
- ret = um_usbclient_heynoti_unsubscribe(ad);
- if (0 > ret) USB_LOG("FAIL: um_usbclient_heynoti_unsubscribe(ad)");
+ um_usbclient_vconf_key_ignore(ad);
- ret = disconnectUsbClient(ad);
- if(0 != ret) USB_LOG("FAIL: disconnectUsbClient(ad)");
+ disconnectUsbClient(ad);
/* If USB accessory is removed, the vconf value of accessory status should be updated */
ret = vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &status);
if (0 == ret && VCONFKEY_USB_ACCESSORY_STATUS_CONNECTED == status) {
ret = vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS,
VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED);
- if(0 != ret) USB_LOG("FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS");
- ret = disconnectAccessory(ad);
- if(0 != ret) USB_LOG("FAIL: disconnectAccessory(ad)\n");
+ if(0 != ret)
+ USB_LOG("FAIL: vconf_set_int(VCONFKEY_USB_ACCESSORY_STATUS");
+ disconnect_accessory(ad);
}
+ FREE(ad->usbAcc);
+
ecore_main_loop_quit();
__USB_FUNC_EXIT__;
- return 0;
}
-static int terminate_usbhost_connection(UmMainData *ad)
+static void terminate_usbhost_connection(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
+ assert(ad);
- ret = um_usb_server_release_handler(ad);
- if (0 > ret) USB_LOG("FAIL: um_usb_server_release_handler(ad)\n");
+ um_uevent_control_stop(ad);
- ret = um_usbhost_vconf_key_ignore(ad);
- if (0 > ret) USB_LOG("FAIL: um_usbhost_vconf_key_ignore(ad)");
+ um_usb_server_release_handler(ad);
- ret = um_usbhost_heynoti_unsubscribe(ad);
- if (0 > ret) USB_LOG("FAIL: um_usbhost_heynoti_unsubscribe(ad)");
+ um_usbhost_vconf_key_ignore(ad);
- ret = disconnectUsbHost(ad);
- if (0 != ret) USB_LOG("FAIL: disconnectUsbHost(ad)");
+ disconnect_usb_host(ad);
ecore_main_loop_quit();
__USB_FUNC_EXIT__;
- return 0;
}
static void um_usbclient_chgdet_cb(keynode_t *in_key, void *data)
{
__USB_FUNC_ENTER__;
- if (!data) return;
+ assert(data);
+
UmMainData *ad = (UmMainData *)data;
- int status = -1;
- int ret = -1;
+ int status;
+ int ret;
+
status = check_usbclient_connection();
switch(status) {
case USB_CLIENT_DISCONNECTED:
- ret = terminate_usbclient_connection(ad);
- um_retm_if(0 != ret, "FAIL: terminate_usbclient_connection(ad)");
+ terminate_usbclient_connection(ad);
break;
+
case USB_CLIENT_CONNECTED:
ret = connectUsbClient(ad);
- um_retm_if(0 != ret, "FAIL: connectUsbClient(ad)");
- if (USB_CLIENT_DISCONNECTED == check_usbclient_connection()) {
- ret = terminate_usbclient_connection(ad);
- um_retm_if(0 != ret, "FAIL: terminate_usbclient_connection(ad)\n");
+ if (0 != ret) {
+ USB_LOG("FAIL: connectUsbClient(ad)");
+ return;
}
+
+ if (USB_CLIENT_DISCONNECTED != check_usbclient_connection())
+ break;
+
+ terminate_usbclient_connection(ad);
break;
+
default:
break;
}
__USB_FUNC_EXIT__;
}
-static void um_usbclient_acc_chgdet_cb(void *data)
+static void um_usbhost_chgdet_cb(keynode_t *in_key, void *data)
{
__USB_FUNC_ENTER__;
- if (!data) return;
- UmMainData *ad = (UmMainData *)data;
+
+ UmMainData *ad;
int status;
- int ret;
- status = check_usbclient_connection();
- if (USB_CLIENT_CONNECTED == status) {
- 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_ACCESSORY_STATUS)\n");
- if (VCONFKEY_USB_ACCESSORY_STATUS_DISCONNECTED == status) {
- ret = connectAccessory(ad);
- um_retm_if(ret != 0, "FAIL: connectAccessory(ad)\n");
-
- 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)");
- }
- }
- __USB_FUNC_EXIT__;
-}
-static void um_usbhost_chgdet_cb(keynode_t *in_key, void *data)
-{
- __USB_FUNC_ENTER__;
- if (!data) return;
- UmMainData *ad = (UmMainData *)data;
- int ret = -1;
- int status = check_usbhost_connection();
+ if (!data)
+ return;
- if (USB_HOST_DISCONNECTED == status) {
- ret = terminate_usbhost_connection(ad);
- um_retm_if(0 > ret, "FAIL: terminnate_usbhost_connection(ad)");
- }
+ ad = (UmMainData *)data;
+ status = check_usbhost_connection();
+
+ if (USB_HOST_DISCONNECTED != status)
+ return;
+
+ terminate_usbhost_connection(ad);
__USB_FUNC_EXIT__;
}
-int um_usbclient_vconf_key_notify(UmMainData *ad)
+static int um_usbclient_vconf_key_notify(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
+ assert(ad);
+
+ int ret;
+ int i;
- 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)");
+ i = 0;
+ do {
+ ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
+ um_usbclient_chgdet_cb, ad);
+ USB_LOG("vconf_notify_key_changed(): %d", ret);
+ if (0 != ret)
+ usleep(FAIL_WAIT);
+ } while (0 != ret && ++i < 10) ;
+
+ ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, change_prev_mode_cb, ad);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_notify_key_changed(SETAPPL_USB_SEL_MODE_INT)");
+ return -1;
+ }
#ifndef SIMULATOR
ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debug_mode_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_notify_key_changed(SETAPPL_USB_DEBUG_MODE_BOOL)");
+ return -1;
+ }
#endif
- ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS, um_usbclient_chgdet_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS)");
+ ret = vconf_notify_key_changed(VCONFKEY_USB_SEL_MODE, change_mode_cb, ad);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_USB_SEL_MODE)");
+ return -1;
+ }
ret = vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, change_hotspot_status_cb, ad);
- if (0 != ret) {
+ if (0 != ret)
USB_LOG("ERROR: vconf_notify_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE)");
- }
__USB_FUNC_EXIT__;
return 0;
}
-int um_usbclient_vconf_key_ignore(UmMainData *ad)
+static void um_usbclient_vconf_key_ignore(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
+ assert(ad);
+
+ int ret;
- ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, change_mode_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)");
+ ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_SEL_MODE_INT, change_prev_mode_cb);
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT)");
ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS, um_usbclient_chgdet_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS)");
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS)");
ret = vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE, change_hotspot_status_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE)");
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_MOBILE_HOTSPOT_MODE)");
#ifndef SIMULATOR
ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debug_mode_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL)");
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_USB_DEBUG_MODE_BOOL)");
#endif
- __USB_FUNC_EXIT__;
- return 0;
-}
-
-int um_usbhost_vconf_key_notify(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
-
- ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS,
- um_usbhost_chgdet_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS)");
-
- ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_ADDED_STORAGE_UEVENT,
- add_mass_storage_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_ADD_STORAGE_UEVENT)");
-
- ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_REMOVED_STORAGE_UEVENT,
- remove_mass_storage_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_REMOVE_STORAGE_UEVENT)");
-
- __USB_FUNC_EXIT__;
- return 0;
-}
-
-int um_usbhost_vconf_key_ignore(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
-
- ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS,
- um_usbhost_chgdet_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS)");
-
- ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_ADDED_STORAGE_UEVENT,
- add_mass_storage_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_ADD_STORAGE_UEVENT)");
-
- ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_REMOVED_STORAGE_UEVENT,
- remove_mass_storage_cb);
- if (0 != ret) USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_REMOVE_STORAGE_UEVENT)");
-
- __USB_FUNC_EXIT__;
- return 0;
-}
-
-int um_usbclient_heynoti_subscribe(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
-
- ret = um_heynoti_add(&(ad->acc_noti_fd), "device_usb_accessory",
- um_usbclient_acc_chgdet_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_heynoti_add(ad->acc_noti_fd)");
+ ret = vconf_ignore_key_changed(VCONFKEY_USB_SEL_MODE, change_mode_cb);
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_USB_SEL_MODE)");
__USB_FUNC_EXIT__;
- return 0;
-}
-
-int um_usbclient_heynoti_unsubscribe(UmMainData *ad)
-{
- __USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
-
- ret = um_heynoti_remove(ad->acc_noti_fd, "device_usb_accessory",
- um_usbclient_acc_chgdet_cb);
- if (0 != ret) USB_LOG("FAIL: um_heynoti_remove(ad->acc_noti_fd)");
-
- __USB_FUNC_EXIT__;
- return 0;
}
-int um_usbhost_heynoti_subscribe(UmMainData *ad)
+static int um_usbhost_vconf_key_notify(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
+ assert(ad);
- ret = um_heynoti_add(&(ad->host_add_noti_fd), "device_usb_host_add",
- add_host_noti_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_heynoti_add(ad->host_add_noti_fd)");
+ int ret;
- ret = um_heynoti_add(&(ad->host_remove_noti_fd), "device_usb_host_remove",
- remove_host_noti_cb, ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_heynoti_add(ad->host_remove_noti_fd)");
+ ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS,
+ um_usbhost_chgdet_cb, ad);
+ if (0 != ret) {
+ USB_LOG("FAIL: vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS)");
+ return -1;
+ }
__USB_FUNC_EXIT__;
return 0;
}
-int um_usbhost_heynoti_unsubscribe(UmMainData *ad)
+static void um_usbhost_vconf_key_ignore(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
+ assert(ad);
- ret = um_heynoti_remove(ad->host_add_noti_fd, "device_usb_host_add",
- add_host_noti_cb);
- if (0 != ret) USB_LOG("FAIL: um_heynoti_remove(ad->host_add_noti_fd)");
+ int ret;
- ret = um_heynoti_remove(ad->host_remove_noti_fd, "device_usb_host_remove",
- remove_host_noti_cb);
- if (0 != ret) USB_LOG("FAIL: um_heynoti_remove(ad->host_remove_noti_fd)");
+ ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS,
+ um_usbhost_chgdet_cb);
+ if (0 != ret)
+ USB_LOG("FAIL: vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_HOST_STATUS)");
__USB_FUNC_EXIT__;
- return 0;
}
-int um_usb_server_register_handler(UmMainData *ad)
+static int um_usb_server_register_handler(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
+ assert(ad);
/* Init server socket for IPC with Accessroy apps and Host apps */
- ad->server_sock_local = ipc_request_server_init();
- um_retvm_if(0 > ad->server_sock_local, -1, "FAIL: ipc_request_server_init()\n");
+ ad->serverSock = ipc_request_server_init();
+ if (0 > ad->serverSock) {
+ USB_LOG("FAIL: ipc_request_server_init()");
+ return -1;
+ }
/* Add fd handler for pipe between main thread and IPC thread */
- 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()");
+ ad->ipcRequestServerFdHandler = ecore_main_fd_handler_add(ad->serverSock,
+ ECORE_FD_READ, answer_to_ipc, ad, NULL, NULL);
+ if (NULL == ad->ipcRequestServerFdHandler) {
+ USB_LOG("FAIL: ecore_main_fd_handler_add()");
+ close(ad->serverSock);
+ return -1;
+ }
__USB_FUNC_EXIT__;
return 0;
}
-int um_usb_server_release_handler(UmMainData *ad)
+static void um_usb_server_release_handler(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
+ assert(ad);
/* Remove fd handler for pipe between main thread and IPC thread */
- if (ad->ipcRequestServerFdHandler != NULL) {
+ if (ad->ipcRequestServerFdHandler) {
ecore_main_fd_handler_del(ad->ipcRequestServerFdHandler);
ad->ipcRequestServerFdHandler = NULL;
}
/* Close server socket for IPC with Accessroy apps and Host apps */
- ipc_request_server_close(ad);
+ close(ad->serverSock);
__USB_FUNC_EXIT__;
- return 0;
}
#ifndef SIMULATOR
-int um_usbclient_value_init(UmMainData *ad)
+static void um_usbclient_value_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
- int debugMode = 0;
+ assert(ad);
+
+ int ret;
+ int debugMode;
ret = vconf_get_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, &debugMode);
if (ret < 0) {
/* Set debug mode to true to find problems */
debugMode = 1;
ret = vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debugMode);
- if (ret < 0) USB_LOG("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL()");
+ if (ret < 0)
+ USB_LOG("FAIL: vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL()");
}
- if (debugMode == 1) {
- ad->prevDebugMode = true;
- ad->curDebugMode = true;
- } else if (debugMode == 0) {
+
+ if (debugMode == 0) {
ad->prevDebugMode = false;
ad->curDebugMode = false;
} else {
- USB_LOG("debugMode %d is improper");
- return -1;
+ ad->prevDebugMode = true;
+ ad->curDebugMode = true;
}
- umAccInfoInit(ad);
+ accessory_info_init(ad);
__USB_FUNC_EXIT__;
- return 0;
}
#else
-int um_usbclient_value_init(UmMainData *ad)
+static void um_usbclient_value_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- umAccInfoInit(ad);
+ assert(ad);
+ accessory_info_init(ad);
__USB_FUNC_EXIT__;
- return 0;
}
#endif
-int um_usbhost_device_list_init(UmMainData *ad)
+static void um_usbhost_device_list_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if(!ad) return -1;
- int ret = -1;
- int status;
- int defNumDevices;
+ assert(ad);
+
+ int ret;
+
ret = get_default_usb_device(ad);
if (ret < 0) {
USB_LOG("FAIL: get_default_usb_device()");
}
- show_all_usb_devices(ad->defaultDevList, 1);
+ show_all_usb_devices(ad->defaultDevList);
ad->devList = NULL;
__USB_FUNC_EXIT__;
- return 0;
}
-int noti_selected_btn(UmMainData *ad, int input)
+static int noti_selected_btn(UmMainData *ad, int input)
{
__USB_FUNC_ENTER__;
- int sock_remote = -1;
+ assert(ad);
+
+ int sockFd;
char buf[SOCK_STR_LEN];
- int ret = -1;
- int ipc_result = -1;
+ int ret;
+ int ipc_result;
switch (input) {
case REQ_ACC_PERM_NOTI_YES_BTN:
- ret = grantAccessoryPermission(ad, tempAppId);
+ ret = grant_accessory_permission(ad, tempAppId);
if (0 != ret) {
- USB_LOG("FAIL: grant_permission_to_app(appId)");
+ USB_LOG("FAIL: grant_accessory_permission(appId)");
}
break;
case REQ_HOST_PERM_NOTI_YES_BTN:
- ret = grantHostPermission(ad, tempAppId, tempVendor, tempProduct);
+ ret = grant_host_permission(ad, tempAppId, tempVendor, tempProduct);
if (0 != ret) {
- USB_LOG("grandHostPermission()\n");
+ USB_LOG("grand_host_permission()");
}
break;
default:
FREE(tempAppId);
tempVendor = 0;
tempProduct = 0;
- 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);
- if (ret == 0) {
- ipc_result = atoi(buf);
+
+ sockFd = ipc_noti_server_init();
+ um_retvm_if(sockFd < 0, -1, "FAIL: ipc_noti_server_init()");
+
+ ret = notice_to_client_app(sockFd, input, buf, sizeof(buf));
+ if (0 != ret) {
+ close(sockFd);
+ return -1;
}
- ret = ipc_noti_server_close(&sock_remote);
- um_retvm_if(ret < 0, -1, "FAIL: ipc_socket_client_close(&sock_remote)\n");
+
+ close(sockFd);
+
+ ipc_result = atoi(buf);
if (IPC_SUCCESS != ipc_result) {
return -1;
}
+
__USB_FUNC_EXIT__;
return 0;
}
static int divide_str(char* str1, char** str2)
{
__USB_FUNC_ENTER__;
- if(!str1 || !str2) return -1;
+ assert(str1);
+ assert(str2);
+
char *tmp = str1;
- if (str1) {
- while (*tmp++) {
- if('|' == *tmp) {
- *tmp = '\0';
- tmp++;
- break;
- }
- USB_LOG("#");
+ while (*tmp++) {
+ if('|' == *tmp) {
+ *tmp = '\0';
+ tmp++;
+ break;
}
+ USB_LOG("#");
}
*str2 = tmp;
__USB_FUNC_EXIT__;
return 0;
}
-Eina_Bool answer_to_ipc(void *data, Ecore_Fd_Handler *fd_handler)
+static Eina_Bool answer_to_ipc(void *data, Ecore_Fd_Handler *fd_handler)
{
__USB_FUNC_ENTER__;
- if (!data) return ECORE_CALLBACK_RENEW;
+ assert(data);
+
UmMainData *ad = (UmMainData *)data;
char str[SOCK_STR_LEN];
- int fd, input, output, t, n;
+ int fd, input, n;
+ int sockFd;
+ socklen_t t;
int ret = -1;
struct sockaddr_un remote;
char *appId = NULL;
+ char *device = NULL;
char *strVendor = NULL;
char *strProduct = NULL;
int vendor = -1;
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");
+ if ((sockFd
+ = accept(ad->serverSock, (struct sockaddr *)&remote, &t)) == -1) {
+ USB_LOG("FAIL: accept(ad->serverSock, (struct sockaddr *)&remote, &t)\n");
return ECORE_CALLBACK_RENEW;
}
- n = recv(ad->server_sock_remote, str, SOCK_STR_LEN, 0);
+
+ n = recv(sockFd, str, sizeof(str), 0);
if (n <= 0) {
- snprintf(str, SOCK_STR_LEN, "ERROR");
+ snprintf(str, sizeof(str), "ERROR");
} else {
- if (n < SOCK_STR_LEN) {
+ if (n < sizeof(str)) {
str[n] = '\0';
- } else { /* n == SOCK_STR_LEN */
- str[SOCK_STR_LEN-1] = '\0';
+ } else { /* n == sizeof(str) */
+ str[sizeof(str)-1] = '\0';
}
USB_LOG("[SERVER] Received value: %s", str);
ret = divide_str(str, &appId);
product = atoi(strProduct);
USB_LOG("appId: %s, vendor: %d, product: %d\n", appId, vendor, product);
break;
+ case UNMOUNT_USB_STORAGE:
+ device = appId;
+ break;
default:
break;
}
switch(input) {
case LAUNCH_APP_FOR_ACC:
- ret = grantAccessoryPermission(ad, appId);
+ ret = grant_accessory_permission(ad, appId);
if (0 != ret) {
- USB_LOG("FAIL: grant_permission_to_app(appId)");
- snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ USB_LOG("FAIL: grant_accessory_permission(appId)");
+ snprintf(str, sizeof(str), "%d", IPC_ERROR);
break;
}
- ret = launch_acc_app(ad->permittedPkgForAcc);
+ ret = launch_acc_app(ad->permAccAppId);
if (0 != ret) {
- USB_LOG("FAIL: launch_app(appId)");
- snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ USB_LOG("FAIL: launch_acc_app(appId)");
+ snprintf(str, sizeof(str), "%d", IPC_ERROR);
break;
}
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
case REQ_ACC_PERMISSION:
tempAppId = strdup(appId);
USB_LOG("tempAppId: %s\n", tempAppId);
- load_system_popup(ad, REQ_ACC_PERM_POPUP);
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ launch_usb_syspopup(ad, REQ_ACC_PERM_POPUP, NULL);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
case HAS_ACC_PERMISSION:
- if (EINA_TRUE == hasAccPermission(ad, appId)) {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ if (true == has_accessory_permission(ad, appId)) {
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
} else {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_FAIL);
+ snprintf(str, sizeof(str), "%d", IPC_FAIL);
}
break;
case REQ_ACC_PERM_NOTI_YES_BTN:
case REQ_ACC_PERM_NOTI_NO_BTN:
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%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",
+ snprintf(str, sizeof(str), "%s|%s|%s|%s|%s|%s",
ad->usbAcc->manufacturer,
ad->usbAcc->model,
ad->usbAcc->description,
break;
case ERROR_POPUP_OK_BTN:
usb_connection_selected_btn(ad, input);
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
case LAUNCH_APP_FOR_HOST:
- ret = grantHostPermission(ad, appId, vendor, product);
+ ret = grant_host_permission(ad, appId, vendor, product);
if (0 != ret) {
USB_LOG("FAIL: grandHostPermission()\n");
- snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ snprintf(str, sizeof(str), "%d", IPC_ERROR);
break;
}
ret = launch_host_app(appId);
if (0 != ret) {
USB_LOG("FAIL: launch_host_app(appId)\n");
- snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ snprintf(str, sizeof(str), "%d", IPC_ERROR);
break;
}
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
case REQ_HOST_PERMISSION:
tempAppId = strdup(appId);
tempVendor = vendor;
tempProduct = product;
- load_system_popup(ad, REQ_HOST_PERM_POPUP);
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ launch_usb_syspopup(ad, REQ_HOST_PERM_POPUP, NULL);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
case HAS_HOST_PERMISSION:
- if (EINA_TRUE == hasHostPermission(ad, appId, vendor, product)) {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ if (EINA_TRUE == has_host_permission(ad, appId, vendor, product)) {
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
} else {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_FAIL);
+ snprintf(str, sizeof(str), "%d", IPC_FAIL);
}
break;
case REQ_HOST_PERM_NOTI_YES_BTN:
case REQ_HOST_PERM_NOTI_NO_BTN:
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
ret = noti_selected_btn(ad, input);
if (ret < 0) USB_LOG("FAIL: noti_selected_btn(input)\n");
break;
case REQ_HOST_CONNECTION:
if (EINA_TRUE == is_host_connected(ad, vendor, product)) {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
} else {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_FAIL);
+ snprintf(str, sizeof(str), "%d", IPC_FAIL);
}
break;
case IS_EMUL_BIN:
if (is_emul_bin()) {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_SUCCESS);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
} else {
- snprintf(str, SOCK_STR_LEN, "%d", IPC_FAIL);
+ snprintf(str, sizeof(str), "%d", IPC_FAIL);
+ }
+ break;
+ case UNMOUNT_USB_STORAGE:
+ if (!device) {
+ snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ break;
}
+ um_uevent_mass_storage_removed(ad, device);
+ snprintf(str, sizeof(str), "%d", IPC_SUCCESS);
break;
default:
- snprintf(str, SOCK_STR_LEN, "%d", IPC_ERROR);
+ snprintf(str, sizeof(str), "%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");
+ if(send(sockFd, str, strlen(str)+1, 0) < 0) {
+ USB_LOG("FAIL: send(sockFd, str, strlen(str)+1, 0)\n");
}
__USB_FUNC_EXIT__;
static int um_usbclient_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
+ assert(ad);
+
+ int ret;
ad->isHostOrClient = USB_DEVICE_CLIENT;
+ ad->notiAccList = NULL;
+ ad->usbAcc = (UsbAccessory*)malloc(sizeof(UsbAccessory));
+ if (!(ad->usbAcc)) {
+ USB_LOG("FAIL: malloc()");
+ return -1;
+ }
- ret = um_usbclient_value_init(ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_usbclient_value_init(ad)");
+ um_usbclient_value_init(ad);
ret = check_driver_version(ad);
um_retvm_if(0 != ret, -1, "FAIL: check_driver_version(ad)");
ret = um_usbclient_vconf_key_notify(ad);
um_retvm_if(0 != ret, -1, "FAIL: um_vconf_key_notify(ad)");
- ret = um_usbclient_heynoti_subscribe(ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_usbclient_heynoti_subscribe(ad)");
+ ret = um_uevent_control_start(ad, USB_DEVICE_CLIENT);
+ um_retvm_if(0 != ret, -1, "FAIL: um_uevent_control_start(ad)");
+
um_usbclient_chgdet_cb(NULL, ad);
static int um_usbhost_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- if (!ad) return -1;
- int ret = -1;
+ assert(ad);
+
+ int ret;
+ int i;
ad->isHostOrClient = USB_DEVICE_HOST;
+ ad->notiHostList = NULL;
+ ad->notiMSList = NULL;
+ ad->devList = NULL;
+ ad->defaultDevList = NULL;
+ ad->devMSList = NULL;
+ ad->addHostTimer = NULL;
+ ad->rmHostTimer = NULL;
ad->usbctx = NULL;
- int i = 0;
+ ad->tmpfsMounted = false;
+
+ i = 0;
do {
ret = libusb_init(&(ad->usbctx));
USB_LOG("libusb_init() return value : %d", ret);
if (i > 10) {
USB_LOG("FAIL: libusb_init()");
- load_connection_popup(ad, "Error: Remove and reconnect USB device",
- TICKERNOTI_ORIENTATION_TOP);
+ load_connection_popup("Error: Remove and reconnect USB device");
return 1;
} else {
i++;
USB_LOG("Wait...");
- sleep(1);
+ usleep(LIBUSB_WAIT);
}
} while(ret != 0);
/* Getting default device list */
- ret = um_usbhost_device_list_init(ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_usbhost_device_list_init(ad)");
+ um_usbhost_device_list_init(ad);
ret = um_usbhost_vconf_key_notify(ad);
um_retvm_if(0 != ret, -1, "FAIL: um_usbhost_vconf_key_notify(ad)");
- ret = um_usbhost_heynoti_subscribe(ad);
- um_retvm_if(0 != ret, -1, "FAIL: um_usbclient_heynoti_subscribe(ad)");
+ ret = um_uevent_control_start(ad, USB_DEVICE_HOST);
+ um_retvm_if(0 != ret, -1, "FAIL: um_uevent_control_start(ad)");
if (USB_HOST_DISCONNECTED == check_usbhost_connection()) {
um_usbhost_chgdet_cb(NULL, ad);
return 1; /* USB host is not available */
- } else {
- load_connection_popup(ad, "IDS_COM_POP_USB_CONNECTOR_CONNECTED", TICKERNOTI_ORIENTATION_TOP);
}
- /* Check devices which is connected before init process */
- ret = add_usb_device_to_list(ad);
- um_retvm_if(0 != ret, -1, "FAIL: add_usb_device_to_list(ad)");
+ load_connection_popup("IDS_COM_POP_USB_CONNECTOR_CONNECTED");
+ /* Check devices which is connected before init process */
+ um_uevent_usb_host_added(ad);
__USB_FUNC_EXIT__;
return 0;
int um_usb_server_init(UmMainData *ad)
{
__USB_FUNC_ENTER__;
- /* In case that heynoties are subscribed after a noti arrives,
- * check whether or not a noti already arrived and do something */
- if(!ad) return -1;
+ assert(ad);
+
int ret = -1;
pm_change_state(LCD_NORMAL);
if (USB_CLIENT_CONNECTED == check_usbclient_connection()) {
USB_LOG("USB cable is connected");
ret = um_usbclient_init(ad);
- um_retvm_if(0 > ret, -1, "FAIL: um_usbclient_init(ad)");
+ um_retvm_if(0 > ret, -1, "FAIL: um_usbclient_init(ad)");
} else {
if (USB_HOST_CONNECTED == check_usbhost_connection()) {
USB_LOG("USB host is connected");
--- /dev/null
+/*
+ * usb-manager
+ * Copyright (c) 2012 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 "um_usb_uevent_handler.h"
+
+#define UEVENT_BUF_MAX (128*1024*1024)
+#define UDEV_MON_UDEV "udev"
+#define UDEV_ENTRY_NAME_SUBSYSTEM "SUBSYSTEM"
+#define UDEV_ENTRY_NAME_ACTION "ACTION"
+#define UDEV_ENTRY_NAME_DEVTYPE "DEVTYPE"
+#define UDEV_ENTRY_NAME_DEVNAME "DEVNAME"
+#define UDEV_ENTRY_NAME_NPARTS "NPARTS"
+#define UDEV_ENTRY_NAME_ACCESSORY "ACCESSORY"
+
+#define UDEV_SUBSYSTEM_BLOCK "block"
+#define UDEV_SUBSYSTEM_USB_DEVICE "usb_device"
+#define UDEV_SUBSYSTEM_USB "usb"
+#define UDEV_SUBSYSTEM_MISC "misc"
+#define UDEV_ACTION_ADD "add"
+#define UDEV_ACTION_REMOVE "remove"
+#define UDEV_ACTION_CHANGE "change"
+#define UDEV_DEVTYPE_DISK "disk"
+#define UDEV_DEVTYPE_PARTITION "partition"
+#define UDEV_ACCESSORY_START "START"
+
+static int um_event_control_get_value_by_name(struct udev_list_entry *list_entry,
+ char *name, char **value)
+{
+ __USB_FUNC_ENTER__;
+ assert(list_entry);
+ assert(name);
+ assert(value);
+
+ const char *localValue = NULL;
+ struct udev_list_entry *entry_found = NULL;
+ entry_found = udev_list_entry_get_by_name(list_entry, name);
+ if (!entry_found) {
+ USB_LOG("FAIL: udev_list_entry_get_by_name(%s)", name);
+ return -1;
+ }
+ localValue = udev_list_entry_get_value(entry_found);
+ if (!localValue) {
+ USB_LOG("FAIL: udev_list_entry_get_value(%s)", name);
+ return -1;
+ }
+ USB_LOG("%s: %s", name, localValue);
+
+ *value = strdup(localValue);
+ if (*value == NULL) {
+ USB_LOG("FAIL: strdup()");
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+static int um_uevent_control_usb_storage_action(UmMainData *ad,
+ char *action,
+ char *devname,
+ char *fstype)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(action);
+ assert(devname);
+ assert(fstype);
+
+ if (!strcmp(action, UDEV_ACTION_ADD)) {
+ USB_LOG("Mass storage is added");
+ um_uevent_mass_storage_added(ad, (char *)devname, fstype);
+ __USB_FUNC_EXIT__;
+ return 0;
+
+ }
+
+ if (!strcmp(action, UDEV_ACTION_REMOVE)) {
+ USB_LOG("Mass storage is removed");
+ um_uevent_mass_storage_removed(ad, (char *)devname);
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+
+ USB_LOG("ERROR: Action (%s) is improper", action);
+ __USB_FUNC_EXIT__;
+ return -1;
+}
+
+static int um_uevent_control_subsystem_block(UmMainData *ad, struct udev_list_entry *list_entry)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(list_entry);
+
+ int ret = -1;
+ char *action = NULL; /* add, remove, ... */
+ char *devname = NULL; /* /dev/sda, /dev/sda1, ... */
+ char *fstype = NULL; /* vfat, ... */
+ char *fsversion = NULL; /* fat, fat32, ntfs, ... */
+
+ ret = um_event_control_get_value_by_name(list_entry, "ID_FS_TYPE", &fstype);
+ if (ret != 0 || !fstype) {
+ USB_LOG("ERROR: This block device cannot be mounted");
+ return 0;
+ }
+
+ ret = um_event_control_get_value_by_name(list_entry, "ID_FS_VERSION", &fsversion);
+ if (ret != 0 || !fsversion) {
+ USB_LOG("ERROR: This block device cannot be mounted");
+ FREE(fstype);
+ return 0;
+ }
+
+ /* Getting device name */
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_DEVNAME, &devname);
+ if (ret != 0 || !devname) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ goto out_fsversion;
+ }
+ USB_LOG("The device name is %s", devname);
+ if (!strstr(devname, "sd")) {
+ USB_LOG("ERROR: devname is improper");
+ goto out_devname;
+ }
+
+ /* Getting device action */
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_ACTION, &action);
+ if (ret != 0 || !action) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ goto out_action;
+ }
+ USB_LOG("The action is %s", action);
+
+ ret = um_uevent_control_usb_storage_action(ad, action, devname, fstype);
+ if (ret < 0) {
+ USB_LOG("FAIL: um_uevent_control_usb_storage_action()");
+ goto out_action;
+ }
+
+ FREE(fstype);
+ FREE(fsversion);
+ FREE(action);
+ FREE(devname);
+
+ __USB_FUNC_EXIT__;
+ return 0;
+
+out_action:
+ FREE(action);
+out_devname:
+ FREE(devname);
+out_fsversion:
+ FREE(fsversion);
+ FREE(fstype);
+ return -1;
+}
+
+static int um_uevent_control_subsystem_usb_device(UmMainData *ad, struct udev_list_entry *list_entry)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(list_entry);
+
+ int ret = -1;
+ char *action = NULL; /* add, remove, ... */
+
+ /* Getting device action */
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_ACTION, &action);
+ if (ret < 0 || !action) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ FREE(action);
+ return -1;
+ }
+ USB_LOG("The action is %s", action);
+
+ if (!strcmp(action, UDEV_ACTION_ADD)) {
+ um_uevent_usb_host_added(ad);
+ FREE(action);
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+
+ if (!strcmp(action, UDEV_ACTION_REMOVE)) {
+ um_uevent_usb_host_removed(ad);
+ FREE(action);
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+
+ USB_LOG("ERROR: action (%s) is improper", action);
+ FREE(action);
+ __USB_FUNC_EXIT__;
+ return -1;
+}
+
+static int um_uevent_control_subsystem_misc(UmMainData *ad, struct udev_list_entry *list_entry)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(list_entry);
+
+ int ret = -1;
+ char *action = NULL; /* add, remove, change ... */
+ char *accessory = NULL; /* START, ... */
+
+ /* Getting device action */
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_ACTION, &action);
+ if (ret < 0 || !action) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ FREE(action);
+ return -1;
+ }
+ USB_LOG("The action is %s", action);
+
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_ACCESSORY, &accessory);
+ if (ret < 0 || !accessory) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ FREE(accessory);
+ return -1;
+ }
+ USB_LOG("The accessory is %s", accessory);
+
+ if (!strcmp(action, UDEV_ACTION_CHANGE) && !strcmp(accessory, UDEV_ACCESSORY_START)) {
+ um_uevent_usb_accessory_added(ad);
+ FREE(action);
+ FREE(accessory);
+ __USB_FUNC_EXIT__;
+ return 0;
+ }
+
+ FREE(action);
+ FREE(accessory);
+ __USB_FUNC_EXIT__;
+ return -1;
+}
+
+static void um_uevent_control_subsystem(UmMainData *ad,
+ struct udev_list_entry *list_entry,
+ char *subsystem)
+{
+ __USB_FUNC_ENTER__;
+ assert(ad);
+ assert(list_entry);
+ assert(subsystem);
+
+ if (!strcmp(subsystem, UDEV_SUBSYSTEM_BLOCK)) {
+ if (um_uevent_control_subsystem_block(ad, list_entry) < 0)
+ USB_LOG("FAIL: um_uevent_control_subsystem_block()");
+ __USB_FUNC_EXIT__;
+ return;
+ }
+
+ if (!strcmp(subsystem, UDEV_SUBSYSTEM_USB_DEVICE)) {
+ if (um_uevent_control_subsystem_usb_device(ad, list_entry) < 0)
+ USB_LOG("FAIL: um_uevent_control_subsystem_usb_device()");
+ __USB_FUNC_EXIT__;
+ return;
+ }
+
+ if (!strcmp(subsystem, UDEV_SUBSYSTEM_MISC)) {
+ if (um_uevent_control_subsystem_misc(ad, list_entry) < 0)
+ USB_LOG("FAIL: um_uevent_control_subsystem_usb_device()");
+ __USB_FUNC_EXIT__;
+ return;
+ }
+
+ USB_LOG("ERROR: subsystem (%s) is improper", subsystem);
+ __USB_FUNC_EXIT__;
+}
+
+static Eina_Bool uevent_control_cb(void *data, Ecore_Fd_Handler *fd_handler)
+{
+ __USB_FUNC_ENTER__;
+ if (!data) return ECORE_CALLBACK_RENEW;
+ if (!fd_handler) return ECORE_CALLBACK_RENEW;
+ UmMainData *ad = (UmMainData *)data;
+ int ret = -1;
+ int i = 0;
+ struct udev_device *dev = NULL;
+ struct udev_list_entry *list_entry = NULL;
+ struct udev_list_entry *entry_found = NULL;
+ char *subsystem = NULL;
+
+ if (!ecore_main_fd_handler_active_get(ad->udevFdHandler, ECORE_FD_READ)) {
+ USB_LOG("FAIL: ecore_main_fd_handler_active_get()");
+ return ECORE_CALLBACK_RENEW;
+ }
+ dev = udev_monitor_receive_device(ad->udevMon);
+ if (!dev) {
+ USB_LOG("FAIL: udev_monitor_receive_device()");
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ /* Getting the First element of the device entry list */
+ list_entry = udev_device_get_properties_list_entry(dev);
+ if (!list_entry) {
+ USB_LOG("FAIL: udev_device_get_properties_list_entry()");
+ udev_device_unref(dev);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ ret = um_event_control_get_value_by_name(list_entry, UDEV_ENTRY_NAME_SUBSYSTEM, &subsystem);
+ if (ret < 0 || !subsystem) {
+ USB_LOG("FAIL: um_event_control_get_value_by_name()");
+ udev_device_unref(dev);
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ udev_list_entry_foreach(entry_found, list_entry) {
+ USB_LOG("::::::::::::::::::::::::::::::::");
+ USB_LOG("::: Number: %d", i);
+ USB_LOG("::: Name : %s", udev_list_entry_get_name(entry_found));
+ USB_LOG("::: value : %s", udev_list_entry_get_value(entry_found));
+ }
+ USB_LOG(":::::::::::::::::::::::::::::");
+
+ um_uevent_control_subsystem(ad, list_entry, subsystem);
+
+ udev_device_unref(dev);
+ FREE(subsystem);
+ __USB_FUNC_EXIT__;
+ return ECORE_CALLBACK_RENEW;
+}
+
+void um_uevent_control_stop(UmMainData *ad)
+{
+ __USB_FUNC_ENTER__;
+ if (!ad) return ;
+
+ if (ad->udevFdHandler) {
+ ecore_main_fd_handler_del(ad->udevFdHandler);
+ ad->udevFdHandler = NULL;
+ }
+
+ if (ad->udevFd >= 0) {
+ close(ad->udevFd);
+ ad->udevFd = -1;
+ }
+
+ if (ad->udevMon) {
+ udev_monitor_unref(ad->udevMon);
+ ad->udevMon = NULL;
+ }
+
+ if (ad->udev) {
+ udev_unref(ad->udev);
+ ad->udev = NULL;
+ }
+
+ __USB_FUNC_EXIT__;
+}
+
+int um_uevent_control_start(UmMainData *ad, int mode)
+{
+ __USB_FUNC_ENTER__;
+ if (!ad) return -1;
+ int ret = -1;
+ ad->udevFd = -1;
+
+ ad->udev = udev_new();
+ if (!(ad->udev)) {
+ USB_LOG("FAIL: udev_new()");
+ return -1;
+ }
+
+ ad->udevMon = udev_monitor_new_from_netlink(ad->udev, UDEV_MON_UDEV);
+ if (ad->udevMon == NULL) {
+ USB_LOG("FAIL: udev_monitor_new_from_netlink()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ /* The buffer size should be 128 * 1024 * 1024
+ * according to the buffer size of udev daemon */
+ ret = udev_monitor_set_receive_buffer_size(ad->udevMon, UEVENT_BUF_MAX);
+ if (ret < 0) {
+ USB_LOG("FAIL: udev_monitor_set_receive_buffer_size()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ switch (mode) {
+ case USB_DEVICE_HOST:
+ if (udev_monitor_filter_add_match_subsystem_devtype(ad->udevMon,
+ UDEV_SUBSYSTEM_BLOCK, NULL) < 0
+ || udev_monitor_filter_add_match_subsystem_devtype(ad->udevMon,
+ UDEV_SUBSYSTEM_USB, NULL) < 0
+ || udev_monitor_filter_add_match_subsystem_devtype(ad->udevMon,
+ UDEV_SUBSYSTEM_USB_DEVICE, NULL) < 0) {
+ USB_LOG("FAIL: udev_monitor_filter_add_match_subsystem_devtype()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+ break;
+
+ case USB_DEVICE_CLIENT:
+ if (udev_monitor_filter_add_match_subsystem_devtype(ad->udevMon,
+ UDEV_SUBSYSTEM_MISC, NULL) < 0) {
+ USB_LOG("FAIL: udev_monitor_filter_add_match_subsystem_devtype()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ break;
+
+ default:
+ USB_LOG("ERROR: mode (%d) is improper", mode);
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ ad->udevFd = udev_monitor_get_fd(ad->udevMon);
+ if (ad->udevFd < 0) {
+ USB_LOG("FAIL: udev_monitor_get_fd()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ ad->udevFdHandler = ecore_main_fd_handler_add(ad->udevFd, ECORE_FD_READ,
+ uevent_control_cb, ad, NULL, NULL);
+ if (ad->udevFdHandler == NULL) {
+ USB_LOG("FAIL: ecore_main_fd_handler_add()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ ret = udev_monitor_enable_receiving(ad->udevMon);
+ if (ret < 0) {
+ USB_LOG("FAIL: udev_monitor_enable_receiving()");
+ um_uevent_control_stop(ad);
+ return -1;
+ }
+
+ __USB_FUNC_EXIT__;
+ return 0;
+}
+
+++ /dev/null
-#USB accessory
-ACTION=="change" DEVPATH=="/devices/virtual/misc/usb_accessory", ENV{ACCESSORY}=="START" RUN+="/usr/bin/sys_event device_usb_accessory"