summaryrefslogtreecommitdiff
path: root/lib/dialer/ph-dialer-tapi.c
blob: 97833f0e5a2d97ec4c2b22396af196b504aae1c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
 * 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://www.tizenopensource.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 "phone.h"
#include "phone-dialer.h"
#include "ph-dialer-utils.h"

#ifdef Status
	#undef Status
#endif

static TapiHandle *handle = NULL;

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)
{
	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)
{
	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));

	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(sim_acces_info->number && *sim_acces_info->number)
			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_puk1_str(const char *number, char *dest_puk, char *dest_pin1, char *dest_pin2, int size_dest)
{
	int count;
	p_retv_if(number==NULL || dest_puk==NULL || dest_pin1==NULL, FALSE);
	count = strlen(number);
	p_retv_if(count<6, FALSE);

	if (0 == strncmp(number, GCF_PUK1_PRE_VALUE, 5)) {
		int source_count = strlen(number);
		int source_index = 0;
		int dest_index=0;
		int process_kind=0;//0 : puk / 1: pin 2:pin/

		for (source_index=5;source_index < source_count;source_index++) {
			if (process_kind == 0) {
				if (size_dest-1 < dest_index)
					return FALSE;

				if (number[source_index]=='*') {
					process_kind++;
					dest_index=0;
					continue;
				}
				dest_puk[dest_index++] = number[source_index];
			}
			else if (process_kind==1) {
				if (size_dest-1 < dest_index)
					return FALSE;

				if (number[source_index]=='*') {
					process_kind++;
					dest_index=0;
					continue;
				}

				dest_pin1[dest_index++] = number[source_index];
			}
			else if (process_kind==2) {
				if (size_dest-1 < dest_index)
					return FALSE;

				if (number[source_index]=='#') {
					process_kind++;
					dest_index=0;
					continue;
				}
				dest_pin2[dest_index++] = number[source_index];
			}
			else
				break;
		}
		if (process_kind != 3)
			return FALSE;
		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;
}