diff options
author | taeyoung <ty317.kim@samsung.com> | 2015-02-10 20:13:38 +0900 |
---|---|---|
committer | taeyoung <ty317.kim@samsung.com> | 2015-02-23 16:24:46 +0900 |
commit | ec7bef629e2ff6811292fdccb887444b8f13d3ce (patch) | |
tree | 43aa3c8e9612bc76e2a17375b50ccfc19599609c | |
parent | 54e4cc087ea8ce909f9b0179455b4e6d27ea3a49 (diff) | |
download | deviced-ec7bef629e2ff6811292fdccb887444b8f13d3ce.tar.gz deviced-ec7bef629e2ff6811292fdccb887444b8f13d3ce.tar.bz2 deviced-ec7bef629e2ff6811292fdccb887444b8f13d3ce.zip |
usb: set default usb config to usb sdb
- Default usb config is used from Tizen 1.0 to tizen 2.3.
USB nodes at sysfs are used to set usb configuration.
- Default usb config is not plugin type since it will be used
when other plugin does not exist
Change-Id: I0f1f3ed1ff128d6cb62c410529c6227981a1f5de
Signed-off-by: taeyoung <ty317.kim@samsung.com>
-rwxr-xr-x | CMakeLists.txt | 3 | ||||
-rwxr-xr-x | packaging/deviced.spec | 2 | ||||
-rw-r--r-- | src/usb/usb-default.c | 273 | ||||
-rw-r--r-- | src/usb/usb-operation.conf | 3 | ||||
-rw-r--r-- | src/usb/usb-setting.conf | 14 | ||||
-rw-r--r-- | src/usb/usb.c | 16 |
6 files changed, 299 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ff2c69f..fd657844 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ SET(SRCS SET(SRCS ${SRCS} src/usb/usb.c + src/usb/usb-default.c ) IF(TIZEN_BUZZER) @@ -189,6 +190,8 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_I INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced-pre.sh DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced.conf DESTINATION /etc/dbus-1/system.d) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/movi_format.sh DESTINATION bin) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-setting.conf DESTINATION /etc/deviced) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-operation.conf DESTINATION /etc/deviced) IF(TIZEN_SDCARD) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mmc-smack-label DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/fsck-msdos/LICENSE DESTINATION share/license RENAME fsck_msdosfs) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index fc0397fd..d18c5adf 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -317,6 +317,8 @@ systemctl daemon-reload %{_bindir}/deviced %{_bindir}/devicectl %{_bindir}/movi_format.sh +%{_sysconfdir}/deviced/usb-setting.conf +%{_sysconfdir}/deviced/usb-operation.conf %if %{with sdcard} %{_bindir}/mmc-smack-label %{_bindir}/fsck_msdosfs diff --git a/src/usb/usb-default.c b/src/usb/usb-default.c new file mode 100644 index 00000000..2154641d --- /dev/null +++ b/src/usb/usb-default.c @@ -0,0 +1,273 @@ +/* + * deviced + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include <stdio.h> +#include <string.h> + +#include "core/log.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "core/launch.h" +#include "usb.h" + +#define USB_SETTING "/etc/deviced/usb-setting.conf" +#define USB_OPERATION "/etc/deviced/usb-operation.conf" + +#define SECTION_BASE "BASE" +#define KEY_ROOTPATH "rootpath" +#define KEY_LOAD "load" +#define KEY_DEFAULT "default" +#define KEY_START "start" +#define KEY_STOP "stop" + +#define CONFIG_ENABLE "1" +#define CONFIG_DISABLE "0" + +#define BUF_MAX 128 + +struct oper_data { + char *type; + char *name; +}; + +static char config_rootpath[BUF_MAX]; +static char config_load[BUF_MAX]; +static char config_default[BUF_MAX]; + +static int write_file(char *path, char *val) +{ + FILE *fp; + int ret; + unsigned int len; + + if (!path || !val) + return -EINVAL; + + fp = fopen(path, "w"); + if (!fp) { + ret = -errno; + _E("Failed to open file (%s, errno:%d)", path, ret); + return ret; + } + + len = strlen(val); + ret = fwrite(val, sizeof(char), len, fp); + fclose(fp); + if (ret < len) { + _E("Failed to write (%s, %s)", path, val); + return -ENOMEM; + } + + return 0; +} + +static int load_setting_config(struct parse_result *result, void *user_data) +{ + char *section = user_data; + char path[BUF_MAX]; + int ret; + + if (!result || !section) + return -EINVAL; + + if (result->section == NULL || result->name == NULL) + return -EINVAL; + + if (strncmp(section, result->section, strlen(section))) + return 0; + + snprintf(path, sizeof(path), "%s/%s", config_rootpath, result->name); + ret = write_file(path, result->value); + if (ret < 0) + _E("Failed to write (%s, %s)", path, result->value); + + return ret; +} + +static int load_base_config(struct parse_result *result, void *user_data) +{ + unsigned int len; + + if (!result) + return -EINVAL; + + if (result->section == NULL || result->name == NULL) + return -EINVAL; + + if (strncmp(result->section, SECTION_BASE, sizeof(SECTION_BASE))) + return 0; + + if (!strncmp(result->name, KEY_ROOTPATH, sizeof(KEY_ROOTPATH))) { + snprintf(config_rootpath, sizeof(config_rootpath), + "%s", result->value); + _I("USB config rootpath(%s)", config_rootpath); + } + + else if (!strncmp(result->name, KEY_LOAD, sizeof(KEY_LOAD))) { + snprintf(config_load, sizeof(config_load), + "%s", result->value); + _I("USB config load(%s)", config_load); + } + + else if (!strncmp(result->name, KEY_DEFAULT, sizeof(KEY_DEFAULT))) { + snprintf(config_default, sizeof(config_default), + "%s", result->value); + _I("USB config default(%s)", config_default); + } + + return 0; +} + +static int load_operation_config(struct parse_result *result, void *user_data) +{ + struct oper_data *data = user_data; + int ret; + + if (!data || !result) + return -EINVAL; + + if (strncmp(result->section, data->type, strlen(result->section))) + return 0; + + if (strncmp(result->name, data->name, strlen(result->name))) + return 0; + + ret = launch_app_cmd(result->value); + + _I("Execute(%s: %d)", result->value, ret); + + return ret; +} + +static int usb_execute_operation(char *type, char *name) +{ + int ret; + struct oper_data data; + + if (!name) + return -EINVAL; + + if (!type) + type = config_default; + + data.name = name; + data.type = type; + + ret = config_parse(USB_OPERATION, + load_operation_config, &data); + if (ret < 0) + _E("Failed to load usb operation (%d)", ret); + + return ret; +} + +static int usb_load_configuration(char *enable) +{ + int ret; + static char buf[BUF_MAX]; + static bool node = false; + + if (!node) { + snprintf(buf, sizeof(buf), "%s/%s", + config_rootpath, config_load); + node = true; + } + + ret = write_file(buf, enable); + if (ret < 0) + _E("Failed to write (%s, %s)", buf, enable); + + return ret; +} + +static int usb_update_configuration(char *name) +{ + if (!name) + name = config_default; + + return config_parse(USB_SETTING, + load_setting_config, name); +} + +static int usb_init(char *name) +{ + int ret; + + ret = config_parse(USB_SETTING, + load_base_config, name); + if (ret < 0) { + _E("Failed to get base information(%d)", ret); + return ret; + } + + ret = usb_update_configuration(name); + if (ret < 0) + _E("Failed to update usb configuration(%d)", ret); + + return ret; +} + +static int usb_enable(char *name) +{ + int ret; + + ret = usb_load_configuration(CONFIG_DISABLE); + if (ret < 0) { + _E("Failed to disable usb config"); + return ret; + } + + ret = usb_load_configuration(CONFIG_ENABLE); + if (ret < 0) { + _E("Failed to enable usb config"); + return ret; + } + + return usb_execute_operation(name, KEY_START); +} + +static int usb_disable(char *name) +{ + return usb_execute_operation(name, KEY_STOP); +} + +static const struct usb_config_plugin_ops default_plugin = { + .init = usb_init, + .enable = usb_enable, + .disable = usb_disable, +}; + +static bool usb_valid(void) +{ + /* TODO + * add checking default config valid condition */ + return true; +} + +static const struct usb_config_plugin_ops *usb_load(void) +{ + return &default_plugin; +} + +static const struct usb_config_ops usb_config_default_ops = { + .is_valid = usb_valid, + .load = usb_load, +}; + +USB_CONFIG_OPS_REGISTER(&usb_config_default_ops) diff --git a/src/usb/usb-operation.conf b/src/usb/usb-operation.conf new file mode 100644 index 00000000..8db280df --- /dev/null +++ b/src/usb/usb-operation.conf @@ -0,0 +1,3 @@ +[SDB] +start=/usr/bin/systemctl start sdbd.service +stop=/usr/bin/systemctl stop sdbd.service diff --git a/src/usb/usb-setting.conf b/src/usb/usb-setting.conf new file mode 100644 index 00000000..755937fa --- /dev/null +++ b/src/usb/usb-setting.conf @@ -0,0 +1,14 @@ +[BASE] +rootpath=/sys/class/usb_mode/usb0 +load=enable +default=SDB + +[SDB] +idVendor=04e8 +idProduct=6860 +funcs_fconf=sdb +funcs_sconf=sdb +bDeviceClass=239 +bDeviceSubClass=2 +bDeviceProtocol=1 +iProduct=TIZEN diff --git a/src/usb/usb.c b/src/usb/usb.c index 02fd197f..bee3b0c7 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -87,9 +87,7 @@ static int usb_config_init(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->init("DEFAULT"); + return config_plugin->init(NULL); } static void usb_config_deinit(void) @@ -104,9 +102,7 @@ static void usb_config_deinit(void) return; } - /* TODO: - * parameter "DEFAULT" can be changed */ - config_plugin->deinit("DEFAULT"); + config_plugin->deinit(NULL); } static int usb_config_enable(void) @@ -121,9 +117,7 @@ static int usb_config_enable(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->enable("DEFAULT"); + return config_plugin->enable(NULL); } static int usb_config_disable(void) @@ -138,9 +132,7 @@ static int usb_config_disable(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->disable("DEFAULT"); + return config_plugin->disable(NULL); } static int usb_state_changed(void *data) |