From 2070128ee0dec39c388cdadd6e10af8ef5bb8c18 Mon Sep 17 00:00:00 2001 From: Kyeongchul Kim Date: Tue, 21 Aug 2012 21:24:16 +0900 Subject: [PATCH] release tizen_2.0 --- CMakeLists.txt | 4 +- TC/_export_env.sh | 9 + TC/_export_target_env.sh | 8 + TC/build.sh | 16 + TC/clean.sh | 11 + TC/config | 2 + TC/execute.sh | 15 + TC/testcase/Makefile | 24 ++ TC/testcase/tslist | 2 + TC/testcase/utc_telephony_sim.c | 360 +++++++++++++++++++ TC/tet_scen | 7 + TC/tetbuild.cfg | 5 + TC/tetclean.cfg | 5 + TC/tetexec.cfg | 5 + debian/changelog | 115 ++++++- debian/control | 2 +- packaging/capi-telephony-sim.spec | 8 +- src/sim.c | 707 ++++++++++++++++++++------------------ 18 files changed, 949 insertions(+), 356 deletions(-) create mode 100755 TC/_export_env.sh create mode 100755 TC/_export_target_env.sh create mode 100755 TC/build.sh create mode 100755 TC/clean.sh create mode 100644 TC/config create mode 100755 TC/execute.sh create mode 100644 TC/testcase/Makefile create mode 100644 TC/testcase/tslist create mode 100644 TC/testcase/utc_telephony_sim.c create mode 100755 TC/tet_scen create mode 100644 TC/tetbuild.cfg create mode 100644 TC/tetclean.cfg create mode 100644 TC/tetexec.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e42ac5..4f93e4a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,9 @@ SET(maintainer "ByungWoo Lee ") SET(description "Telephony SIM Framework") SET(service "telephony") SET(submodule "sim") -SET(dependents "dlog tapi glib-2.0 vconf capi-base-common") +SET(dependents "dlog tapi glib-2.0 capi-base-common") SET(pc_dependents "capi-base-common") -SET(deb_dependents "dlog-dev libslp-tapi-dev libglib2.0-dev libvconf-dev capi-base-common-dev") +SET(deb_dependents "dlog-dev libslp-tapi-dev libglib2.0-dev capi-base-common-dev") SET(Services "application" diff --git a/TC/_export_env.sh b/TC/_export_env.sh new file mode 100755 index 0000000..ac8f4a1 --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..c693f83 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,8 @@ +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +RESULT_DIR=results + +tcc -c -p ./ # executing tcc, with clean option (-c) +rm -r $RESULT_DIR +rm -r tet_tmp_dir +rm testcase/tet_captured diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..f919537 --- /dev/null +++ b/TC/config @@ -0,0 +1,2 @@ +TET_INSTALL_HOST_PATH=/home/bwlee/tools/TETware +TET_INSTALL_TARGET_PATH=/home/bwlee/tools/TETware diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..0fe02e2 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./_export_target_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100644 index 0000000..81b182b --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,24 @@ +CC ?= gcc + +C_FILES = $(shell ls *.c) + +PKGS = capi-telephony-sim + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +TCS := $(shell ls -1 *.c | cut -d. -f1) + +all: $(TCS) + +%: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TCS) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..fdb0580 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1,2 @@ +/testcase/utc_telephony_sim + diff --git a/TC/testcase/utc_telephony_sim.c b/TC/testcase/utc_telephony_sim.c new file mode 100644 index 0000000..1744ec5 --- /dev/null +++ b/TC/testcase/utc_telephony_sim.c @@ -0,0 +1,360 @@ +/* + * 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. + */ + + +#include +#include +#include + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_telephony_sim_get_icc_id_n(void); +static void utc_telephony_sim_get_icc_id_p(void); +static void utc_telephony_sim_get_mcc_n(void); +static void utc_telephony_sim_get_mcc_p(void); +static void utc_telephony_sim_get_mnc_n(void); +static void utc_telephony_sim_get_mnc_p(void); +static void utc_telephony_sim_get_msin_n(void); +static void utc_telephony_sim_get_msin_p(void); +static void utc_telephony_sim_get_spn_n(void); +static void utc_telephony_sim_get_spn_p(void); +static void utc_telephony_sim_get_cphs_operator_name_n(void); +static void utc_telephony_sim_get_cphs_operator_name_p(void); +static void utc_telephony_sim_get_state_n(void); +static void utc_telephony_sim_get_state_p(void); +static void utc_telephony_sim_get_subscriber_number_n(void); +static void utc_telephony_sim_get_subscriber_number_p(void); +static void utc_telephony_sim_set_state_changed_cb_p(void); +static void utc_telephony_sim_set_state_changed_cb_n(void); +static void utc_telephony_sim_unset_state_changed_cb_p(void); + + + +struct tet_testlist tet_testlist[] = { + { utc_telephony_sim_get_icc_id_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_icc_id_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_mcc_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_mcc_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_mnc_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_mnc_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_msin_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_msin_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_spn_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_spn_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_cphs_operator_name_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_cphs_operator_name_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_state_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_state_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_get_subscriber_number_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_get_subscriber_number_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_set_state_changed_cb_p, POSITIVE_TC_IDX }, + { utc_telephony_sim_set_state_changed_cb_n, NEGATIVE_TC_IDX }, + { utc_telephony_sim_unset_state_changed_cb_p, POSITIVE_TC_IDX }, + { NULL, 0 }, +}; + + +static void startup(void) +{ + /* start of TC */ + tet_printf("\n TC start"); +} + + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("\n TC end"); +} + +/** + * @brief Callback function + */ +void sim_state_changed(sim_state_e state, void* user_data) +{ + +} + +/** + * @brief Negative test case of sim_get_icc_id() + */ +static void utc_telephony_sim_get_icc_id_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_icc_id(NULL); + dts_check_eq("sim_get_icc_id", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_icc_id() + */ +static void utc_telephony_sim_get_icc_id_p(void) +{ + char* icc_id = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_icc_id(&icc_id); + if( icc_id != NULL ) + free(icc_id); + dts_check_eq("sim_get_icc_id", ret, SIM_ERROR_NONE, "Failed to get ICC ID"); +} + + +/** + * @brief Negative test case of sim_get_mcc() + */ +static void utc_telephony_sim_get_mcc_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_mcc(NULL); + dts_check_eq("sim_get_mcc", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_mcc() + */ +static void utc_telephony_sim_get_mcc_p(void) +{ + char* mcc = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_mcc(&mcc); + if( ret == SIM_ERROR_NONE ) + free(mcc); + dts_check_eq("sim_get_mcc", ret, SIM_ERROR_NONE, "Failed to get MCC"); +} + + +/** + * @brief Negative test case of sim_get_mnc() + */ +static void utc_telephony_sim_get_mnc_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_mnc(NULL); + dts_check_eq("sim_get_mnc", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_mnc() + */ +static void utc_telephony_sim_get_mnc_p(void) +{ + char* mnc = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_mnc(&mnc); + if( ret == SIM_ERROR_NONE ) + free(mnc); + dts_check_eq("sim_get_mnc", ret, SIM_ERROR_NONE, "Failed to get MNC"); +} + + +/** + * @brief Negative test case of sim_get_msin() + */ +static void utc_telephony_sim_get_msin_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_msin(NULL); + dts_check_eq("sim_get_msin", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_msin() + */ +static void utc_telephony_sim_get_msin_p(void) +{ + char* msin = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_msin(&msin); + if( ret == SIM_ERROR_NONE ) + free(msin); + dts_check_eq("sim_get_msin", ret, SIM_ERROR_NONE, "Failed to get MSIN"); +} + + +/** + * @brief Negative test case of sim_get_spn() + */ +static void utc_telephony_sim_get_spn_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_spn(NULL); + dts_check_eq("sim_get_spn", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_spn() + */ +static void utc_telephony_sim_get_spn_p(void) +{ + char* spn = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_spn(&spn); + if( ret == SIM_ERROR_NONE ) + free(spn); + dts_check_eq("sim_get_spn", ret, SIM_ERROR_NONE, "Failed to get SPN"); +} + + +/** + * @brief Negative test case of sim_get_cphs_operator_name() + */ +static void utc_telephony_sim_get_cphs_operator_name_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_cphs_operator_name(NULL, NULL); + dts_check_eq("sim_get_cphs_operator_name", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_cphs_operator_name() + */ +static void utc_telephony_sim_get_cphs_operator_name_p(void) +{ + char* full_name = NULL; + char* short_name = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_cphs_operator_name(&full_name, &short_name); + if( ret == SIM_ERROR_NONE ) { + free(full_name); + free(short_name); + } + dts_check_eq("sim_get_cphs_operator_name", ret, SIM_ERROR_NONE, "Failed to get CPHS full/short operator name"); +} + + +/** + * @brief Negative test case of sim_get_state() + */ +static void utc_telephony_sim_get_state_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_state(NULL); + dts_check_eq("sim_get_state", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_state() + */ +static void utc_telephony_sim_get_state_p(void) +{ + sim_state_e sim_status; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_state(&sim_status); + dts_check_eq("sim_get_state", ret, SIM_ERROR_NONE, "Failed to get the current status of SIM"); +} + + +/** + * @brief Negative test case of sim_get_subscriber_number() + */ +static void utc_telephony_sim_get_subscriber_number_n(void) +{ + int ret = SIM_ERROR_NONE; + + // Invalid parameter test + ret = sim_get_subscriber_number(NULL); + dts_check_eq("sim_get_subscriber_number", ret, SIM_ERROR_INVALID_PARAMETER, "Must return SIM_ERROR_INVALID_PARAMETER in case of invalid parameter"); +} + + +/** + * @brief Positive test case of sim_get_subscriber_number() + */ +static void utc_telephony_sim_get_subscriber_number_p(void) +{ + char* subscriber_number = NULL; + int ret = SIM_ERROR_NONE; + + // Normal operation test + ret = sim_get_subscriber_number(&subscriber_number); + if( ret == SIM_ERROR_NONE ) + { + free(subscriber_number); + dts_pass("sim_get_subscriber_number", "Succeeded to get subscriber number."); + } + else + { + dts_fail("sim_get_subscriber_number", "Failed to get subscriber number."); + } +} + + +static void utc_telephony_sim_set_state_changed_cb_p(void) +{ + sim_error_e ret = sim_set_state_changed_cb(sim_state_changed, NULL); + dts_check_eq("sim_set_state_changed_cb", ret, SIM_ERROR_NONE, + "sim_set_state_changed_cb failed."); +} + +static void utc_telephony_sim_set_state_changed_cb_n(void) +{ + sim_error_e ret = sim_set_state_changed_cb(NULL, NULL); + dts_check_eq("sim_set_state_changed_cb", ret, SIM_ERROR_INVALID_PARAMETER, + "SIM_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +static void utc_telephony_sim_unset_state_changed_cb_p(void) +{ + sim_error_e ret = sim_unset_state_changed_cb(); + dts_check_eq("sim_unset_state_changed_cb", ret, SIM_ERROR_NONE, + "sim_unset_state_changed_cb failed."); +} + + diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option for build operation checking +TET_BUILD_TOOL=make # build with using make command +TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build +TET_API_COMPLIANT=True # use TET API in Test Case ? +TET_PASS_TC_NAME=True # report passed TC name in Journal file? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option +TET_CLEAN_TOOL= make clean # clean tool +TET_CLEAN_FILE= Makefile # file for clean +TET_API_COMPLIANT=True # TET API useage +TET_PASS_TC_NAME=True # showing name , passed TC diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capturing execution or not +TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional +TET_EXEC_FILE= # ex) exectool : execution file/ Optional +TET_API_COMPLIANT=True # Test case or Tool usesTET API? +TET_PASS_TC_NAME=True # showing Passed TC name ? diff --git a/debian/changelog b/debian/changelog index 5ab3d50..9c9d846 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,7 @@ capi-telephony-sim (0.1.0-12) unstable; urgency=low * Correct dependent packages - * Git: api/sim + * Git: slp/api/sim * Tag: capi-telephony-sim_0.1.0-12 -- ByungWoo Lee Thu, 15 Mar 2012 13:32:00 +0900 @@ -9,15 +9,15 @@ capi-telephony-sim (0.1.0-12) unstable; urgency=low capi-telephony-sim (0.1.0-11) unstable; urgency=low * Add new APIs(sim_get_msin, sim_get_cphs_operator_name),related TCs and test code - * Git: api/sim + * Git: slp/api/sim * Tag: capi-telephony-sim_0.1.0-11 -- Kyeongchul Kim Wed, 07 Mar 2012 13:54:07 +0900 capi-telephony-sim (0.1.0-10) unstable; urgency=low - * Convert internal symbol to static - * Git: api/sim + * Modify coding style + * Git: slp/api/sim * Tag: capi-telephony-sim_0.1.0-10 -- ByungWoo Lee Mon, 20 Feb 2012 15:54:30 +0900 @@ -25,23 +25,112 @@ capi-telephony-sim (0.1.0-10) unstable; urgency=low capi-telephony-sim (0.1.0-9) unstable; urgency=low * Add versioning of library - * Git: api/sim + * Git: slp/api/sim * Tag: capi-telephony-sim_0.1.0-9 -- ByungWoo Lee Tue, 14 Feb 2012 17:22:41 +0900 capi-telephony-sim (0.1.0-8) unstable; urgency=low - * Update version - * Git: api/sim - * Tag: capi-telephony-sim_0.1.0-8 + * Return NULL when there does not exist value + * Git: slp/api/sim + * Tag: capi-telephony-sim_0.1.0-8 - -- ByungWoo Lee Thu, 15 Dec 2011 13:17:30 +0900 + -- ByungWoo Lee Thu, 15 Dec 2011 18:52:55 +0900 + +capi-telephony-sim (0.1.0-7) unstable; urgency=low + + * Add LICENSE, remove COPYING and Convert TIZEN_ERROR_OK to TIZEN_ERROR_NONE + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-7 + + -- ByungWoo Lee Mon, 05 Dec 2011 12:58:17 +0900 + +capi-telephony-sim (0.1.0-6) unstable; urgency=low + + * Support only one callback not several callback and modify log + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-6 + + -- ByungWoo Lee Wed, 30 Nov 2011 19:46:33 +0900 + +capi-telephony-sim (0.1.0-5) unstable; urgency=low + + * sim_get_subscriber_name() is deprecated + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-5 + + -- ByungWoo Lee Wed, 23 Nov 2011 16:56:57 +0900 + +capi-telephony-sim (0.1.0-4) unstable; urgency=low + + * Convert SLP into TIZEN + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-4 + + -- ByungWoo Lee Wed, 23 Nov 2011 13:35:01 +0900 + +capi-telephony-sim (0.1.0-3) unstable; urgency=low + + * Put boilerplate in the source code + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-3 + + -- ByungWoo Lee Wed, 02 Nov 2011 19:20:27 +0900 + +capi-telephony-sim (0.1.0-2) unstable; urgency=low + + * Set the length of ICC ID to copy and Correct bug when remove callback function + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-2 + + -- ByungWoo Lee Fri, 07 Oct 2011 18:18:29 +0900 + +capi-telephony-sim (0.1.0-1) unstable; urgency=low + + * SLP API baseline + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.1.0-1 + + -- ByungWoo Lee Tue, 27 Sep 2011 22:34:35 +0900 + +capi-telephony-sim (0.0.1-5) unstable; urgency=low + + * Remove SIM_ERROR_NO_DATA + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.0.1-5 + + -- ByungWoo Lee Fri, 23 Sep 2011 18:01:09 +0900 + +capi-telephony-sim (0.0.1-4) unstable; urgency=low + + * Conver SIM_ERROR_INTERNAL to SIM_ERROR_OPERATION_FAILED + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.0.1-4 + + -- ByungWoo Lee Mon, 05 Sep 2011 21:03:47 +0900 + +capi-telephony-sim (0.0.1-3) unstable; urgency=low + + * Remove mutex + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.0.1-3 + + -- ByungWoo Lee Mon, 22 Aug 2011 16:01:41 +0900 + +capi-telephony-sim (0.0.1-2) unstable; urgency=low + + * Correct a problem about extern C + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.0.1-2 + + -- ByungWoo Lee Mon, 22 Aug 2011 09:19:10 +0900 capi-telephony-sim (0.0.1-1) unstable; urgency=low - * Initial release. - * Git: api/sim - * Tag: capi-telephony-sim_0.0.1-1 + * Initial upload + * Git: slp-source.sec.samsung.net:slp/api/sim + * Tag: capi-telephony-sim_0.0.1-1 + + -- ByungWoo Lee Thu, 04 Aug 2011 17:47:44 +0900 - -- ByungWoo Lee Wed, 07 Dec 2011 12:47:03 +0900 diff --git a/debian/control b/debian/control index 245f421..fff1084 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Source: capi-telephony-sim Section: libs Priority: extra Maintainer: Kangho Hur , ByungWoo Lee , kyeongchul.kim , JaYoung Gu -Build-Depends: debhelper (>= 5), dlog-dev, libslp-tapi-dev, libglib2.0-dev, libvconf-dev, capi-base-common-dev +Build-Depends: debhelper (>= 5), dlog-dev, libslp-tapi-dev, libglib2.0-dev, capi-base-common-dev Package: capi-telephony-sim Architecture: any diff --git a/packaging/capi-telephony-sim.spec b/packaging/capi-telephony-sim.spec index 536f1d6..07281b8 100644 --- a/packaging/capi-telephony-sim.spec +++ b/packaging/capi-telephony-sim.spec @@ -1,15 +1,15 @@ +#sbs-git:slp/api/sim capi-telephony-sim 0.1.0 338620cf30c11d71e7f17c6cad5968ac57d724d4 Name: capi-telephony-sim Summary: Telephony SIM Framework -Version: 0.1.0 -Release: 12 +Version: 0.1.2 +Release: 1 Group: TO_BE/FILLED_IN -License: Apache-2.0 +License: TO BE FILLED IN Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-base-common) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/sim.c b/src/sim.c index fb24a09..1bc52df 100644 --- a/src/sim.c +++ b/src/sim.c @@ -14,40 +14,41 @@ * limitations under the License. */ - #include -#include +#include +#include #include -#include -#include + #include #include #include #include + #include +#include +#include #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "TIZEN_N_SIM" -typedef struct sim_cb_data -{ +struct tapi_handle { + gpointer dbus_connection; + char *path; + char *cp_name; + GHashTable *evt_list; + char cookie[20]; +}; + +typedef struct sim_cb_data { sim_state_e previous_state; - const void* cb; + struct tapi_handle *th; + void* cb; void* user_data; } sim_cb_data; -// Whether vconf_notifiy_key_chnaged is registered or not -static bool init_is_registered = false; -static bool chv_is_registered = false; -static bool slot_is_registered = false; - -// Callback function data -static sim_cb_data sim_state_cb = {SIM_STATE_UNKNOWN, NULL, NULL}; - -// Callback function adapter -static void __sim_state_changed_cb_adapter(keynode_t *node, void* user_data); +static struct tapi_handle *ghandle = NULL; // Internal Macros #define SIM_CHECK_INPUT_PARAMETER(arg) \ @@ -57,281 +58,298 @@ static void __sim_state_changed_cb_adapter(keynode_t *node, void* user_data); return SIM_ERROR_INVALID_PARAMETER; \ } -#define SIM_INIT() \ - if( tel_init() != TAPI_API_SUCCESS ) \ - { \ +#define SIM_INIT(th) \ + th = tel_init(NULL); \ + if (!th) { \ LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); \ return SIM_ERROR_OPERATION_FAILED; \ } +#define SIM_MAKE_CB(ccb,th,callback,user_data) \ + ccb = (sim_cb_data*) calloc(sizeof(sim_cb_data), 1);\ + ccb->th = th; \ + ccb->cb = (void*) callback;\ + ccb->user_data = user_data + +static sim_error_e _convert_access_rt_to_sim_error(TelSimAccessResult_t access_rt) +{ + sim_error_e error = SIM_ERROR_NONE; + switch (access_rt) { + case TAPI_SIM_ACCESS_SUCCESS: + error = SIM_ERROR_NONE; + break; + case TAPI_SIM_ACCESS_FILE_NOT_FOUND: + case TAPI_SIM_ACCESS_ACCESS_CONDITION_NOT_SATISFIED: + error = SIM_ERROR_NOT_AVAILABLE; + break; + case TAPI_SIM_ACCESS_CARD_ERROR: + case TAPI_SIM_ACCESS_FAILED: + default: + error = SIM_ERROR_OPERATION_FAILED; + break; + } + return error; +} int sim_get_icc_id(char** icc_id) { - TelSimIccIdInfo_t icc_data; int error_code = SIM_ERROR_NONE; int card_changed = 0; TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; + GError *gerr = NULL; + GVariant *sync_gv = NULL; + gchar *iccid = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; SIM_CHECK_INPUT_PARAMETER(icc_id); - SIM_INIT(); - - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 - || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { - LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); - error_code = SIM_ERROR_NOT_AVAILABLE; - } - - else - { - if( tel_get_sim_iccid(&icc_data) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - *icc_id = strndup(icc_data.icc_num, icc_data.icc_length); - if( *icc_id == NULL ) - { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); - error_code = SIM_ERROR_OUT_OF_MEMORY; - } + SIM_INIT(th); + + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); + error_code = SIM_ERROR_NOT_AVAILABLE; + } else { + sync_gv = g_dbus_connection_call_sync(th->dbus_connection, DBUS_TELEPHONY_SERVICE, th->path, + DBUS_TELEPHONY_SIM_INTERFACE, "GetICCID", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &gerr); + + if (sync_gv) { + g_variant_get(sync_gv, "(is)", &result, &iccid); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + if (iccid != NULL && strlen(iccid) != 0) { + *icc_id = (char*) malloc(strlen(iccid) + 1); + if (*icc_id == NULL) { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*icc_id, strlen(iccid) + 1, "%s", iccid); + } + } else { + *icc_id = NULL; + } + } else { + error_code = _convert_access_rt_to_sim_error(result); + } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + g_error_free(gerr); + error_code = SIM_ERROR_OPERATION_FAILED; } } - - tel_deinit(); + tel_deinit(th); return error_code; } - int sim_get_mcc(char** mcc) { TelSimImsiInfo_t sim_imsi_info; int error_code = SIM_ERROR_NONE; int card_changed = 0; TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; SIM_CHECK_INPUT_PARAMETER(mcc); - SIM_INIT(); - - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 - || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { - LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); - error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - if( tel_get_sim_imsi(&sim_imsi_info) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - *mcc = (char*)malloc(sizeof(char) * (TAPI_SIM_MCC_CODE_LEN+1)); - if( *mcc == NULL ) - { + SIM_INIT(th); + + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); + error_code = SIM_ERROR_NOT_AVAILABLE; + } else { + if (tel_get_sim_imsi(th, &sim_imsi_info) != 0) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + error_code = SIM_ERROR_OPERATION_FAILED; + } else { + *mcc = (char*) malloc(sizeof(char) * (3 + 1)); + if (*mcc == NULL) { LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); - error_code = SIM_ERROR_OUT_OF_MEMORY; - } - else - { - strncpy(*mcc, sim_imsi_info.szMcc, TAPI_SIM_MCC_CODE_LEN+1); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*mcc, strlen(sim_imsi_info.szMcc) + 1, "%s", sim_imsi_info.szMcc); } } } - - tel_deinit(); + tel_deinit(th); return error_code; } - int sim_get_mnc(char** mnc) { TelSimImsiInfo_t sim_imsi_info; int error_code = SIM_ERROR_NONE; int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; + TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; SIM_CHECK_INPUT_PARAMETER(mnc); - SIM_INIT(); + SIM_INIT(th); - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 - || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { - LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); - error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - if( tel_get_sim_imsi(&sim_imsi_info) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - *mnc = (char*)malloc(sizeof(char) * (TAPI_SIM_MNC_CODE_LEN+1)); - if( *mnc == NULL ) - { + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 + || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); + error_code = SIM_ERROR_NOT_AVAILABLE; + } else { + if (tel_get_sim_imsi(th, &sim_imsi_info) != 0) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + error_code = SIM_ERROR_OPERATION_FAILED; + } else { + *mnc = (char*) malloc(sizeof(char) * (3 + 1)); + if (*mnc == NULL) { LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); error_code = SIM_ERROR_OUT_OF_MEMORY; - } - else - { - strncpy(*mnc, sim_imsi_info.szMnc, TAPI_SIM_MNC_CODE_LEN+1); + } else { + snprintf(*mnc, strlen(sim_imsi_info.szMnc) + 1, "%s", sim_imsi_info.szMnc); } } } - tel_deinit(); + tel_deinit(th); return SIM_ERROR_NONE; } - int sim_get_msin(char** msin) { TelSimImsiInfo_t sim_imsi_info; int error_code = SIM_ERROR_NONE; int card_changed = 0; TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; SIM_CHECK_INPUT_PARAMETER(msin); - SIM_INIT(); + SIM_INIT(th); - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 - || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - if( tel_get_sim_imsi(&sim_imsi_info) != 0 ) - { + } else { + if (tel_get_sim_imsi(th, &sim_imsi_info) != 0) { LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - *msin = (char*)malloc(sizeof(char) * (TAPI_SIM_MSIN_CODE_LEN+1)); - if( *msin == NULL ) - { + } else { + *msin = (char*) malloc(sizeof(char) * (10 + 1)); + if (*msin == NULL) { LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); error_code = SIM_ERROR_OUT_OF_MEMORY; - } - else - { - strncpy(*msin, sim_imsi_info.szMsin, TAPI_SIM_MSIN_CODE_LEN+1); + } else { + snprintf(*msin, strlen(sim_imsi_info.szMsin) + 1, "%s", sim_imsi_info.szMsin); } } } - - tel_deinit(); + tel_deinit(th); return error_code; } - int sim_get_spn(char** spn) { int error_code = SIM_ERROR_NONE; int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - char* service_provider_name = NULL; + TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; + GError *gerr = NULL; + GVariant *sync_gv = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + gchar *spn_str = NULL; + guchar dc = 0; SIM_CHECK_INPUT_PARAMETER(spn); - SIM_INIT(); + SIM_INIT(th); - error_code = tel_get_sim_init_info(&sim_card_state, &card_changed); - if( error_code != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { - LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); - error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - service_provider_name = vconf_get_str(VCONFKEY_TELEPHONY_SPN_NAME); - if( service_provider_name == NULL ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 + || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); + error_code = SIM_ERROR_NOT_AVAILABLE; + } else { + sync_gv = g_dbus_connection_call_sync(th->dbus_connection, DBUS_TELEPHONY_SERVICE, th->path, + DBUS_TELEPHONY_SIM_INTERFACE, "GetSpn", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &gerr); + + if (sync_gv) { + g_variant_get(sync_gv, "(iys)", &result, &dc, &spn_str); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + if (spn_str != NULL && strlen(spn_str) != 0) { + *spn = (char*) malloc(strlen(spn_str) + 1); + if (*spn == NULL) { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*spn, strlen(spn_str) + 1, "%s", spn_str); + } + } else { + *spn = NULL; + } + } else { + error_code = _convert_access_rt_to_sim_error(result); + } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + g_error_free(gerr); error_code = SIM_ERROR_OPERATION_FAILED; } - else if( strlen(service_provider_name) == 0 ) - { - LOGI("[%s] spn has no value", __FUNCTION__); - free(service_provider_name); - *spn = NULL; - } - else - { - *spn = service_provider_name; - } } - - tel_deinit(); + tel_deinit(th); return error_code; } - int sim_get_cphs_operator_name(char** full_name, char** short_name) { - TelSimCphsLocalInfo_t cphs_info; int error_code = SIM_ERROR_NONE; int card_changed = 0; TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; + GError *gerr = NULL; + GVariant *sync_gv = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + gchar *full_str = NULL; + gchar *short_str = NULL; SIM_CHECK_INPUT_PARAMETER(full_name); SIM_CHECK_INPUT_PARAMETER(short_name); - SIM_INIT(); + SIM_INIT(th); - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 - || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 + || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - if( tel_get_sim_cphs_info(&cphs_info) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - if(cphs_info.opname.NameLength) - { - *full_name = strndup((const char*)cphs_info.opname.OperatorName, cphs_info.opname.NameLength); - if(*full_name == NULL) - { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); - error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + sync_gv = g_dbus_connection_call_sync(th->dbus_connection, DBUS_TELEPHONY_SERVICE, th->path, + DBUS_TELEPHONY_SIM_INTERFACE, "GetCphsNetName", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &gerr); + + if (sync_gv) { + g_variant_get(sync_gv, "(iss)", &result, &full_str, &short_str); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + if (full_str != NULL && strlen(full_str) != 0) { + *full_name = (char*) malloc(strlen(full_str) + 1); + if (*full_name == NULL) { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*full_name, strlen(full_str) + 1, "%s", full_str); + } + } else { + *full_name = NULL; } - } - else - { - *full_name = NULL; - } - if(cphs_info.opshortform.ShortNameLength) - { - *short_name = strndup((const char*)cphs_info.opshortform.OperatorShortName, cphs_info.opshortform.ShortNameLength); - if(*short_name == NULL) - { - LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); - error_code = SIM_ERROR_OUT_OF_MEMORY; + if (short_str != NULL && strlen(short_str) != 0) { + *short_name = (char*) malloc(strlen(short_str) + 1); + if (*short_name == NULL) { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*short_name, strlen(short_str) + 1, "%s", short_str); + } + } else { + *short_name = NULL; } + } else { + error_code = _convert_access_rt_to_sim_error(result); } - else - { - *short_name = NULL; - } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + g_error_free(gerr); + error_code = SIM_ERROR_OPERATION_FAILED; } } - - tel_deinit(); + tel_deinit(th); return error_code; } @@ -340,19 +358,16 @@ int sim_get_state(sim_state_e* sim_state) int card_changed = 0; TelSimCardStatus_t sim_card_state = 0x00; int error_code = SIM_ERROR_NONE; + struct tapi_handle *th = NULL; SIM_CHECK_INPUT_PARAMETER(sim_state); - SIM_INIT(); + SIM_INIT(th); - if( tel_get_sim_init_info(&sim_card_state, &card_changed) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); error_code = SIM_ERROR_OPERATION_FAILED; - } - else - { - switch(sim_card_state) - { + } else { + switch (sim_card_state) { case TAPI_SIM_STATUS_CARD_ERROR: *sim_state = SIM_STATE_UNAVAILABLE; break; @@ -370,193 +385,213 @@ int sim_get_state(sim_state_e* sim_state) break; case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: *sim_state = SIM_STATE_LOCKED; - break; + break; case TAPI_SIM_STATUS_CARD_BLOCKED: *sim_state = SIM_STATE_UNAVAILABLE; - break; + break; case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: *sim_state = SIM_STATE_LOCKED; - break; + break; case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: *sim_state = SIM_STATE_LOCKED; - break; + break; case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: *sim_state = SIM_STATE_LOCKED; - break; + break; case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: *sim_state = SIM_STATE_LOCKED; - break; + break; case TAPI_SIM_STATUS_CARD_REMOVED: *sim_state = SIM_STATE_UNAVAILABLE; - break; + break; case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: *sim_state = SIM_STATE_LOCKED; break; default: *sim_state = SIM_STATE_UNAVAILABLE; - break; + break; } } - tel_deinit(); + tel_deinit(th); return error_code; } - int sim_get_subscriber_number(char** subscriber_number) { int error_code = SIM_ERROR_NONE; int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - char* subscriber_number_p = NULL; + TelSimCardStatus_t sim_card_state = 0x00; + struct tapi_handle *th = NULL; + GError *gerr = NULL; + GVariant *sync_gv = NULL; + GVariant *value = NULL; + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + const gchar *key = NULL; + const gchar *str_value = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + TelSimMsisdnList_t list; + int i = 0; SIM_CHECK_INPUT_PARAMETER(subscriber_number); - SIM_INIT(); + SIM_INIT(th); - error_code = tel_get_sim_init_info(&sim_card_state, &card_changed); - if( error_code != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED ) - { - LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); - error_code = SIM_ERROR_NOT_AVAILABLE; - } - else - { - subscriber_number_p = vconf_get_str(VCONFKEY_TELEPHONY_SUBSCRIBER_NUMBER); - if( subscriber_number_p == NULL ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0 || sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, SIM_ERROR_NOT_AVAILABLE); + error_code = SIM_ERROR_NOT_AVAILABLE; + } else { + sync_gv = g_dbus_connection_call_sync(th->dbus_connection, DBUS_TELEPHONY_SERVICE, th->path, + DBUS_TELEPHONY_SIM_INTERFACE, "GetMSISDN", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, + NULL, &gerr); + + if (sync_gv) { + memset(&list, 0, sizeof(TelSimMsisdnList_t)); + g_variant_get(sync_gv, "(iaa{sv})", &result, &iter); + list.count = g_variant_iter_n_children(iter); + + if (result == TAPI_SIM_ACCESS_SUCCESS) { + i = 0; + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) { + if (!g_strcmp0(key, "name")) { + str_value = g_variant_get_string(value, NULL); + snprintf(list.list[i].name, strlen(str_value) + 1, "%s", str_value); + } + if (!g_strcmp0(key, "number")) { + str_value = g_variant_get_string(value, NULL); + snprintf(list.list[i].num, strlen(str_value) + 1, "%s", str_value); + } + } + i++; + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); + + if (list.list[0].num != NULL && strlen(list.list[0].num) != 0) { + *subscriber_number = (char*) malloc(strlen(list.list[0].num) + 1); + if (*subscriber_number == NULL) { + LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SIM_ERROR_OUT_OF_MEMORY); + error_code = SIM_ERROR_OUT_OF_MEMORY; + } else { + snprintf(*subscriber_number, strlen(list.list[0].num) + 1, "%s", + list.list[0].num); + } + } else { + *subscriber_number = NULL; + } + + } else { + error_code = _convert_access_rt_to_sim_error(result); + } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + g_error_free(gerr); error_code = SIM_ERROR_OPERATION_FAILED; } - else if( strlen(subscriber_number_p) == 0 ) - { - LOGI("[%s] subscriber number has no value", __FUNCTION__); - free(subscriber_number_p); - *subscriber_number = NULL; - } - else - { - *subscriber_number = subscriber_number_p; - } } - - tel_deinit(); + tel_deinit(th); return error_code; } -int sim_set_state_changed_cb(sim_state_changed_cb sim_cb, void* user_data) +static void on_noti_sim_status(struct tapi_handle *handle, const char *noti_id, void *data, + void *user_data) { + TelSimCardStatus_t *status = data; + sim_cb_data *ccb = user_data; sim_state_e state = SIM_STATE_UNKNOWN; - - SIM_CHECK_INPUT_PARAMETER(sim_cb); - - if( sim_get_state(&state) != SIM_ERROR_NONE ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to get current state of SIM", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; + sim_state_changed_cb cb; + LOGE("event(%s) receive with status[%d]", TAPI_NOTI_SIM_STATUS, *status); + + switch (*status) { + case TAPI_SIM_STATUS_CARD_ERROR: + state = SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + state = SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_INITIALIZING: + state = SIM_STATE_UNKNOWN; + break; + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + state = SIM_STATE_AVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_CARD_BLOCKED: + state = SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_CARD_REMOVED: + state = SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; + default: + state = SIM_STATE_UNAVAILABLE; + break; } - - if( init_is_registered == false) - { - if( vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_INIT, (vconf_callback_fn)__sim_state_changed_cb_adapter, NULL) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to register callback of sim initialization", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - init_is_registered = true; - } - - if( chv_is_registered == false ) - { - if( vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_CHV, (vconf_callback_fn)__sim_state_changed_cb_adapter, NULL) != 0) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to register callback of several lock verification", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - chv_is_registered = true; - } - - if( slot_is_registered == false ) - { - if(vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT, (vconf_callback_fn)__sim_state_changed_cb_adapter, NULL) != 0) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to register callback of sim slot", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - slot_is_registered = true; + if (!ccb->cb) { + LOGE("[%s] callback is null", __FUNCTION__); + return; } - - sim_state_cb.previous_state = state; - sim_state_cb.cb = sim_cb; - sim_state_cb.user_data = user_data; - - return SIM_ERROR_NONE; + cb = ccb->cb; + cb(state, ccb->user_data); } -int sim_unset_state_changed_cb() +int sim_set_state_changed_cb(sim_state_changed_cb sim_cb, void* user_data) { - if( init_is_registered == true) - { - if( vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_INIT, (vconf_callback_fn)__sim_state_changed_cb_adapter) != 0 ) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to unregister callback of sim initialization", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - init_is_registered = false; - } + int error_code = SIM_ERROR_NONE; + int ret; + sim_cb_data *ccb = NULL; - if( chv_is_registered == true ) - { - if( vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_CHV, (vconf_callback_fn)__sim_state_changed_cb_adapter) != 0) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to unregister callback of several lock verification", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - chv_is_registered = false; - } + SIM_CHECK_INPUT_PARAMETER(sim_cb); - if( slot_is_registered == true ) - { - if( vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT, (vconf_callback_fn)__sim_state_changed_cb_adapter) != 0) - { - LOGE("[%s] OPERATION_FAILED(0x%08x) : fail to unregister callback of sim slot", - __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } - slot_is_registered = false; + ghandle = tel_init(NULL); + if (!ghandle) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + return SIM_ERROR_OPERATION_FAILED; } - sim_state_cb.previous_state = SIM_STATE_UNKNOWN; - sim_state_cb.cb = NULL; - sim_state_cb.user_data = NULL; + ccb = (sim_cb_data*) calloc(sizeof(sim_cb_data), 1); + ccb->th = ghandle; + ccb->cb = (void*) sim_cb; + ccb->user_data = user_data; - return SIM_ERROR_NONE; + ret = tel_register_noti_event(ghandle, TAPI_NOTI_SIM_STATUS, on_noti_sim_status, ccb); + if (ret != TAPI_API_SUCCESS) error_code = SIM_ERROR_OPERATION_FAILED; + return error_code; } -static void __sim_state_changed_cb_adapter(keynode_t *node, void* user_data) +int sim_unset_state_changed_cb() { - sim_state_e sim_state = SIM_STATE_UNKNOWN; - - if( sim_state_cb.cb == NULL ) - { - return; - } + int error_code = SIM_ERROR_NONE; + int ret; - if( sim_get_state(&sim_state) == SIM_ERROR_NONE ) - { - if( sim_state != sim_state_cb.previous_state ) - { - ((sim_state_changed_cb)(sim_state_cb.cb))(sim_state, sim_state_cb.user_data); - sim_state_cb.previous_state = sim_state; + if (ghandle == NULL) { + ghandle = tel_init(NULL); + if (!ghandle) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); + return SIM_ERROR_OPERATION_FAILED; } } + ret = tel_deregister_noti_event(ghandle, TAPI_NOTI_SIM_STATUS); + if (ret != TAPI_API_SUCCESS) error_code = SIM_ERROR_OPERATION_FAILED; + return error_code; } - - - - - -- 2.7.4