From 63d2a309841c6737bc7b0f2b202689c5b20ae5fc Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sun, 1 Feb 2015 13:32:12 +0900 Subject: [PATCH] tizen 2.3 release --- CMakeLists.txt | 2 + TC/testcase/utc_system_info.c | 73 +----------- doc/system_info_doc.h | 37 ++++++ include/system_info.h | 192 +++++++++++-------------------- include/system_info_internal.h | 134 ++++++++++++++++++++++ include/system_info_private.h | 6 + include/system_info_type.h | 53 +++++++++ packaging/capi-system-info.manifest | 3 + packaging/capi-system-info.spec | 16 ++- packaging/tizenid.service | 10 ++ script/make_info_file.sh | 10 +- src/system_info.c | 56 +++++++-- src/system_info_hardware.c | 62 ++++++---- src/system_info_no_file.c | 181 ++++++++++++++++++++++++++++++ src/system_info_parse.c | 16 ++- src/system_info_platform.c | 6 + src/tizenid/CMakeLists.txt | 30 +++++ src/tizenid/tizenid.c | 218 ++++++++++++++++++++++++++++++++++++ 18 files changed, 864 insertions(+), 241 deletions(-) create mode 100644 doc/system_info_doc.h create mode 100644 include/system_info_internal.h create mode 100644 include/system_info_type.h create mode 100644 packaging/tizenid.service create mode 100644 src/system_info_no_file.c create mode 100755 src/tizenid/CMakeLists.txt create mode 100755 src/tizenid/tizenid.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e91bee4..9aca8cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ CONFIGURE_FILE( ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +ADD_SUBDIRECTORY(src/tizenid) + IF(UNIX) ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) diff --git a/TC/testcase/utc_system_info.c b/TC/testcase/utc_system_info.c index b69d51e..c68af84 100644 --- a/TC/testcase/utc_system_info.c +++ b/TC/testcase/utc_system_info.c @@ -73,10 +73,6 @@ static void utc_system_info_manufacturer_p(void); static void utc_system_info_tethering_support_key_p(void); struct tet_testlist tet_testlist[] = { - {utc_system_info_get_int_p, 1}, - {utc_system_info_get_int_n, 1}, - {utc_system_info_get_bool_p, 1}, - {utc_system_info_get_bool_n, 1}, {utc_system_info_get_string_p, 1}, {utc_system_info_get_string_n, 1}, {utc_system_info_get_double_p, 1}, @@ -87,7 +83,6 @@ struct tet_testlist tet_testlist[] = { {utc_system_info_w_res_p, 1}, {utc_system_info_platform_name_p, 1}, {utc_system_info_platform_ver_p, 1}, - {utc_system_info_screen_DPI_p, 1}, {utc_system_info_core_cpu_arch_p, 1}, {utc_system_info_core_freq_p, 1}, {utc_system_info_physical_screen_height_p, 1}, @@ -121,50 +116,6 @@ static void cleanup(void) /****************************************************************/ /* check if all defined types for results are accessible */ -static void utc_system_info_get_int_p(void) -{ - int value; - - int retcode = system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, &value); - - if (retcode == SYSTEM_INFO_ERROR_NONE) - dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed"); - else - dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed"); -} - -static void utc_system_info_get_int_n(void) -{ - int retcode = system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, NULL); - - if (retcode != SYSTEM_INFO_ERROR_NONE) - dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed"); - else - dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed"); -} - -static void utc_system_info_get_bool_p(void) -{ - bool value; - - int retcode = system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &value); - - if (retcode == SYSTEM_INFO_ERROR_NONE) - dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed"); - else - dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed"); -} - -static void utc_system_info_get_bool_n(void) -{ - int retcode = system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, NULL); - - if (retcode != SYSTEM_INFO_ERROR_NONE) - dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed"); - else - dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed"); -} - static void utc_system_info_get_string_p(void) { char *value = NULL; @@ -313,18 +264,6 @@ static void utc_system_info_platform_ver_p(void) dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1); } -static void utc_system_info_screen_DPI_p(void) -{ - int w = -1; - int result = 0; - - system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &w); - - result = (w > 0) && (w < 10000); - - dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1); -} - static void utc_system_info_core_cpu_arch_p(void) { char *string = NULL; @@ -478,7 +417,7 @@ static void utc_system_info_get_platform_int(void) int value = -1; int result = 0; - system_info_get_value_int("tizen.org/feature/screen.bpp", &value); + system_info_get_platform_int("tizen.org/feature/screen.bpp", &value); result = (value > 0) && (value < 10000); @@ -492,7 +431,7 @@ static void utc_system_info_get_platform_double(void) retcode = system_info_get_platform_double("tizen.org/feature/double", &value); - if (retcode == SYSTEM_INFO_ERROR_IO_ERROR) + if (retcode != SYSTEM_INFO_ERROR_NONE) dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed"); else dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed"); @@ -523,7 +462,7 @@ static void utc_system_info_get_custom_bool(void) retcode = system_info_get_custom_bool("tizen.org/feature/double", &value); - if (retcode == SYSTEM_INFO_ERROR_IO_ERROR) + if (retcode != SYSTEM_INFO_ERROR_NONE) dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed"); else dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed"); @@ -536,7 +475,7 @@ static void utc_system_info_get_custom_int(void) retcode = system_info_get_custom_int("tizen.org/feature/double", &value); - if (retcode == SYSTEM_INFO_ERROR_IO_ERROR) + if (retcode != SYSTEM_INFO_ERROR_NONE) dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed"); else dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed"); @@ -549,7 +488,7 @@ static void utc_system_info_get_custom_double(void) retcode = system_info_get_custom_double("tizen.org/feature/double", &value); - if (retcode == SYSTEM_INFO_ERROR_IO_ERROR) + if (retcode != SYSTEM_INFO_ERROR_NONE) dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed"); else dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed"); @@ -565,7 +504,7 @@ static void utc_system_info_get_custom_string(void) if (value) free(value); - if (retcode == SYSTEM_INFO_ERROR_IO_ERROR) + if (retcode != SYSTEM_INFO_ERROR_NONE) dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed"); else dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed"); diff --git a/doc/system_info_doc.h b/doc/system_info_doc.h new file mode 100644 index 0000000..18382e8 --- /dev/null +++ b/doc/system_info_doc.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_SYSTEM_SYSTEM_INFO_DOC_H__ +#define __TIZEN_SYSTEM_SYSTEM_INFO_DOC_H__ + +/** + * @ingroup CAPI_SYSTEM_FRAMEWORK + * @defgroup CAPI_SYSTEM_SYSTEM_INFO_MODULE System Information + * @brief The System Information API provides functions which can be used to obtain device information. This section provides more information about the System Information API. + * + * @section CAPI_SYSTEM_SYSTEM_INFO_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_SYSTEM_SYSTEM_INFO_MODULE_OVERVIEW Overview + * The System Information API provides functions which can be used to obtain system information such as the device API and platform versions, device model number, supported device features, and device screen dimensions. + * The available system information is stored in key/value pairs. Depending on their respective key, values can have different data types. + * The keys for the platform functions are specified by the Tizen platform and can be seen here. + * The keys for the custom functions are specified by OEM's and vendors. Developers should check with their OEM's Tizen OS support if they wish to use a custom functions. + * + */ + +#endif /* __TIZEN_SYSTEM_SYSTEM_INFO_DOC_H__ */ diff --git a/include/system_info.h b/include/system_info.h index c216e8a..5b0048a 100644 --- a/include/system_info.h +++ b/include/system_info.h @@ -18,7 +18,7 @@ #ifndef __TIZEN_SYSTEM_SYSTEM_INFO_H__ #define __TIZEN_SYSTEM_SYSTEM_INFO_H__ -#include +#include "system_info_type.h" #ifdef __cplusplus extern "C" @@ -31,188 +31,122 @@ extern "C" */ /** - * @brief Enumeration of error code for system information - */ -typedef enum { - SYSTEM_INFO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - SYSTEM_INFO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - SYSTEM_INFO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - SYSTEM_INFO_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< An input/output error occurred when read value from system */ -} system_info_error_e; - -/** - * @brief Enumeration of key for system information - */ -typedef enum { - SYSTEM_INFO_KEY_MODEL, /**< The model of the device */ - SYSTEM_INFO_KEY_TIZEN_VERSION, /**< The version of the Tizen API */ - SYSTEM_INFO_KEY_PLATFORM_NAME, /**< The name of platform */ - SYSTEM_INFO_KEY_TIZEN_VERSION_NAME, /**< The name of tizen version */ - SYSTEM_INFO_KEY_MANUFACTURER, /**< The manufacturer of the device */ - SYSTEM_INFO_KEY_CORE_CPU_ARCH, /**< The CORE CPU architecture of model */ - SYSTEM_INFO_KEY_CORE_CPU_FREQ, /**< The CORE CPU frequency of model */ - SYSTEM_INFO_KEY_BUILD_STRING, /**< The build string of platform binary */ - SYSTEM_INFO_KEY_BUILD_DATE, /**< The build date of platform binary */ - SYSTEM_INFO_KEY_BUILD_TIME, /**< The build time of platform binary */ - SYSTEM_INFO_KEY_SCREEN_HEIGHT, /**< The height of the screen in pixels */ - SYSTEM_INFO_KEY_SCREEN_WIDTH, /**< The width of the screen in pixels */ - SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, /**< The physical screen height in millimeters */ - SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, /**< The physical screen width in millimeters */ - SYSTEM_INFO_KEY_TETHERING_SUPPORTED, /**< Indicates whether the device supports tethering */ -} system_info_key_e; - -/** - * @brief Gets the integer value of the system information - * @param[in] key The name of the system information to get - * @param[out] value The value of the given system information - * @return 0 on success, otherwise a negative error value. - * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system - */ -int system_info_get_value_int(system_info_key_e key, int *value); - -/** - * @brief Gets the boolean value of the system information - * @param[in] key The name of the system information to get - * @param[out] value The value of the given system information - * @return 0 on success, otherwise a negative error value. - * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system - */ -int system_info_get_value_bool(system_info_key_e key, bool *value); - -/** - * @brief Gets the double value of the system information - * @param[in] key The name of the system information to get - * @param[out] value The value of the given system information - * @return 0 on success, otherwise a negative error value. - * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system - */ -int system_info_get_value_double(system_info_key_e key, double *value); - -/** - * @brief Gets the string value of the system information - * @remarks The @a value must be released with @c free() by you. - * @param[in] key The name of the system information to get - * @param[out] value The value of the given system information - * @return 0 on success, otherwise a negative error value. - * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system - */ -int system_info_get_value_string(system_info_key_e key, char **value); - -/** - * @brief Gets the boolean value of the platform feature + * @brief Gets the boolean value of the @a platform feature. + * @since_tizen 2.3 * @param[in] key The name of the platform feature to get * @param[out] value The value of the given platform feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_platform_bool(const char *key, bool *value); /** - * @brief Gets the integer value of the platform feature + * @brief Gets the integer value of the @a platform feature. + * @since_tizen 2.3 * @param[in] key The name of the platform feature to get * @param[out] value The value of the given platform feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_platform_int(const char *key, int *value); /** - * @brief Gets the string value of the platform feature + * @brief Gets the double value of the @a platform feature. + * @since_tizen 2.3 * @param[in] key The name of the platform feature to get * @param[out] value The value of the given platform feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_platform_double(const char *key, double *value); /** - * @brief Gets the string value of the platform feature - * @remarks The @a value must be released with @c free() by you. + * @brief Gets the string value of the @a platform feature. + * @since_tizen 2.3 + * @remarks You must release the @a value using free(). * @param[in] key The name of the platform feature to get * @param[out] value The value of the given platform feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_platform_string(const char *key, char **value); /** - * @brief Gets the boolean value of the custom feature - * @param[in] key The name of the custom feature to get + * @brief Gets the boolean value of the @a custom feature. + * @since_tizen 2.3 + * @param[in] key The name of the custom feature to get. NOTE: This custom function uses a custom key which is provided by OEM's * @param[out] value The value of the given custom feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_custom_bool(const char *key, bool *value); /** - * @brief Gets the string value of the custom feature - * @param[in] key The name of the custom feature to get + * @brief Gets the integer value of the @a custom feature. + * @since_tizen 2.3 + * @param[in] key The name of the custom feature to get. NOTE: This custom function uses a custom key which is provided by OEM's * @param[out] value The value of the given custom feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot the find @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_custom_int(const char *key, int *value); /** - * @brief Gets the string value of the custom feature - * @param[in] key The name of the custom feature to get + * @brief Gets the double value of the @a custom feature. + * @since_tizen 2.3 + * @param[in] key The name of the custom feature to get. NOTE: This custom function uses a custom key which is provided by OEM's * @param[out] value The value of the given custom feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_custom_double(const char *key, double *value); /** - * @brief Gets the string value of the custom feature - * @remarks The @a value must be released with @c free() by you. - * @param[in] key The name of the custom feature to get + * @brief Gets the string value of the @a custom feature. + * @since_tizen 2.3 + * @remarks You must release the @a value using free(). + * @param[in] key The name of the custom feature to get. NOTE: This custom function uses a custom key which is provided by OEM's * @param[out] value The value of the given custom feature - * @return 0 on success, otherwise a negative error value. + * @return @c 0 on success, + * otherwise a negative error value * @retval #SYSTEM_INFO_ERROR_NONE Successful * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in model config file - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from model config file + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Cannot find the @a key in the model config file + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred while reading the @a value from the model config file + * @retval #SYSTEM_INFO_ERROR_PERMISSION_DENIED No permission to use the API */ int system_info_get_custom_string(const char *key, char **value); -/** - * @brief Gets the string value of the internal feature - * @remarks The @a value must be released with @c free() by you. - * @param[in] key The name of the internal feature to get - * @param[out] value The value of the given internal feature - * @return 0 on success, otherwise a negative error value. - * @retval #SYSTEM_INFO_ERROR_NONE Successful - * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in config files - * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from config files - */ -int system_info_get_internal_value(const char *key, char **value); - /** * @} diff --git a/include/system_info_internal.h b/include/system_info_internal.h new file mode 100644 index 0000000..c0b84dc --- /dev/null +++ b/include/system_info_internal.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_SYSTEM_SYSTEM_INFO_INTERNAL_H__ +#define __TIZEN_SYSTEM_SYSTEM_INFO_INTERNAL_H__ + +#include "system_info_type.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @internal + * @addtogroup CAPI_SYSTEM_SYSTEM_INFO_INTERNAL_MODULE + * @{ + */ + +/** + * @brief Enumeration of key for system information + */ +typedef enum { + SYSTEM_INFO_KEY_MODEL, /**< The model of the device */ + SYSTEM_INFO_KEY_TIZEN_VERSION, /**< The version of the Tizen API */ + SYSTEM_INFO_KEY_PLATFORM_NAME, /**< The name of platform */ + SYSTEM_INFO_KEY_TIZEN_VERSION_NAME, /**< The name of tizen version */ + SYSTEM_INFO_KEY_MANUFACTURER, /**< The manufacturer of the device */ + SYSTEM_INFO_KEY_CORE_CPU_ARCH, /**< The CORE CPU architecture of model */ + SYSTEM_INFO_KEY_CORE_CPU_FREQ, /**< The CORE CPU frequency of model */ + SYSTEM_INFO_KEY_BUILD_STRING, /**< The build string of platform binary */ + SYSTEM_INFO_KEY_BUILD_DATE, /**< The build date of platform binary */ + SYSTEM_INFO_KEY_BUILD_TIME, /**< The build time of platform binary */ + SYSTEM_INFO_KEY_SCREEN_HEIGHT, /**< The height of the screen in pixels */ + SYSTEM_INFO_KEY_SCREEN_WIDTH, /**< The width of the screen in pixels */ + SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, /**< The physical screen height in millimeters */ + SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, /**< The physical screen width in millimeters */ + SYSTEM_INFO_KEY_TETHERING_SUPPORTED, /**< Indicates whether the device supports tethering */ +} system_info_key_e; + +/** + * @internal + * @brief Gets the integer value of the system information + * @since_tizen 2.3 + * @param[in] key The name of the system information to get + * @param[out] value The value of the given system information + * @return 0 on success, otherwise a negative error value. + * @retval #SYSTEM_INFO_ERROR_NONE Successful + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system + */ +int system_info_get_value_int(system_info_key_e key, int *value); + +/** + * @internal + * @brief Gets the boolean value of the system information + * @since_tizen 2.3 + * @param[in] key The name of the system information to get + * @param[out] value The value of the given system information + * @return 0 on success, otherwise a negative error value. + * @retval #SYSTEM_INFO_ERROR_NONE Successful + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system + */ +int system_info_get_value_bool(system_info_key_e key, bool *value); + +/** + * @internal + * @brief Gets the double value of the system information + * @since_tizen 2.3 + * @param[in] key The name of the system information to get + * @param[out] value The value of the given system information + * @return 0 on success, otherwise a negative error value. + * @retval #SYSTEM_INFO_ERROR_NONE Successful + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system + */ +int system_info_get_value_double(system_info_key_e key, double *value); + +/** + * @internal + * @brief Gets the string value of the system information + * @since_tizen 2.3 + * @remarks The @a value must be released with @c free() by you. + * @param[in] key The name of the system information to get + * @param[out] value The value of the given system information + * @return 0 on success, otherwise a negative error value. + * @retval #SYSTEM_INFO_ERROR_NONE Successful + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from system + */ +int system_info_get_value_string(system_info_key_e key, char **value); + + +/** + * @internal + * @brief Gets the string value of the internal feature + * @since_tizen 2.3 + * @remarks The @a value must be released with @c free() by you. + * @param[in] key The name of the internal feature to get + * @param[out] value The value of the given internal feature + * @return 0 on success, otherwise a negative error value. + * @retval #SYSTEM_INFO_ERROR_NONE Successful + * @retval #SYSTEM_INFO_ERROR_OUT_OF_MEMORY Out of memory + * @retval #SYSTEM_INFO_ERROR_INVALID_PARAMETER cannot find key in config files + * @retval #SYSTEM_INFO_ERROR_IO_ERROR An input/output error occurred when read value from config files + */ +int system_info_get_internal_value(const char *key, char **value); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_SYSTEM_SYSTEM_INFO_INTERNAL_H__ */ diff --git a/include/system_info_private.h b/include/system_info_private.h index 901444d..601250e 100644 --- a/include/system_info_private.h +++ b/include/system_info_private.h @@ -23,6 +23,8 @@ extern "C" { #endif +#include "system_info_internal.h" + #ifndef API #define API __attribute__ ((visibility("default"))) #endif @@ -32,6 +34,7 @@ extern "C" #define CPU_INFO_FILE_PATH "/proc/cpuinfo" #define CPU_INFO_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" #define CONFIG_FILE_PATH "/etc/config/model-config.xml" +#define SERIAL_PATH "/csa/imei/serialno.dat" #define MAXBUFSIZE 512 #define PLATFORM_TAG "platform" @@ -90,6 +93,9 @@ int system_info_get_build_string(system_info_key_e key, system_info_data_type_e int system_info_get_build_date(system_info_key_e key, system_info_data_type_e data_type, void **value); int system_info_get_build_time(system_info_key_e key, system_info_data_type_e data_type, void **value); int system_info_get_tethering_supported(system_info_key_e key, system_info_data_type_e data_type, void **value); + +int system_info_get_no_file(const char *key, void **value); + #ifdef __cplusplus } #endif diff --git a/include/system_info_type.h b/include/system_info_type.h new file mode 100644 index 0000000..38cc0e1 --- /dev/null +++ b/include/system_info_type.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __TIZEN_SYSTEM_SYSTEM_INFO_TYPE_H__ +#define __TIZEN_SYSTEM_SYSTEM_INFO_TYPE_H__ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @addtogroup CAPI_SYSTEM_SYSTEM_INFO_MODULE + * @{ + */ + +/** + * @brief Enumeration of error codes for system information + */ +typedef enum { + SYSTEM_INFO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + SYSTEM_INFO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + SYSTEM_INFO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + SYSTEM_INFO_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< An input/output error occurred when reading value from system */ + SYSTEM_INFO_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< No permission to use the API */ +} system_info_error_e; + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_SYSTEM_SYSTEM_INFO_TYPE_H__ */ diff --git a/packaging/capi-system-info.manifest b/packaging/capi-system-info.manifest index 97e8c31..e515dca 100644 --- a/packaging/capi-system-info.manifest +++ b/packaging/capi-system-info.manifest @@ -2,4 +2,7 @@ + + + diff --git a/packaging/capi-system-info.spec b/packaging/capi-system-info.spec index 24d70a4..43c507c 100644 --- a/packaging/capi-system-info.spec +++ b/packaging/capi-system-info.spec @@ -5,12 +5,15 @@ Release: 0 Group: System/Libraries License: Apache License, Version 2.0 Source0: %{name}-%{version}.tar.gz -Source1001: %{name}.manifest +Source1001: %{name}.manifest +Source2001: tizenid.service BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(iniparser) -BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(openssl) +BuildRequires: pkgconfig(cryptsvc) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -46,6 +49,10 @@ cp -f LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} mkdir -p %{buildroot}/etc cp -f script/make_info_file.sh %{buildroot}/etc/make_info_file.sh +mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants +install -m 0644 %SOURCE2001 %{buildroot}%{_libdir}/systemd/system/tizenid.service +ln -s ../tizenid.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/tizenid.service + %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -56,9 +63,14 @@ cp -f script/make_info_file.sh %{buildroot}/etc/make_info_file.sh /usr/share/license/%{name} %{_libdir}/libcapi-system-info.so.* %attr(0744,root,-) /etc/make_info_file.sh +%{_bindir}/tizen_id +%{_libdir}/systemd/system/tizenid.service +%{_libdir}/systemd/system/multi-user.target.wants/tizenid.service %files devel %manifest %{name}.manifest %{_includedir}/system/system_info.h +%{_includedir}/system/system_info_type.h +%{_includedir}/system/system_info_internal.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-system-info.so diff --git a/packaging/tizenid.service b/packaging/tizenid.service new file mode 100644 index 0000000..9333789 --- /dev/null +++ b/packaging/tizenid.service @@ -0,0 +1,10 @@ +[Unit] +Description=Making Tizen ID +Requires=opt-usr.mount + +[Service] +Type=simple +ExecStart=/usr/bin/tizen_id + +[Install] +WantedBy=multi-user.target diff --git a/script/make_info_file.sh b/script/make_info_file.sh index 11d1382..ce44ddb 100644 --- a/script/make_info_file.sh +++ b/script/make_info_file.sh @@ -2,18 +2,24 @@ # make_info_file.sh : make /etc/info.ini # -if [ $# != 2 ]; then - echo "Usage : make_info_file.sh [model] [build] " +if [ $# -lt 2 -o $# -gt "3" ]; then + echo "Usage : make_info_file.sh [model] [build] {operator}" exit fi MODEL=$1 BUILD=$2 +if [ $# == 3 ]; then + OPERATOR=$3 +else + OPERATOR="" +fi cat >/etc/info.ini < #include #include +#include #include @@ -164,8 +165,8 @@ system_info_mode_type_e system_info_get_system_info_model_type(void) void __attribute__((constructor)) system_info_init(void) { - int ret; - char *str; + int ret, len, i; + char *str = NULL; ret = system_info_get_platform_string("tizen.org/system/model_name", &str); @@ -174,7 +175,17 @@ void __attribute__((constructor)) system_info_init(void) return; } - if (!strcmp(str, "Emulator")) + if (!str) { + LOGE("Failed to get model name"); + return; + } + + len = strlen(str); + for (i = 0 ; i < len ; i++) { + str[i] = toupper(str[i]); + } + + if (!strcmp(str, "EMULATOR")) system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_EMULATOR; else system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_TARGET; @@ -258,6 +269,8 @@ API int system_info_get_platform_bool(const char *key, bool *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } @@ -287,6 +300,8 @@ API int system_info_get_platform_int(const char *key, int *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } @@ -313,6 +328,8 @@ API int system_info_get_platform_double(const char *key, double *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } @@ -336,9 +353,17 @@ API int system_info_get_platform_string(const char *key, char **value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } + ret = system_info_get_no_file(key, (void**)&string); + if (ret == 0) { + *value = string; + return SYSTEM_INFO_ERROR_NONE; + } + ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, STR_TYPE, &string); if (ret) { LOGE("cannot get %s", key); @@ -360,14 +385,15 @@ API int system_info_get_custom_bool(const char *key, bool *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &string); if (ret) { - LOGI("cannot get %s", key); - *supported = false; - return SYSTEM_INFO_ERROR_NONE; + LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH); + return ret; } if (!strcmp(string, "true") || !strcmp(string, "TRUE")) @@ -390,14 +416,15 @@ API int system_info_get_custom_int(const char *key, int *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &string); if (ret) { - LOGI("cannot get %s", key); - *ret_val = 0; - return SYSTEM_INFO_ERROR_NONE; + LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH); + return ret; } *ret_val = atoi(string); @@ -417,14 +444,15 @@ API int system_info_get_custom_double(const char *key, double *value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &string); if (ret) { - LOGI("cannot get %s", key); - *ret_val = 0; - return SYSTEM_INFO_ERROR_NONE; + LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH); + return ret; } *ret_val = atof(string); @@ -441,6 +469,8 @@ API int system_info_get_custom_string(const char *key, char **value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } @@ -469,6 +499,8 @@ API int system_info_get_internal_value(const char *key, char **value) if (access(CONFIG_FILE_PATH, R_OK)) { LOGE("cannot find file %s!!!", CONFIG_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } diff --git a/src/system_info_hardware.c b/src/system_info_hardware.c index 515217e..adf8106 100644 --- a/src/system_info_hardware.c +++ b/src/system_info_hardware.c @@ -36,40 +36,46 @@ int system_info_get_value_from_cpuinfo(char *field, char **value) int tmpStrlen = 0; FILE *cpuinfo = NULL; char *name = NULL; - char str[MAXBUFSIZE] = ""; - char tmpStr[MAXBUFSIZE] = ""; + char str[MAXBUFSIZE] = { 0, }; + char tmpStr[MAXBUFSIZE] = { 0, }; + + if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) { + snprintf(tmpStr, sizeof(tmpStr), "default"); + goto out; + } cpuinfo = fopen(CPU_INFO_FILE_PATH, "r"); if (NULL == cpuinfo) { LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } while (fgets(str, MAXBUFSIZE, cpuinfo)) { - if (!strncmp(field, str, strlen(field))) { - name = strchr(str, ':'); - tmpStrlen = strlen(name+2); - strncpy(tmpStr, name+2, tmpStrlen); - tmpStr[tmpStrlen-1] = '\0'; - *value = strdup(tmpStr); - if (*value == NULL) { - LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY); - fclose(cpuinfo); - return SYSTEM_INFO_ERROR_OUT_OF_MEMORY; - } - } + if (strncmp(field, str, strlen(field))) + continue; + + name = strchr(str, ':'); + tmpStrlen = strlen(name+2); + strncpy(tmpStr, name+2, tmpStrlen); + tmpStr[tmpStrlen-1] = '\0'; + break; } - if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) - *value = strdup("default"); + fclose(cpuinfo); - if (*value == NULL) { - LOGE("cannot get %s in cpuinfo", field); - fclose(cpuinfo); +out: + if (strlen(tmpStr) == 0) { + LOGE("Failed to get (%s) info", field); return SYSTEM_INFO_ERROR_OUT_OF_MEMORY; } - fclose(cpuinfo); + *value = strdup(tmpStr); + if (*value == NULL) { + LOGE("malloc() failed to get (%s) info", field); + return SYSTEM_INFO_ERROR_OUT_OF_MEMORY; + } return SYSTEM_INFO_ERROR_NONE; } @@ -82,24 +88,30 @@ int system_info_get_bsp_info(const char *key, char **value) char *revision = NULL; char Rrevision[MAXBUFSIZE] = ""; char file_path[MAXBUFSIZE] = ""; + int ret; if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) { LOGE("cannot get Hardware info in emulator!!!"); return SYSTEM_INFO_ERROR_IO_ERROR; } - if (system_info_get_value_from_cpuinfo("Hardware", &model)) { + ret = system_info_get_value_from_cpuinfo("Hardware", &model); + if (ret != SYSTEM_INFO_ERROR_NONE) { LOGE("cannot get Hardware info from cpuinfo file!!!"); - return SYSTEM_INFO_ERROR_IO_ERROR; + return ret; } - if (system_info_get_value_from_cpuinfo("Revision", &revision)) { + ret = system_info_get_value_from_cpuinfo("Revision", &revision); + if (ret != SYSTEM_INFO_ERROR_NONE) { LOGE("cannot get Hardware info from cpuinfo file!!!"); - return SYSTEM_INFO_ERROR_IO_ERROR; + free(model); + return ret; } if (!revision || !strcmp(revision, "default")) { LOGE("cannot get revision info from cpuinfo file!!!"); + free(model); + free(revision); return SYSTEM_INFO_ERROR_IO_ERROR; } @@ -108,6 +120,8 @@ int system_info_get_bsp_info(const char *key, char **value) if (access(file_path, R_OK)) { LOGE("cannot find file %s!!!", file_path); + free(model); + free(revision); return SYSTEM_INFO_ERROR_IO_ERROR; } diff --git a/src/system_info_no_file.c b/src/system_info_no_file.c new file mode 100644 index 0000000..95d94c1 --- /dev/null +++ b/src/system_info_no_file.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_SYSTEM_INFO" + +#define SERIAL_TOK_DELIMITER "," +#define BUF_MAX 256 + +#define TIZEN_ID_PATH "/opt/home/root/tizenid" + +static int get_tizenid(char **value) +{ + char id[BUF_MAX]; + FILE *fp; + + fp = fopen(TIZEN_ID_PATH, "r"); + if (!fp) { + LOGE("Failed to open file (%s)", TIZEN_ID_PATH); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + if (fgets(id, sizeof(id), fp) == NULL) { + LOGE("Failed to get string (errno:%d)", errno); + fclose(fp); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + fclose(fp); + + if (strlen(id) == 0) { + LOGE("String length of id is 0"); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + *value = strdup(id); + + return 0; +} + +static int get_build_info(int key, char *buf, unsigned int len) +{ + int ret; + char *val; + + if (key != SYSTEM_INFO_KEY_BUILD_DATE && + key != SYSTEM_INFO_KEY_BUILD_STRING && + key != SYSTEM_INFO_KEY_BUILD_TIME) + return -EINVAL; + + ret = system_info_get_value_string(key, &val); + if (ret != SYSTEM_INFO_ERROR_NONE) { + LOGE("Failed to get build date(%d)", ret); + return ret; + } + + if (!val) { + LOGE("val == NULL"); + return SYSTEM_INFO_ERROR_OUT_OF_MEMORY; + } + + if (strlen(val) == 0) { + LOGE("Invalid date"); + free(val); + return SYSTEM_INFO_ERROR_IO_ERROR; + } + + snprintf(buf, len, "%s", val); + free(val); + + return ret; +} + +static int get_build_date(char **value) +{ + int ret; + char date[BUF_MAX]; + + ret = get_build_info(SYSTEM_INFO_KEY_BUILD_DATE, date, sizeof(date)); + if (ret != SYSTEM_INFO_ERROR_NONE) { + LOGE("Failed to get build date(%d)", ret); + return ret; + } + + *value = strdup(date); + + return SYSTEM_INFO_ERROR_NONE; +} + +static int get_build_string(char **value) +{ + int ret; + char str[BUF_MAX]; + + ret = get_build_info(SYSTEM_INFO_KEY_BUILD_STRING, str, sizeof(str)); + if (ret != SYSTEM_INFO_ERROR_NONE) { + LOGE("Failed to get build date(%d)", ret); + return ret; + } + + *value = strdup(str); + + return SYSTEM_INFO_ERROR_NONE; +} + +static int get_build_time(char **value) +{ + int ret; + char time[BUF_MAX]; + + ret = get_build_info(SYSTEM_INFO_KEY_BUILD_TIME, time, sizeof(time)); + if (ret != SYSTEM_INFO_ERROR_NONE) { + LOGE("Failed to get build date(%d)", ret); + return ret; + } + + *value = strdup(time); + + return SYSTEM_INFO_ERROR_NONE; +} + +int system_info_get_no_file(const char *key, void **value) +{ + char *p_key; + + if (!key || !value) + return -EINVAL; + + p_key = strstr(key, "http://"); + if (p_key && p_key == key) + p_key = (char *)key + strlen("http://"); + else + p_key = (char *)key; + + if (!strncmp(p_key, "tizen.org/system/tizenid", strlen(p_key))) { + return get_tizenid((char **)value); + } + + if (!strncmp(p_key, "tizen.org/system/build.date", strlen(p_key))) { + return get_build_date((char**)value); + } + + if (!strncmp(p_key, "tizen.org/system/build.string", strlen(p_key))) { + return get_build_string((char**)value); + } + + if (!strncmp(p_key, "tizen.org/system/build.time", strlen(p_key))) { + return get_build_time((char**)value); + } + + return -ENOENT; +} diff --git a/src/system_info_parse.c b/src/system_info_parse.c index da38edb..290e831 100644 --- a/src/system_info_parse.c +++ b/src/system_info_parse.c @@ -194,7 +194,7 @@ int system_info_get_value_from_config_xml(char *feature_tag, const char *name_fi xmlNodePtr cur = NULL; xmlNodePtr model_node = NULL; xmlNode *cur_node = NULL; - char *name = NULL; + char *name = NULL, *p_name = NULL; char *type = NULL; char *string = NULL; @@ -233,7 +233,7 @@ int system_info_get_value_from_config_xml(char *feature_tag, const char *name_fi if (model_node == NULL) { LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH); xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; + return SYSTEM_INFO_ERROR_INVALID_PARAMETER; } if (model_node) { @@ -244,8 +244,14 @@ int system_info_get_value_from_config_xml(char *feature_tag, const char *name_fi name = (char *)xmlGetProp(cur_node, (const xmlChar*)"name"); type = (char *)xmlGetProp(cur_node, (const xmlChar*)"type"); - if (!strncmp(name, name_field, strlen(name))) { - if (!strncmp(name, name_field, strlen(name_field))) { + p_name = strstr(name_field, "http://"); + if (p_name && p_name == name_field) + p_name = (char *)name_field + strlen("http://"); + else + p_name = (char *)name_field; + + if (!strncmp(name, p_name, strlen(name))) { + if (!strncmp(name, p_name, strlen(p_name))) { if (strncmp(type, type_field, strlen(type_field))) { LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER); free(name); @@ -272,7 +278,7 @@ int system_info_get_value_from_config_xml(char *feature_tag, const char *name_fi if (!cur_node) { LOGE("cannot find %s field from %s file!!!", name_field, CONFIG_FILE_PATH); xmlFreeDoc(doc); - return SYSTEM_INFO_ERROR_IO_ERROR; + return SYSTEM_INFO_ERROR_INVALID_PARAMETER; } if (*value == NULL) { diff --git a/src/system_info_platform.c b/src/system_info_platform.c index 537c8f1..49fac27 100644 --- a/src/system_info_platform.c +++ b/src/system_info_platform.c @@ -93,6 +93,8 @@ int system_info_get_core_cpu_freq(system_info_key_e key, system_info_data_type_e cpuinfo_max_freq = fopen(CPU_INFO_MAX_FREQ_PATH, "r"); if (NULL == cpuinfo_max_freq) { LOGE("cannot file open %s file!!!", CPU_INFO_MAX_FREQ_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } else { if (fscanf(cpuinfo_max_freq, "%lf", &max_freq) < 1) { @@ -107,6 +109,8 @@ int system_info_get_core_cpu_freq(system_info_key_e key, system_info_data_type_e cpuinfo = fopen(CPU_INFO_FILE_PATH, "r"); if (NULL == cpuinfo) { LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } else { while (fgets(str, MAXBUFSIZE, cpuinfo)) { @@ -145,6 +149,8 @@ int system_info_get_tizen_version_name(system_info_key_e key, system_info_data_t info = fopen(OS_RELEASE_FILE_PATH, "r"); if (NULL == info) { LOGE("cannot file open %s file!!!", OS_RELEASE_FILE_PATH); + if (errno == EPERM || errno == EACCES) + return SYSTEM_INFO_ERROR_PERMISSION_DENIED; return SYSTEM_INFO_ERROR_IO_ERROR; } diff --git a/src/tizenid/CMakeLists.txt b/src/tizenid/CMakeLists.txt new file mode 100755 index 0000000..8ea9d4c --- /dev/null +++ b/src/tizenid/CMakeLists.txt @@ -0,0 +1,30 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET(TIZENID "tizen_id") +SET(SRCS + ${CMAKE_SOURCE_DIR}/src/tizenid/tizenid.c +) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(tizenid_pkgs REQUIRED + dlog + openssl + cryptsvc +) + +FOREACH(flag ${tizenid_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -fpie") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +ADD_EXECUTABLE(${TIZENID} ${SRCS}) +TARGET_LINK_LIBRARIES(${TIZENID} ${tizenid_pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TIZENID} DESTINATION bin) diff --git a/src/tizenid/tizenid.c b/src/tizenid/tizenid.c new file mode 100755 index 0000000..bc79d86 --- /dev/null +++ b/src/tizenid/tizenid.c @@ -0,0 +1,218 @@ +/* + * tizenid + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "TIZENID" + +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) + +#define KEY_MAX 20 + +#define TIZEN_ID_PATH "/opt/home/root/tizenid" +#define RANDOM_PATH "/dev/random" +#define MODEL_CONFIG_PATH "/etc/config/model-config.xml" + +static int get_pw_key(char *pw, unsigned int len) +{ + char key[KEY_MAX];/* 128 bit */ + int fd, ret, i, key_len; + + if (!pw) + return -EINVAL; + + fd = open(RANDOM_PATH, O_RDONLY); + if (fd == -1) { + _E("Failed to open (%s, errno:%d)", RANDOM_PATH, errno); + return -errno; + } + + key_len = sizeof(key); + ret = read(fd, key, key_len); + close(fd); + if (ret == -1) { + _E("Failed to read (%s, errno:%d)", RANDOM_PATH, errno); + return -errno; + } + + for(i = 0 ; i < len - 1 ; i++) { + if (i >= key_len) + break; + pw[i] = key[i]; + } + pw[i] = '\0'; + + return 0; +} + +static int get_salt_by_model(char *salt, unsigned int len) +{ + int i; + char *str = NULL, *start, *stop; + char buf[256]; + char *key = "tizen.org/system/model_name"; + FILE *fp; + + if (!salt) + return -EINVAL; + + fp = fopen(MODEL_CONFIG_PATH, "r"); + if (!fp) { + _E("Failed to open (%s)", MODEL_CONFIG_PATH); + return -ENOENT; + } + + while (fgets(buf, sizeof(buf), fp) != NULL) { + str = strstr(buf, key); + if (!str) + continue; + + start = strchr(str, '>'); + if (!start) + continue; + stop = strchr(str, '<'); + if (!stop) + continue; + if (start >= stop) + continue; + + for(start += 1, i = 0; (start < stop) && (i < len-1) ; start++, i++) { + salt[i] = start[i]; + } + salt[i] = '\0'; + + break; + } + + fclose(fp); + + return 0; +} + +static int store_tizen_id(char *id) +{ + FILE *fp; + int ret; + + if (!id) + return -EINVAL; + + fp = fopen(TIZEN_ID_PATH, "w"); + if (!fp) { + _E("Failed to open file (%s)", TIZEN_ID_PATH); + return -ENOMEM; + } + + ret = fputs(id, fp); + fclose(fp); + if (ret == EOF) { + _E("Failed to store id"); + return -ENOMEM; + } + + ret = chmod(TIZEN_ID_PATH, 0554); + if (ret == -1) { + _E("chmod() failed(errno:%d)", errno); + return -errno; + } + + return 0; +} + +static int make_tizen_id(void) +{ + char salt[KEY_MAX], pw_key[KEY_MAX]; + char *id = NULL, *id_64 = NULL; + int ret; + + ret = get_salt_by_model(salt, sizeof(salt)); + if (ret < 0) { + _E("Failed to get salt value (%d)", ret); + return ret; + } + + ret = get_pw_key(pw_key, sizeof(pw_key)); + if (ret < 0) { + _E("Failed to get pw key value (%d)", ret); + return ret; + } + + id = (char *)malloc(sizeof(char) * KEY_MAX); + if (!id) { + _E("malloc() failed"); + return -ENOMEM; + } + + ret = PKCS5_PBKDF2_HMAC_SHA1(pw_key, strlen(pw_key), /* pw key */ + (unsigned char *)salt, sizeof(salt), /*salt*/ + 1, /* nr of iteration */ + KEY_MAX, (unsigned char *)id); /* output */ + if (ret == 0) { /* 0: failed, 1: successful */ + _E("PKCS5_PBKDF2_HMAC_SHA1() failed"); + ret = -ENOENT; + goto out; + } + + id[KEY_MAX-1] = '\0'; + _I("ID: (%s)", id); + + id_64 = Base64Encoding(id, KEY_MAX); + + ret = store_tizen_id(id_64); + if (ret < 0) { + _E("Failed to store tizen id to file (%d)", ret); + goto out; + } + + ret = 0; + +out: + if (id) + free(id); + if (id_64) + free(id_64); + + return ret; +} + +int main(int argc, char *argv[]) +{ + if (access(TIZEN_ID_PATH, F_OK) == 0) + return 0; + + return make_tizen_id(); +} -- 2.7.4