From 86a457080ca9eacbb442504c83837f7abf2fc397 Mon Sep 17 00:00:00 2001 From: Dongchul Lim Date: Mon, 7 Apr 2014 19:45:54 +0900 Subject: [PATCH] Initial refactoring merge Change-Id: I50ce3528394635f0ad7eabb8f5ec1fbf14b48663 --- AUTHORS | 2 - CMakeLists.txt | 5 +- packaging/capi-telephony-sim.spec | 11 +- src/sim.c | 769 ++++++++++++++++----------------- test/CMakeLists.txt | 20 + test/sim_get_cphs_operator_name_test.c | 79 ++++ test/sim_get_icc_id_test.c | 66 +++ test/sim_get_mcc_test.c | 64 +++ test/sim_get_mnc_test.c | 64 +++ test/sim_get_msin_test.c | 64 +++ test/sim_get_spn_test.c | 68 +++ test/sim_get_state_test.c | 61 +++ test/sim_get_subscriber_number_test.c | 61 +++ test/sim_state_changed_test.c | 72 +++ 14 files changed, 1012 insertions(+), 394 deletions(-) delete mode 100644 AUTHORS create mode 100644 test/CMakeLists.txt create mode 100644 test/sim_get_cphs_operator_name_test.c create mode 100644 test/sim_get_icc_id_test.c create mode 100644 test/sim_get_mcc_test.c create mode 100644 test/sim_get_mnc_test.c create mode 100644 test/sim_get_msin_test.c create mode 100644 test/sim_get_spn_test.c create mode 100644 test/sim_get_state_test.c create mode 100644 test/sim_get_subscriber_number_test.c create mode 100644 test/sim_state_changed_test.c diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 0bb1836..0000000 --- a/AUTHORS +++ /dev/null @@ -1,2 +0,0 @@ -ByungWoo Lee -Kangho Hur diff --git a/CMakeLists.txt b/CMakeLists.txt index 7615f76..a78449f 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 capi-base-common") +SET(dependents "dlog tapi-3.0 glib-2.0 capi-base-common") SET(pc_dependents "capi-base-common") -SET(deb_dependents "dlog-dev libslp-tapi-dev libglib2.0-dev capi-base-common-dev") +SET(deb_dependents "dlog-dev libtapi3-devel libglib2.0-dev capi-base-common-dev") SET(Services "application" @@ -103,6 +103,7 @@ CONFIGURE_FILE( @ONLY ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +ADD_SUBDIRECTORY(test) IF(UNIX) diff --git a/packaging/capi-telephony-sim.spec b/packaging/capi-telephony-sim.spec index 8ddb220..31537cf 100644 --- a/packaging/capi-telephony-sim.spec +++ b/packaging/capi-telephony-sim.spec @@ -1,6 +1,11 @@ +%define major 3 +%define minor 0 +%define patchlevel 1 + +#sbs-git:slp/api/sim capi-telephony-sim 0.1.0 338620cf30c11d71e7f17c6cad5968ac57d724d4 Name: capi-telephony-sim Summary: Telephony SIM Framework -Version: 0.1.7 +Version: %{major}.%{minor}.%{patchlevel} Release: 1 Group: Telephony/API License: Apache-2.0 @@ -8,9 +13,11 @@ Source0: %{name}-%{version}.tar.gz Source1001: capi-telephony-sim.manifest BuildRequires: cmake BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(tapi-3.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(capi-base-common) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig %description Telephony SIM Framework. diff --git a/src/sim.c b/src/sim.c index bf0edb9..70878a0 100644 --- a/src/sim.c +++ b/src/sim.c @@ -15,9 +15,6 @@ */ #include -#include -#include -#include #include #include @@ -28,550 +25,546 @@ #include #include +#include +#include +#include +#include + #ifdef LOG_TAG #undef LOG_TAG #endif -#define LOG_TAG "TIZEN_N_SIM" - -struct tapi_handle { - gpointer dbus_connection; - char *path; - char *cp_name; - GHashTable *evt_list; - char cookie[20]; -}; +#define LOG_TAG "CAPI_TELEPHONY_SIM" -typedef struct sim_cb_data { +typedef struct { sim_state_e previous_state; - struct tapi_handle *th; - void* cb; - void* user_data; + TelHandle *th; + void *cb; + void *user_data; } sim_cb_data; -static struct tapi_handle *ghandle = NULL; +static TelHandle *handle = NULL; +static sim_cb_data *ccb = NULL; // Internal Macros #define SIM_CHECK_INPUT_PARAMETER(arg) \ - if( arg == NULL ) \ - { \ + if (arg == NULL) { \ LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SIM_ERROR_INVALID_PARAMETER); \ return SIM_ERROR_INVALID_PARAMETER; \ } #define SIM_INIT(th) \ - th = tel_init(NULL); \ + th = tapi_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 +#define SIM_DEINIT(th) tapi_deinit(th) -static sim_error_e _convert_access_rt_to_sim_error(TelSimAccessResult_t access_rt) +static sim_error_e _convert_access_rt_to_sim_error(TelSimResult access_rt) { sim_error_e error = SIM_ERROR_NONE; + switch (access_rt) { - case TAPI_SIM_ACCESS_SUCCESS: - case TAPI_SIM_ACCESS_FILE_NOT_FOUND: - error = SIM_ERROR_NONE; - break; - case TAPI_SIM_ACCESS_ACCESS_CONDITION_NOT_SATISFIED: - case TAPI_SIM_ACCESS_CARD_ERROR: - error = SIM_ERROR_NOT_AVAILABLE; - break; - case TAPI_SIM_ACCESS_FAILED: - default: - error = SIM_ERROR_OPERATION_FAILED; - break; + case TEL_SIM_RESULT_SUCCESS: + error = SIM_ERROR_NONE; + break; + case TEL_SIM_RESULT_ACCESS_CONDITION_NOT_SATISFIED: + case TEL_SIM_RESULT_CARD_ERROR: + error = SIM_ERROR_NOT_AVAILABLE; + break; + case TEL_SIM_RESULT_FAILURE: + default: + error = SIM_ERROR_OPERATION_FAILED; + break; } + return error; } -int sim_get_icc_id(char** icc_id) +static int __sim_check_init_status(TelHandle *handle) { + TelSimCardStatusInfo sim_status_info = {0,}; int error_code = SIM_ERROR_NONE; - int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - struct tapi_handle *th = NULL; - GError *gerr = NULL; + + if (tapi_sim_get_init_info(handle, &sim_status_info) != TEL_RETURN_SUCCESS + || sim_status_info.status != TEL_SIM_STATUS_SIM_INIT_COMPLETED) { + error_code = SIM_ERROR_NOT_AVAILABLE; + LOGE("[%s] NOT_AVAILABLE(0x%08x)", __FUNCTION__, error_code); + } + + return error_code; +} + +static GVariant *__sim_get_info(const char *method) +{ + GVariant *sync_gv = NULL; + char **cp_list = NULL; + GDBusConnection *dbus_connection; + GError *error = NULL; + + tapi_get_cp_name_list(&cp_list); + if (cp_list == NULL) { + LOGE("CP List is NULL"); + return NULL; + } + + dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) { + LOGE("Error Creating DBus Connection: [%s]", error->message); + g_error_free(error); + } else { + sync_gv = g_dbus_connection_call_sync(dbus_connection, + TELEPHONY_SERVICE, cp_list[0], + TELEPHONY_SIM_INTERFACE, method, + NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + + if (error) { + LOGE("g_dbus_conn failed. error (%s)", error->message); + g_error_free(error); + } + } + + /* Free cp_list */ + g_object_unref(dbus_connection); + g_strfreev(cp_list); + return sync_gv; +} + +int sim_get_icc_id(char **icc_id) +{ + TelHandle *handle = NULL; + int error_code; GVariant *sync_gv = NULL; - gchar *iccid = NULL; - TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; SIM_CHECK_INPUT_PARAMETER(icc_id); - SIM_INIT(th); + *icc_id = NULL; + SIM_INIT(handle); - 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; - *icc_id = NULL; - } 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 && iccid[0] != '\0') { - *icc_id = g_strdup(iccid); - } else { - *icc_id = NULL; - } + error_code = __sim_check_init_status(handle); + if (error_code != SIM_ERROR_NONE) { + LOGE("[%s] SIM NOT Initialized (0x%08x)", __FUNCTION__, error_code); + return error_code; + } + + sync_gv = __sim_get_info("GetIccid"); + if (sync_gv) { + gint result; + gchar *iccid = NULL; + + g_variant_get(sync_gv, "(is)", &result, &iccid); + if (result == TEL_SIM_RESULT_SUCCESS) { + if (iccid != NULL) { + *icc_id = g_strdup(iccid); + g_free(iccid); + LOGI("ICCID: [%s]", *icc_id); } else { - error_code = _convert_access_rt_to_sim_error(result); - *icc_id = NULL; + LOGE("ICCID is NULL"); } - g_free(iccid); } else { - LOGE("g_dbus_conn failed. error (%s)", gerr->message); - g_error_free(gerr); - error_code = SIM_ERROR_OPERATION_FAILED; - *icc_id = NULL; + error_code = _convert_access_rt_to_sim_error(result); + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } g_variant_unref(sync_gv); + } else { + error_code = SIM_ERROR_OPERATION_FAILED; + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -int sim_get_mcc(char** mcc) +static int __sim_get_imsi(TelHandle *handle, TelSimImsiInfo *sim_imsi_info) { - 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; + + error_code = __sim_check_init_status(handle); + if (error_code != SIM_ERROR_NONE) { + LOGE("[%s] SIM NOT Initialized (0x%08x)", __FUNCTION__, error_code); + return error_code; + } + + error_code = tapi_sim_get_imsi(handle, sim_imsi_info); + return error_code; +} + +int sim_get_mcc(char **mcc) +{ + TelHandle *handle = NULL; + TelSimImsiInfo sim_imsi_info = {"",}; + int error_code; SIM_CHECK_INPUT_PARAMETER(mcc); - SIM_INIT(th); + SIM_INIT(handle); - 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; + error_code = __sim_get_imsi(handle, &sim_imsi_info); + if (error_code != TEL_RETURN_SUCCESS) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, error_code); *mcc = NULL; } 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 = g_strdup(sim_imsi_info.szMcc); - } + *mcc = g_strdup(sim_imsi_info.mcc); + LOGI("MCC: [%s]", *mcc); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -int sim_get_mnc(char** mnc) +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; - struct tapi_handle *th = NULL; + TelHandle *handle = NULL; + TelSimImsiInfo sim_imsi_info = {"",}; + int error_code; SIM_CHECK_INPUT_PARAMETER(mnc); - SIM_INIT(th); + SIM_INIT(handle); - 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; + error_code = __sim_get_imsi(handle, &sim_imsi_info); + if (error_code != TEL_RETURN_SUCCESS) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, error_code); *mnc = NULL; } 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 = g_strdup(sim_imsi_info.szMnc); - } + *mnc = g_strdup(sim_imsi_info.mnc); + LOGI("MNC: [%s]", *mnc); } - tel_deinit(th); - return SIM_ERROR_NONE; + + SIM_DEINIT(handle); + return error_code; } -int sim_get_msin(char** msin) +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; + TelHandle *handle = NULL; + TelSimImsiInfo sim_imsi_info = {"",}; + int error_code; SIM_CHECK_INPUT_PARAMETER(msin); - SIM_INIT(th); + SIM_INIT(handle); - 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; + error_code = __sim_get_imsi(handle, &sim_imsi_info); + if (error_code != TEL_RETURN_SUCCESS) { + LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, error_code); *msin = NULL; } 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 = g_strdup(sim_imsi_info.szMsin); - } + *msin = g_strdup(sim_imsi_info.msin); + LOGI("MSIN: [%s]", *msin); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -int sim_get_spn(char** spn) +int sim_get_spn(char **spn) { - int error_code = SIM_ERROR_NONE; - int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - struct tapi_handle *th = NULL; - GError *gerr = NULL; + TelHandle *handle = NULL; + int error_code; 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(th); + *spn = NULL; + SIM_INIT(handle); - 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; - *spn = NULL; - } 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 && spn_str[0] != '\0') { - *spn = g_strdup(spn_str); - } else { - *spn = NULL; - } + error_code = __sim_check_init_status(handle); + if (error_code != SIM_ERROR_NONE) { + LOGE("[%s] SIM NOT initialized (0x%08x)", __FUNCTION__, error_code); + return error_code; + } + + sync_gv = __sim_get_info("GetSpn"); + if (sync_gv) { + gint result; + gint display_condition; + gchar *spn_str = NULL; + + g_variant_get(sync_gv, "(iis)", &result, &display_condition, &spn_str); + if (result == TEL_SIM_RESULT_SUCCESS) { + if (spn_str != NULL) { + *spn = g_strdup(spn_str); + g_free(spn_str); + LOGI("SPN: [%s]", *spn); } else { - error_code = _convert_access_rt_to_sim_error(result); - *spn = NULL; + LOGE("SPN is NULL"); } - g_free(spn_str); } else { - LOGE("g_dbus_conn failed. error (%s)", gerr->message); - g_error_free(gerr); - error_code = SIM_ERROR_OPERATION_FAILED; - *spn = NULL; + error_code = _convert_access_rt_to_sim_error(result); + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } g_variant_unref(sync_gv); + } else { + error_code = SIM_ERROR_OPERATION_FAILED; + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -int sim_get_cphs_operator_name(char** full_name, char** short_name) +int sim_get_cphs_operator_name(char **full_name, char **short_name) { - int error_code = SIM_ERROR_NONE; - int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - struct tapi_handle *th = NULL; - GError *gerr = NULL; + TelHandle *handle = NULL; + int error_code; 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(th); + *full_name = NULL; + *short_name = NULL; + SIM_INIT(handle); + + error_code = __sim_check_init_status(handle); + if (error_code != SIM_ERROR_NONE) { + LOGE("[%s] SIM NOT initialized (0x%08x)", __FUNCTION__, error_code); + return error_code; + } - 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; - *full_name = NULL; - *short_name = NULL; - } 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 && full_str[0] != '\0') { - *full_name = g_strdup(full_str); - } else { - *full_name = NULL; - } + sync_gv = __sim_get_info("GetCphsNetName"); + if (sync_gv) { + gint result; + gchar *full_str = NULL; + gchar *short_str = NULL; + + g_variant_get(sync_gv, "(iss)", &result, &full_str, &short_str); + if (result == TEL_SIM_RESULT_SUCCESS) { + if (full_str != NULL) { + *full_name = g_strdup(full_str); + g_free(full_str); + LOGI("Full name: [%s]", *full_name); + } else { + LOGE("full_name is NULL"); + } - if (short_str != NULL && short_str[0] != '\0') { - *full_name = g_strdup(short_str); - } else { - *short_name = NULL; - } + if (short_str != NULL) { + *short_name = g_strdup(short_str); + g_free(short_str); + LOGI("Short name: [%s]", *short_name); } else { - error_code = _convert_access_rt_to_sim_error(result); - *full_name = NULL; - *short_name = NULL; + LOGE("short_name is NULL"); } - g_free(full_str); - g_free(short_str); } else { - LOGE("g_dbus_conn failed. error (%s)", gerr->message); - g_error_free(gerr); - error_code = SIM_ERROR_OPERATION_FAILED; - *full_name = NULL; - *short_name = NULL; + error_code = _convert_access_rt_to_sim_error(result); + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } g_variant_unref(sync_gv); + } else { + error_code = SIM_ERROR_OPERATION_FAILED; + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -int sim_get_state(sim_state_e* sim_state) +int sim_get_state(sim_state_e *sim_state) { - int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; + TelSimCardStatusInfo sim_status_info = {0,}; int error_code = SIM_ERROR_NONE; - struct tapi_handle *th = NULL; + TelHandle *handle = NULL; SIM_CHECK_INPUT_PARAMETER(sim_state); - SIM_INIT(th); + SIM_INIT(handle); - if (tel_get_sim_init_info(th, &sim_card_state, &card_changed) != 0) { + if (tapi_sim_get_init_info(handle, &sim_status_info) != TEL_RETURN_SUCCESS) { LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - error_code = SIM_ERROR_OPERATION_FAILED; - } else { - switch (sim_card_state) { - case TAPI_SIM_STATUS_CARD_ERROR: - *sim_state = SIM_STATE_UNAVAILABLE; - break; - case TAPI_SIM_STATUS_CARD_NOT_PRESENT: - *sim_state = SIM_STATE_UNAVAILABLE; - break; - case TAPI_SIM_STATUS_SIM_INITIALIZING: - *sim_state = SIM_STATE_UNKNOWN; - break; - case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: - *sim_state = SIM_STATE_AVAILABLE; - break; - case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_CARD_BLOCKED: - *sim_state = SIM_STATE_UNAVAILABLE; - break; - case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - case TAPI_SIM_STATUS_CARD_REMOVED: - *sim_state = SIM_STATE_UNAVAILABLE; - break; - case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: - *sim_state = SIM_STATE_LOCKED; - break; - default: - *sim_state = SIM_STATE_UNAVAILABLE; - break; - } + *sim_state = SIM_STATE_UNKNOWN; + SIM_DEINIT(handle); + return SIM_ERROR_OPERATION_FAILED; + } + + switch (sim_status_info.status) { + case TEL_SIM_STATUS_CARD_ERROR: + case TEL_SIM_STATUS_SIM_CARD_POWEROFF: + case TEL_SIM_STATUS_CARD_NOT_PRESENT: + case TEL_SIM_STATUS_CARD_BLOCKED: + case TEL_SIM_STATUS_CARD_REMOVED: + *sim_state = SIM_STATE_UNAVAILABLE; + break; + case TEL_SIM_STATUS_UNKNOWN: + case TEL_SIM_STATUS_SIM_INITIALIZING: + *sim_state = SIM_STATE_UNKNOWN; + break; + case TEL_SIM_STATUS_SIM_INIT_COMPLETED: + *sim_state = SIM_STATE_AVAILABLE; + break; + case TEL_SIM_STATUS_SIM_PIN_REQUIRED: + case TEL_SIM_STATUS_SIM_PUK_REQUIRED: + case TEL_SIM_STATUS_SIM_NCK_REQUIRED: + case TEL_SIM_STATUS_SIM_NSCK_REQUIRED: + case TEL_SIM_STATUS_SIM_SPCK_REQUIRED: + case TEL_SIM_STATUS_SIM_CCK_REQUIRED: + case TEL_SIM_STATUS_SIM_LOCK_REQUIRED: + *sim_state = SIM_STATE_LOCKED; + break; } - tel_deinit(th); + LOGI("SIM state: [%d]", *sim_state); + + SIM_DEINIT(handle); return error_code; } -int sim_get_subscriber_number(char** subscriber_number) +int sim_get_subscriber_number(char **subscriber_number) { - int error_code = SIM_ERROR_NONE; - int card_changed = 0; - TelSimCardStatus_t sim_card_state = 0x00; - struct tapi_handle *th = NULL; - GError *gerr = NULL; + TelHandle *handle = NULL; + int error_code; 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(th); + *subscriber_number = NULL; + SIM_INIT(handle); - 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; - *subscriber_number = NULL; - } 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); - } + error_code = __sim_check_init_status(handle); + if (error_code != SIM_ERROR_NONE) { + LOGE("[%s] SIM NOT initialized (0x%08x)", __FUNCTION__, error_code); + return error_code; + } + + sync_gv = __sim_get_info("GetMsisdn"); + if (sync_gv) { + gint result; + GVariant *var = NULL; + TelSimMsisdnList msisdn_list = {0,}; + + g_variant_get(sync_gv, "(iu@aa{sv})", &result, &msisdn_list.count, &var); + if (result == TEL_SIM_RESULT_SUCCESS && msisdn_list.count) { + int i = 0; + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + + LOGI("MSISDN list count: [%d]", msisdn_list.count); + msisdn_list.list = g_malloc0(msisdn_list.count * sizeof(TelSimMsisdnList)); + g_variant_get(var, "aa{sv}", &iter); + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + const gchar *key; + GVariant *key_value; + while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) { + if (g_strcmp0(key, "alpha_id") == 0) { + msisdn_list.list[i].alpha_id = + g_strdup(g_variant_get_string(key_value, NULL)); } - i++; - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - - if (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); + + if (g_strcmp0(key, "num") == 0) { + msisdn_list.list[i].num = + g_strdup(g_variant_get_string(key_value, NULL)); } - } else { - *subscriber_number = NULL; } + i++; + g_variant_iter_free(iter_row); + } + g_variant_iter_free(iter); - } else { - error_code = _convert_access_rt_to_sim_error(result); - *subscriber_number = NULL; + /* Only set first number */ + if (msisdn_list.count) { + *subscriber_number = g_strdup(msisdn_list.list[0].num); + LOGI("Subscribe Number: [%s]", *subscriber_number); } + + /* Free resources */ + for (i = 0; i < msisdn_list.count; i++) { + g_free(msisdn_list.list[i].alpha_id); + g_free(msisdn_list.list[i].num); + } + g_free(msisdn_list.list); } else { - LOGE("g_dbus_conn failed. error (%s)", gerr->message); - g_error_free(gerr); - error_code = SIM_ERROR_OPERATION_FAILED; - *subscriber_number = NULL; + error_code = _convert_access_rt_to_sim_error(result); + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } g_variant_unref(sync_gv); + } else { + error_code = SIM_ERROR_OPERATION_FAILED; + LOGE("[%s] Operation Failed!!! (0x%08x)", __FUNCTION__, error_code); } - tel_deinit(th); + + SIM_DEINIT(handle); return error_code; } -static void on_noti_sim_status(struct tapi_handle *handle, const char *noti_id, void *data, - void *user_data) +static void on_noti_sim_status(TelHandle *handle, const char *noti_id, + void *data, void *user_data) { - TelSimCardStatus_t *status = data; - sim_cb_data *ccb = user_data; + TelSimCardStatus *status = data; sim_state_e state = SIM_STATE_UNKNOWN; sim_state_changed_cb cb; - LOGE("event(%s) receive with status[%d]", TAPI_NOTI_SIM_STATUS, *status); + + LOGE("event(%s) receive with status[%d]", TEL_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; + case TEL_SIM_STATUS_CARD_ERROR: + case TEL_SIM_STATUS_SIM_CARD_POWEROFF: + case TEL_SIM_STATUS_CARD_NOT_PRESENT: + case TEL_SIM_STATUS_CARD_BLOCKED: + case TEL_SIM_STATUS_CARD_REMOVED: + state = SIM_STATE_UNAVAILABLE; + break; + case TEL_SIM_STATUS_UNKNOWN: + case TEL_SIM_STATUS_SIM_INITIALIZING: + state = SIM_STATE_UNKNOWN; + break; + case TEL_SIM_STATUS_SIM_INIT_COMPLETED: + state = SIM_STATE_AVAILABLE; + break; + case TEL_SIM_STATUS_SIM_PIN_REQUIRED: + case TEL_SIM_STATUS_SIM_PUK_REQUIRED: + case TEL_SIM_STATUS_SIM_NCK_REQUIRED: + case TEL_SIM_STATUS_SIM_NSCK_REQUIRED: + case TEL_SIM_STATUS_SIM_SPCK_REQUIRED: + case TEL_SIM_STATUS_SIM_CCK_REQUIRED: + case TEL_SIM_STATUS_SIM_LOCK_REQUIRED: + state = SIM_STATE_LOCKED; + break; } + if (!ccb->cb) { LOGE("[%s] callback is null", __FUNCTION__); return; } + cb = ccb->cb; cb(state, ccb->user_data); } -int sim_set_state_changed_cb(sim_state_changed_cb sim_cb, void* user_data) +int sim_set_state_changed_cb(sim_state_changed_cb sim_cb, void *user_data) { int error_code = SIM_ERROR_NONE; - int ret; - sim_cb_data *ccb = NULL; SIM_CHECK_INPUT_PARAMETER(sim_cb); - ghandle = tel_init(NULL); - if (!ghandle) { - LOGE("[%s] OPERATION_FAILED(0x%08x)", __FUNCTION__, SIM_ERROR_OPERATION_FAILED); - return SIM_ERROR_OPERATION_FAILED; - } + if (handle == NULL) + SIM_INIT(handle); - ccb = (sim_cb_data*) calloc(sizeof(sim_cb_data), 1); - ccb->th = ghandle; - ccb->cb = (void*) sim_cb; + if (ccb == NULL) + ccb = g_malloc0(sizeof(sim_cb_data)); + + ccb->th = handle; + ccb->cb = (void *)sim_cb; ccb->user_data = user_data; - 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; + error_code = tapi_register_event_id(handle, TEL_NOTI_SIM_STATUS, on_noti_sim_status, NULL); + if (error_code != TEL_RETURN_SUCCESS) { + error_code = SIM_ERROR_OPERATION_FAILED; + SIM_DEINIT(handle); + handle = NULL; + g_free(ccb); + ccb = NULL; + } + return error_code; } int sim_unset_state_changed_cb() { int error_code = SIM_ERROR_NONE; - int ret; - 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; + if (handle == NULL) + return SIM_ERROR_NONE; + + error_code = tapi_deregister_event_id(handle, TEL_NOTI_SIM_STATUS); + if (error_code != TEL_RETURN_SUCCESS) + error_code = SIM_ERROR_OPERATION_FAILED; + + SIM_DEINIT(handle); + handle = NULL; + g_free(ccb); + ccb = NULL; return error_code; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..97657b6 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED glib-2.0) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") + +#ADD_EXECUTABLE("system-sensor" system-sensor.c) +#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS}) + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() diff --git a/test/sim_get_cphs_operator_name_test.c b/test/sim_get_cphs_operator_name_test.c new file mode 100644 index 0000000..2df35fd --- /dev/null +++ b/test/sim_get_cphs_operator_name_test.c @@ -0,0 +1,79 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* full_name = NULL; + char* short_name = NULL; + int ret_value = sim_get_cphs_operator_name(&full_name, &short_name); + + switch(ret_value) + { + case SIM_ERROR_NONE: + ret = 0; + if( full_name != NULL ) + { + LOGI("CPHS full ONS is %s", full_name); + g_free(full_name); + } + else + { + LOGI("CPHS full ONS is NULL"); + } + + if( short_name != NULL ) + { + LOGI("CPHS short ONS is %s", short_name); + g_free(short_name); + } + else + { + LOGI("CPHS short ONS is NULL"); + } + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Cannot find SPN value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + + return ret; +} diff --git a/test/sim_get_icc_id_test.c b/test/sim_get_icc_id_test.c new file mode 100644 index 0000000..5f0229d --- /dev/null +++ b/test/sim_get_icc_id_test.c @@ -0,0 +1,66 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + + +int main() +{ + int ret = 0; + char* icc_id = NULL; + int ret_value = sim_get_icc_id(&icc_id); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("ICC-ID is %s", icc_id); + ret = 0; + if(icc_id != NULL) + g_free(icc_id); + break; + case SIM_ERROR_OUT_OF_MEMORY: + LOGI("Out of memory\n"); + ret = -1; + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGI("Invalid parameter\n"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGI("Can not get ICC-ID value\n"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGI("SIM is not available\n"); + ret = -1; + break; + default: + LOGI("Unexpected return value\n"); + ret = -1; + break; + } + + return ret; +} diff --git a/test/sim_get_mcc_test.c b/test/sim_get_mcc_test.c new file mode 100644 index 0000000..6b4f3f5 --- /dev/null +++ b/test/sim_get_mcc_test.c @@ -0,0 +1,64 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* mcc = NULL; + int ret_value = sim_get_mcc(&mcc); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("MCC is %s", mcc); + ret = 0; + g_free(mcc); + break; + case SIM_ERROR_OUT_OF_MEMORY: + LOGE("Out of memory"); + ret = -1; + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Can not get MCC value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + return ret; +} diff --git a/test/sim_get_mnc_test.c b/test/sim_get_mnc_test.c new file mode 100644 index 0000000..d967044 --- /dev/null +++ b/test/sim_get_mnc_test.c @@ -0,0 +1,64 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* mnc = NULL; + int ret_value = sim_get_mnc(&mnc); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("MNC is %s", mnc); + ret = 0; + g_free(mnc); + break; + case SIM_ERROR_OUT_OF_MEMORY: + LOGE("Out of memory"); + ret = -1; + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Can not get MNC value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + return ret; +} diff --git a/test/sim_get_msin_test.c b/test/sim_get_msin_test.c new file mode 100644 index 0000000..e44a790 --- /dev/null +++ b/test/sim_get_msin_test.c @@ -0,0 +1,64 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* msin = NULL; + int ret_value = sim_get_msin(&msin); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("MSIN is %s", msin); + ret = 0; + g_free(msin); + break; + case SIM_ERROR_OUT_OF_MEMORY: + LOGE("Out of memory"); + ret = -1; + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Can not get MNC value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + return ret; +} diff --git a/test/sim_get_spn_test.c b/test/sim_get_spn_test.c new file mode 100644 index 0000000..3e6ae90 --- /dev/null +++ b/test/sim_get_spn_test.c @@ -0,0 +1,68 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* spn = NULL; + int ret_value = sim_get_spn(&spn); + + switch(ret_value) + { + case SIM_ERROR_NONE: + ret = 0; + if( spn != NULL ) + { + LOGI("SPN is %s", spn); + g_free(spn); + } + else + { + LOGI("SPN is NULL"); + } + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Cannot find SPN value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + + return ret; +} diff --git a/test/sim_get_state_test.c b/test/sim_get_state_test.c new file mode 100644 index 0000000..b5d102f --- /dev/null +++ b/test/sim_get_state_test.c @@ -0,0 +1,61 @@ +/* + * 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 +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +static const char *capi_sim_state[] = { + "UNAVAILABLE", + "LOCKED", + "AVAILABLE", + "UNKNOWN", +}; + +int main() +{ + int ret = 0; + sim_state_e sim_state = SIM_STATE_UNAVAILABLE; + int ret_value = sim_get_state(&sim_state); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("SIM is [%s]", capi_sim_state[sim_state]); + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Can not get sim state"); + ret = -1; + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + return ret; +} diff --git a/test/sim_get_subscriber_number_test.c b/test/sim_get_subscriber_number_test.c new file mode 100644 index 0000000..efa50af --- /dev/null +++ b/test/sim_get_subscriber_number_test.c @@ -0,0 +1,61 @@ +/* + * 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 +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +int main() +{ + int ret = 0; + char* subscriber_number = NULL; + int ret_value = sim_get_subscriber_number(&subscriber_number); + + switch(ret_value) + { + case SIM_ERROR_NONE: + LOGI("Subscriber number is [%s]", subscriber_number); + ret = 0; + free(subscriber_number); + break; + case SIM_ERROR_INVALID_PARAMETER: + LOGE("Invalid parameter"); + ret = -1; + break; + case SIM_ERROR_OPERATION_FAILED: + LOGE("Cannot find subscriber number value"); + ret = -1; + break; + case SIM_ERROR_NOT_AVAILABLE: + LOGE("SIM is not available"); + ret = -1; + break; + default: + LOGE("Unexpected return value"); + ret = -1; + break; + } + + + return ret; +} diff --git a/test/sim_state_changed_test.c b/test/sim_state_changed_test.c new file mode 100644 index 0000000..a59bddc --- /dev/null +++ b/test/sim_state_changed_test.c @@ -0,0 +1,72 @@ +/* + * 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 +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "TIZEN_N_SIM_TEST" + +static GMainLoop *event_loop; + +static const char *capi_sim_state[] = { + "UNAVAILABLE", + "LOCKED", + "AVAILABLE", + "UNKNOWN", +}; + +void sim_state_changed(sim_state_e state, void* user_data) +{ + LOGI("[%s] Start sim_state_changed_cb", __FUNCTION__); + + LOGI("[%s] Status of sim: %s", __FUNCTION__, capi_sim_state[state]); + LOGI("[%s] user data: %s", __FUNCTION__, user_data); + + LOGI("[%s] End sim_state_changed_cb", __FUNCTION__); + g_main_loop_quit(event_loop); +} + +int main() +{ + if( sim_set_state_changed_cb(sim_state_changed, "sim_state_changed_test") == SIM_ERROR_NONE ) + { + LOGI("[%s] Succeeded to add callback function", __FUNCTION__); + } + else + { + LOGE("[%s] Failed to add callback function", __FUNCTION__); + return -1; + } + + LOGI("[%s] If you change the state of SIM card, then callback function will be called", __FUNCTION__); + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + + if( sim_unset_state_changed_cb() != SIM_ERROR_NONE ) + { + LOGE("[%s] Failed to remove callback function", __FUNCTION__); + return -1; + } + LOGI("[%s] Succeeded to remove callback function", __FUNCTION__); + return 0; +} -- 2.7.4