summaryrefslogtreecommitdiff
path: root/lib/dialer/ph-dialer-tapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialer/ph-dialer-tapi.c')
-rwxr-xr-xlib/dialer/ph-dialer-tapi.c503
1 files changed, 503 insertions, 0 deletions
diff --git a/lib/dialer/ph-dialer-tapi.c b/lib/dialer/ph-dialer-tapi.c
new file mode 100755
index 0000000..5aa5a64
--- /dev/null
+++ b/lib/dialer/ph-dialer-tapi.c
@@ -0,0 +1,503 @@
+/*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.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://floralicense.org/license/
+*
+* 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 <tapi_common.h>
+#include <ITapiSim.h>
+#include <ITapiPhonebook.h>
+#include <TapiUtility.h>
+#include <regex.h>
+
+#include "phone.h"
+#include "phone-dialer.h"
+#include "ph-dialer-utils.h"
+
+#ifdef Status
+ #undef Status
+#endif
+
+static TapiHandle *handle = NULL;
+
+typedef enum {
+ SIM_INCORRECT_PIN1_CODE,
+ SIM_INCORRECT_PIN2_CODE,
+ SIM_PIN1_CHANGE_SUCCESS,
+ SIM_PIN2_CHANGE_SUCCESS,
+ SIM_PIN1_BLOCKED,
+ SIM_PIN2_BLOCKED,
+} sim_stat_value;
+
+typedef enum {
+ TYPE_PIN1 = 0,
+ TYPE_PIN2,
+} pin_type_value;
+typedef struct _tapi_receive_info {
+ sim_stat_value stat;
+ int retry_cnt;
+} tapi_receive_info;
+
+#define PIN1_REGEX "^\\*\\*04\\*[0-9]{4}\\*[0-9]{4}\\*[0-9]{4}#$"
+#define PIN2_REGEX "^\\*\\*042\\*[0-9]{4}\\*[0-9]{4}\\*[0-9]{4}#$"
+#define PUK_REGEX "\\*\\*05\\*[0-9]{8}\\*[0-9]{4}\\*[0-9]{4}#$"
+
+
+int dialer_tapi_init()
+{
+ handle = tel_init(NULL);
+ if (NULL == handle)
+ return FALSE;
+ return TRUE;
+}
+
+int dialer_tapi_deinit()
+{
+ int ret = tel_deinit(handle);
+ handle = NULL;
+ return ret;
+}
+
+int dialer_check_pin_str(const char* number, char **old_pin, char **new_pin, char **com_pin, int* pin_type)
+{
+ PH_FN_CALL;
+ regex_t fsm;
+ regmatch_t str[strlen(number)+1];
+ char* origin_string;
+ char * str_temp;
+
+ if(regcomp(&fsm, PIN1_REGEX, REG_EXTENDED))
+ {
+ PH_DBG("regular expression fail");
+ regfree(&fsm);
+ return FALSE;
+ }
+ else {
+ if(regexec(&fsm, number, strlen(number)+1, str, 0) == REG_NOMATCH)
+ {
+ PH_DBG("regular expression 1 matching fail");
+ regfree(&fsm);
+ }
+ else
+ {
+ PH_DBG("regular expression 1 matching success");
+ origin_string = strdup(number);
+ str_temp = origin_string + 5;
+ *old_pin = strdup(strtok(str_temp, "*"));
+ *new_pin = strdup(strtok(NULL, "*"));
+ *com_pin = strdup(strtok(NULL, "#"));
+ *pin_type = TYPE_PIN1;
+ free(origin_string);
+ regfree(&fsm);
+ return TRUE;
+ }
+ }
+
+ if(regcomp(&fsm, PIN2_REGEX, REG_EXTENDED))
+ {
+ PH_DBG("regular expression fail");
+ regfree(&fsm);
+ return FALSE;
+ }
+ else
+ {
+ if(regexec(&fsm, number, strlen(number)+1, str, 0) == REG_NOMATCH)
+ {
+ PH_DBG("regular expression 2 matching fail");
+ regfree(&fsm);
+ }
+ else
+ {
+ PH_DBG("regular expression 2 matching success");
+ origin_string = strdup(number);
+ str_temp = origin_string + 5;
+ *old_pin = strdup(strtok(str_temp, "*"));
+ *new_pin = strdup(strtok(NULL, "*"));
+ *com_pin = strdup(strtok(NULL, "#"));
+ *pin_type = TYPE_PIN2;
+ free(origin_string);
+ regfree(&fsm);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void dialer_pin_result_popup (tapi_receive_info* result, void* data)
+{
+ PH_FN_CALL;
+ Evas_Object *popup;
+ ph_dialer_data *dial_d = (ph_dialer_data *)data;
+
+ popup = elm_popup_add(dial_d->win);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ switch(result->stat)
+ {
+ case SIM_PIN1_CHANGE_SUCCESS :
+ case SIM_PIN2_CHANGE_SUCCESS :
+ phone_show_popup(dial_d->navi, S_(CT_SYS_POP_SUCCESS), 2.0);
+ break;
+ case SIM_INCORRECT_PIN1_CODE :
+ case SIM_INCORRECT_PIN2_CODE :
+ phone_show_popup(dial_d->navi, S_(PH_SYS_POP_INCORRECT_PASSWORD), 2.0);
+ break;
+ case SIM_PIN1_BLOCKED :
+ case SIM_PIN2_BLOCKED :
+ phone_show_popup(dial_d->navi, S_(PH_SYS_SK3_BLOCK), 2.0);
+ break;
+ default:
+ elm_object_text_set(popup, "dafault case called");
+ break;
+ }
+}
+
+
+void dialer_sim_change_pins_cb(TapiHandle *handle, int result, void *data, void *user_data)
+{
+ PH_FN_CALL;
+ TelSimPinOperationResult_t sec_rt = result;
+ TelSimSecResult_t *sim_event_data = (TelSimSecResult_t *) data;
+ tapi_receive_info result_info = { 0, };
+
+ PH_DBG("sec_rt[%d]", sec_rt);
+ PH_DBG("sim_event_data->type:%d", sim_event_data->type);
+ PH_DBG("sim_event_data->retry_count[%d]", sim_event_data->retry_count);
+
+ if(sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS)
+ {
+ if(sim_event_data->type == TAPI_SIM_PTYPE_PIN1)
+ result_info.stat = SIM_PIN1_CHANGE_SUCCESS;
+ else if ( sim_event_data->type == TAPI_SIM_PTYPE_PIN2)
+ result_info.stat = SIM_PIN2_CHANGE_SUCCESS;
+ }
+ else if (sec_rt ==TAPI_SIM_PIN_INCORRECT_PASSWORD)
+ {
+ if (sim_event_data->type == TAPI_SIM_PTYPE_PIN1)
+ {
+ result_info.stat = SIM_INCORRECT_PIN1_CODE;
+ result_info.retry_cnt = sim_event_data->retry_count;
+ }
+ else if (sim_event_data->type == TAPI_SIM_PTYPE_PIN2)
+ {
+ result_info.stat = SIM_INCORRECT_PIN2_CODE;
+ result_info.retry_cnt = sim_event_data->retry_count;
+ }
+ }
+ else if (sec_rt == TAPI_SIM_PUK_REQUIRED)
+ {
+ if (sim_event_data->type == TAPI_SIM_PTYPE_PIN1)
+ result_info.stat = SIM_PIN1_BLOCKED;
+ else if (sim_event_data->type == TAPI_SIM_PTYPE_PIN2)
+ result_info.stat = SIM_PIN2_BLOCKED;
+ }
+ else {
+ ERR("INCORRECTED");
+ return;
+ }
+ dialer_pin_result_popup(&result_info, user_data);
+}
+
+
+void dialer_pin_operation(int type, const char *old_pin, const char *new_pin, void* data)
+{
+ PH_FN_CALL;
+ int tapi_ret = -100;
+ ph_dialer_data *dial_d = (ph_dialer_data *)data;
+
+ char old_pw[PH_TEXT_MAX_LEN] = {0};
+ char new_pw[PH_TEXT_MAX_LEN]={0};
+
+ TelSimSecPw_t sim_old_sec_data = {0, };
+ TelSimSecPw_t sim_new_sec_data = {0, };
+
+ if(handle == NULL)
+ PH_DBG("tapi handle is null");
+
+ snprintf(old_pw, sizeof(old_pw), "%s", old_pin);
+ snprintf(new_pw, sizeof(new_pw), "%s", new_pin);
+
+ switch(type)
+ {
+ case TYPE_PIN1:
+ sim_old_sec_data.type = TAPI_SIM_PTYPE_PIN1;
+ sim_new_sec_data.type = TAPI_SIM_PTYPE_PIN1;
+ sim_old_sec_data.pw_len = STRLEN(old_pw);
+ sim_old_sec_data.pw = (unsigned char *)calloc(1, sim_old_sec_data.pw_len);
+ memcpy(sim_old_sec_data.pw, old_pw, sim_old_sec_data.pw_len);
+ sim_new_sec_data.pw_len = STRLEN(new_pw);
+ sim_new_sec_data.pw = (unsigned char *)calloc(1, sim_new_sec_data.pw_len);
+ memcpy(sim_new_sec_data.pw, new_pw, sim_new_sec_data.pw_len);
+ break;
+ case TYPE_PIN2:
+ sim_old_sec_data.type = TAPI_SIM_PTYPE_PIN2;
+ sim_new_sec_data.type = TAPI_SIM_PTYPE_PIN2;
+ sim_old_sec_data.pw_len = STRLEN(old_pw);
+ sim_old_sec_data.pw = (unsigned char *)calloc(1, sim_old_sec_data.pw_len);
+ memcpy(sim_old_sec_data.pw, old_pw, sim_old_sec_data.pw_len);
+ sim_new_sec_data.pw_len = STRLEN(new_pw);
+ sim_new_sec_data.pw = (unsigned char *)calloc(1, sim_new_sec_data.pw_len);
+ memcpy(sim_new_sec_data.pw, new_pw, sim_new_sec_data.pw_len);
+ break;
+ default:
+ ERR("Never get here(type: %d)", type);
+ break;
+ }
+
+ tapi_ret = tel_change_sim_pins(handle,&sim_old_sec_data,&sim_new_sec_data, dialer_sim_change_pins_cb, data);
+ PH_DBG("return_num:%d", tapi_ret);
+
+ if(tapi_ret != TAPI_API_SUCCESS)
+ {
+ ERR("TelTapiSimChangePIN err=%d ", tapi_ret);
+ phone_show_popup(dial_d->navi, S_(CT_SYS_POP_ERROR), 2.0);
+ }
+ free(sim_old_sec_data.pw);
+ free(sim_new_sec_data.pw);
+}
+
+
+int GCF_tapi_init()
+{
+ int status;
+ int ret;
+ TelSimPbList_t pb_list;
+
+ handle = tel_init(NULL);
+ if (NULL == handle)
+ return FALSE;
+
+ ret = tel_get_sim_pb_init_info(handle, &status, &pb_list);
+ if (TAPI_API_SUCCESS != ret)
+ {
+ ERR("tel_get_sim_pb_init_info() is failed(%d)", ret);
+ tel_deinit(handle);
+ handle = NULL;
+ return FALSE;
+ }
+
+ if (!status)
+ {
+ ERR("SIM is not available");
+ tel_deinit(handle);
+ handle = NULL;
+ return FALSE;
+ }
+ return TRUE;
+}
+
+int GCF_tapi_deinit()
+{
+ int ret = tel_deinit(handle);
+ handle = NULL;
+ return ret;
+}
+
+static void sim_async_response_verify_puk(TapiHandle *handle, int result, void *data, void *user_data)
+{
+ PH_FN_CALL;
+ TelSimPinOperationResult_t sec_rt = result;
+ TelSimSecResult_t *pPinInfo = data;
+
+ if (sec_rt == TAPI_SIM_PIN_OPERATION_SUCCESS)
+ {
+ if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1)
+ {
+ ph_dialer_data *dial_d = user_data;
+ phone_show_popup(dial_d->navi, T_(PH_GET_TEXT_BASIC, PHTEXT_REQUEST_SUCCESS), 2.0);
+ }
+ else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN2)
+ PH_DBG("Unblock PIN2 Success!");
+ }
+ else
+ {
+ if (pPinInfo->type == TAPI_SIM_PTYPE_PUK1)
+ {
+ ph_dialer_data *dial_d = user_data;
+ phone_show_popup(dial_d->navi, T_(PH_GET_TEXT_BASIC, PHTEXT_REQUEST_FAIL), 2.0);
+ }
+ else if (pPinInfo->type == TAPI_SIM_PTYPE_PIN1 || pPinInfo->type == TAPI_SIM_PTYPE_PIN2 || pPinInfo->type == TAPI_SIM_PTYPE_PUK2)
+ {
+ ERR("%d Verification Failed! - PIN Required", pPinInfo->type);
+ PH_DBG("Remainint attempts [%d]", pPinInfo->retry_count);
+ }
+ }
+
+ GCF_tapi_deinit();
+}
+
+void GCF_test_puk_operation(const char *puk1, const char *pin1, void *user_data)
+{
+ PH_FN_CALL;
+ char init_pin_val[PH_TEXT_MAX_LEN] = {0};
+ char init_puk_val[PH_TEXT_MAX_LEN]={0};
+
+ TelSimSecPw_t puk_data;
+ TelSimSecPw_t new_pin_data;
+ int ret;
+
+ memset(&puk_data, 0, sizeof(TelSimSecPw_t));
+ memset(&new_pin_data, 0, sizeof(TelSimSecPw_t));
+
+ PH_DBG("puk1:%s", puk1 );
+ PH_DBG("pin1: %s", pin1 );
+
+
+ snprintf(init_puk_val, sizeof(init_puk_val), "%s", puk1);
+ snprintf(init_pin_val, sizeof(init_pin_val), "%s", pin1);
+
+ puk_data.type = TAPI_SIM_PTYPE_PUK1; // 0x00
+ puk_data.pw_len = strlen(init_puk_val);
+ puk_data.pw = (unsigned char*)calloc(1, puk_data.pw_len);
+ memcpy(puk_data.pw, init_puk_val, puk_data.pw_len);
+
+ new_pin_data.type = TAPI_SIM_PTYPE_PIN1; // 0x00
+ new_pin_data.pw_len = strlen(init_pin_val);
+ new_pin_data.pw = (unsigned char*)calloc(1, new_pin_data.pw_len);
+ memcpy(new_pin_data.pw, init_pin_val, new_pin_data.pw_len);
+
+ ret = tel_verify_sim_puks(handle, &puk_data, &new_pin_data, sim_async_response_verify_puk, user_data);
+ if (ret != TAPI_API_SUCCESS)
+ {
+ ERR("TAPI API FAIL: Error Code [0x%x]", ret);
+ GCF_tapi_deinit();
+ }
+
+ free(puk_data.pw);
+ free(new_pin_data.pw);
+}
+
+static void sim_async_response_read_contact(TapiHandle *handle, int result, void *data, void *user_data)
+{
+ PH_FN_CALL;
+ TelSimPbAccessResult_t sec_rt = result;
+ TelSimPbRecord_t *sim_acces_info = data;
+
+ if (sec_rt != TAPI_SIM_PB_SUCCESS)
+ {
+ ERR("SIM phone book access error [%d]", sec_rt);
+ GCF_tapi_deinit();
+ return;
+ }
+
+ if (sim_acces_info->phonebook_type == TAPI_SIM_PB_ADN) //KKC - ADN number value!
+ ph_dialer_util_show_matched_one_number(user_data, (char *)sim_acces_info->name, (char *)sim_acces_info->number);
+ else if (sim_acces_info->phonebook_type == TAPI_SIM_PB_3GSIM)
+ {
+ if(strlen(sim_acces_info->number) > 0)
+ ph_dialer_util_show_matched_one_number(user_data, (char *)sim_acces_info->name, (char*)(sim_acces_info->number));
+ if (sim_acces_info->anr1_ton == TAPI_SIM_TON_ABBREVIATED_NUMBER) //KKC - USIM ADN number value!
+ ph_dialer_util_show_matched_one_number(user_data, NULL, (char*)(sim_acces_info->anr1));
+ if (sim_acces_info->anr2_ton == TAPI_SIM_TON_ABBREVIATED_NUMBER) //KKC - USIM ADN number value!
+ ph_dialer_util_show_matched_one_number(user_data, NULL, (char*)(sim_acces_info->anr2));
+ if (sim_acces_info->anr3_ton == TAPI_SIM_TON_ABBREVIATED_NUMBER) //KKC - USIM ADN number value!
+ ph_dialer_util_show_matched_one_number(user_data, NULL, (char*)(sim_acces_info->anr3));
+ }
+ GCF_tapi_deinit();
+}
+
+void GCF_test_read_contact(int index, void *user_data)
+{
+ TelSimPbType_t pb_type = 0;
+ TelSimCardType_t card_type = 0;
+ int ret;
+
+ tel_get_sim_type(handle, &card_type);
+ if (card_type == TAPI_SIM_CARD_TYPE_GSM)
+ pb_type = TAPI_SIM_PB_ADN;
+ else if (card_type == TAPI_SIM_CARD_TYPE_USIM)
+ pb_type = TAPI_SIM_PB_3GSIM;
+
+ ret = tel_read_sim_pb_record(handle, pb_type, index, sim_async_response_read_contact, user_data);
+ if (ret != TAPI_API_SUCCESS) {
+ ERR("TAPI API FAIL: Error Code [0x%x]", ret);
+ GCF_tapi_deinit();
+ }
+}
+
+/* Gcf Puk1*/
+#define GCF_PUK1_PRE_VALUE "**05*"
+
+int GCF_check_puk_str(const char* number, char **dest_puk, char **dest_pin1, char **dest_pin2, int size_dest)
+{
+ PH_FN_CALL;
+ regex_t fsm;
+ regmatch_t str[strlen(number)+1];
+ char* origin_string;
+ char * str_temp;
+
+ if(regcomp(&fsm, PUK_REGEX, REG_EXTENDED))
+ {
+ PH_DBG("regular expression fail");
+ regfree(&fsm);
+ return FALSE;
+ }
+ else
+ {
+ if(regexec(&fsm, number, strlen(number)+1, str, 0) == REG_NOMATCH)
+ {
+ PH_DBG("matching fail");
+ regfree(&fsm);
+ }
+ else
+ {
+ PH_DBG("matching success");
+ origin_string = strdup(number);
+ str_temp = origin_string + 5;
+ *dest_puk = strdup(strtok(str_temp, "*"));
+ *dest_pin1 = strdup(strtok(NULL, "*"));
+ *dest_pin2 = strdup(strtok(NULL, "#"));
+ free(origin_string);
+ regfree(&fsm);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+bool GCF_check_admin_sim(const char *number, int *ret_index)
+{
+ int count;
+ char *dest;
+ bool success;
+ p_retvm_if(number==NULL || ret_index==NULL, FALSE, "Parameter is null");
+
+ count = strlen(number);
+ p_retvm_if(count < 2, FALSE, "number length is too short");
+ dest = (char*)calloc(1, count);
+
+ success = true;
+ if (number[count-1]=='#')
+ {
+ int i=0;
+ for (;i<count-1;i++)
+ {
+ if ('0' <= number[i] && number[i] <= '9')
+ dest[i] = number[i];
+ else
+ {
+ success = false;
+ break;
+ }
+ }
+ if (success)
+ *ret_index = atoi(dest);
+ }
+ else
+ success = false;
+ free(dest);
+
+ return success;
+}
+