4 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <tapi_common.h>
29 #include <ITapiPhonebook.h>
30 #include <TapiUtility.h>
34 #include "phonebook.h"
39 msg("api call failed with[%d]",x); \
44 static const char* dbg_pb_type_name[] = { "TAPI_SIM_PB_FDN", "TAPI_SIM_PB_ADN", "TAPI_SIM_PB_SDN",
45 "TAPI_SIM_PB_3GSIM", "TAPI_SIM_PB_AAS", "TAPI_SIM_PB_GAS", };
46 static const char* dbg_pb_adf_field_name[] = { "NO VALUE 0", "TAPI_PB_3G_NAME", "TAPI_PB_3G_NUMBER",
47 "TAPI_PB_3G_ANR1", "TAPI_PB_3G_ANR2", "TAPI_PB_3G_ANR3", "TAPI_PB_3G_EMAIL1",
48 "TAPI_PB_3G_EMAIL2", "TAPI_PB_3G_EMAIL3", "TAPI_PB_3G_EMAIL4", "TAPI_PB_3G_SNE",
49 "TAPI_PB_3G_GRP", "TAPI_PB_3G_PBC" };
50 static const char* dbg_pb_ton_name[] = { "TAPI_SIM_TON_UNKNOWN", "TAPI_SIM_TON_INTERNATIONAL",
51 "TAPI_SIM_TON_NATIONAL", "TAPI_SIM_TON_NETWORK_SPECIFIC", "TAPI_SIM_TON_DEDICATED_ACCESS",
52 "TAPI_SIM_TON_ALPHA_NUMERIC", "TAPI_SIM_TON_ABBREVIATED_NUMBER",
53 "TAPI_SIM_TON_RESERVED_FOR_EXT", };
54 static const char* dbg_pb_dcs_name[] = { "TAPI_SIM_TEXT_ENC_ASCII", "TAPI_SIM_TEXT_ENC_GSM7BIT",
55 "TAPI_SIM_TEXT_ENC_UCS2", "TAPI_SIM_TEXT_ENC_HEX", };
57 static char data_pb_type[MENU_DATA_SIZE + 1] = {};
58 static char data_pb_index[MENU_DATA_SIZE + 1] = {};
59 static char data_pb_name[MENU_DATA_SIZE + 1] = {};
60 static char data_pb_dcs[MENU_DATA_SIZE + 1] = {};
61 static char data_pb_number[MENU_DATA_SIZE + 1] = {};
62 static char data_pb_ton[MENU_DATA_SIZE + 1] = {};
63 static char data_pb_anr1[MENU_DATA_SIZE + 1] = {};
64 static char data_pb_anr1_ton[MENU_DATA_SIZE + 1] = {};
65 static char data_pb_anr2[MENU_DATA_SIZE + 1] = {};
66 static char data_pb_anr2_ton[MENU_DATA_SIZE + 1] = {};
67 static char data_pb_anr3[MENU_DATA_SIZE + 1] = {};
68 static char data_pb_anr3_ton[MENU_DATA_SIZE + 1] = {};
69 static char data_pb_email1[MENU_DATA_SIZE + 1] = {};
70 static char data_pb_email2[MENU_DATA_SIZE + 1] = {};
71 static char data_pb_email3[MENU_DATA_SIZE + 1] = {};
72 static char data_pb_email4[MENU_DATA_SIZE + 1] = {};
73 static char data_pb_group_index[MENU_DATA_SIZE + 1] = {};
74 static char data_pb_pb_control[MENU_DATA_SIZE + 1] = {};
77 static void on_noti_pb_status(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
79 TelSimPbStatus_t *status = data;
80 msgb("event(%s) receive !!", TAPI_NOTI_PB_STATUS);
84 msg("init[%d] fdn[%d] adn[%d] sdn[%d] usim[%d] aas[%d] gas[%d]",
85 status->init_completed,
86 status->pb_list.b_fdn,
87 status->pb_list.b_adn,
88 status->pb_list.b_sdn,
90 status->pb_list.b_aas,
91 status->pb_list.b_gas);
94 static int run_pb_get_sim_pb_init_info(MManager *mm, struct menu_data *menu)
96 TapiHandle *handle = menu_manager_ref_user_data(mm);
101 msg("run_pb_get_sim_pb_init_info service!");
102 memset(&list, 0, sizeof(TelSimPbList_t));
104 rt = tel_get_sim_pb_init_info(handle, &o_status, &list);
107 msg("status[%d]", o_status);
108 msg("fdn[%d]", list.b_fdn);
109 msg("adn[%d]", list.b_adn);
110 msg("sdn[%d]", list.b_sdn);
111 msg("3g usim[%d]", list.b_3g);
112 msg("aas[%d]", list.b_aas);
113 msg("gas[%d]", list.b_gas);
117 static void on_pb_get_sim_pb_count(TapiHandle *handle, int result, void *data, void *user_data)
119 TelSimPbAccessResult_t access_rt = result;
120 TelSimPbStorageInfo_t *ps = data;
122 msg("on_pb_get_sim_pb_count received");
123 msg("access_rt[%d]", access_rt);
124 if (access_rt == TAPI_SIM_PB_SUCCESS) {
125 if (ps->StorageFileType <= TAPI_SIM_PB_GAS) {
126 msg("StorageFileType[%d][%s]", ps->StorageFileType, dbg_pb_type_name[ps->StorageFileType]);
128 msg("StorageFileType[%d]", ps->StorageFileType);
130 msg("TotalRecordCount[%d]", ps->TotalRecordCount);
131 msg("UsedRecordCount[%d]", ps->UsedRecordCount);
135 static int run_pb_get_sim_pb_count(MManager *mm, struct menu_data *menu)
137 TapiHandle *handle = menu_manager_ref_user_data(mm);
138 TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
141 pb_type = data_pb_type[0] - '0';
142 msg("request pb [%d]", pb_type);
143 rt = tel_get_sim_pb_count(handle, pb_type, on_pb_get_sim_pb_count, NULL);
148 static void on_pb_get_sim_pb_meta_info(TapiHandle *handle, int result, void *data, void *user_data)
150 TelSimPbAccessResult_t access_rt = result;
151 TelSimPbEntryInfo_t *pe = data;
153 msg("on_pb_get_sim_pb_meta_info received");
154 msg("access_rt[%d]", access_rt);
155 if (access_rt == TAPI_SIM_PB_SUCCESS) {
156 if (pe->StorageFileType <= TAPI_SIM_PB_GAS) {
157 msg("StorageFileType[%d][%s]", pe->StorageFileType, dbg_pb_type_name[pe->StorageFileType]);
159 msg("StorageFileType[%d]", pe->StorageFileType);
161 msg("PbIndexMin[%d]",pe->PbIndexMin);
162 msg("PbIndexMax[%d]",pe->PbIndexMax);
163 msg("PbNumLenMax[%d]",pe->PbNumLenMax);
164 msg("PbTextLenMax[%d]",pe->PbTextLenMax);
165 msg("PbUsedCount[%d]",pe->PbUsedCount);
170 static int run_pb_get_sim_pb_meta_info(MManager *mm, struct menu_data *menu)
172 TapiHandle *handle = menu_manager_ref_user_data(mm);
173 TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
176 pb_type = data_pb_type[0] - '0';
177 msg("request pb [%d]", pb_type);
178 rt = tel_get_sim_pb_meta_info(handle, pb_type, on_pb_get_sim_pb_meta_info, NULL);
183 static void on_pb_get_sim_pb_usim_meta_info(TapiHandle *handle, int result, void *data, void *user_data)
185 TelSimPbAccessResult_t access_rt = result;
186 TelSimPbCapabilityInfo_t *capa = data;
189 msg("on_pb_get_sim_pb_3g_meta_info received");
190 msg("access_rt[%d]", access_rt);
191 if (access_rt == TAPI_SIM_PB_SUCCESS) {
192 for (i = 0; i < capa->FileTypeCount; i++) {
193 if(capa->FileTypeInfo[i].field_type <=TAPI_PB_3G_PBC ) {
194 msg("capa->FileTypeInfo[%d].field_type[%d][%s]", i, capa->FileTypeInfo[i].field_type, dbg_pb_adf_field_name[capa->FileTypeInfo[i].field_type]);
196 msg("capa->FileTypeInfo[%d].field_type[%d]", i, capa->FileTypeInfo[i].field_type);
198 msg("capa->FileTypeInfo[%d].index_max[%d]", i, capa->FileTypeInfo[i].index_max);
199 msg("capa->FileTypeInfo[%d].text_max[%d]", i, capa->FileTypeInfo[i].text_max);
200 msg("capa->FileTypeInfo[%d].used_count[%d]", i, capa->FileTypeInfo[i].used_count);
205 static int run_pb_get_sim_pb_usim_meta_info(MManager *mm, struct menu_data *menu)
207 TapiHandle *handle = menu_manager_ref_user_data(mm);
210 msg("call 3g meta info");
211 rt = tel_get_sim_pb_usim_meta_info(handle, on_pb_get_sim_pb_usim_meta_info, NULL);
216 static void on_pb_read_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
218 TelSimPbAccessResult_t access_rt = result;
219 TelSimPbRecord_t *pr = data;
221 msg("on_pb_read_sim_pb_record received");
222 msg("access_rt[%d]", access_rt);
223 if(access_rt == TAPI_SIM_PB_SUCCESS) {
224 if( pr->phonebook_type <= TAPI_SIM_PB_GAS){
225 msg("phonebook_type[%d][%s]", pr->phonebook_type, dbg_pb_type_name[pr->phonebook_type]);
227 msg("phonebook_type[%d]", pr->phonebook_type);
229 msg("index[%d]", pr->index);
230 msg("next_index[%d]", pr->next_index);
231 msg("name[%s]", pr->name);
232 if(pr->dcs <= TAPI_SIM_TEXT_ENC_HEX) {
233 msg("dcs[%d][%s]", pr->dcs, dbg_pb_dcs_name[pr->dcs]);
235 msg("dcs[%d]", pr->dcs);
237 msg("number[%s]", pr->number);
239 if(pr->ton <= TAPI_SIM_TON_RESERVED_FOR_EXT) {
240 msg("ton[%d][%s]", pr->ton, dbg_pb_ton_name[pr->ton]);
242 msg("ton[%d]", pr->ton);
245 if (pr->phonebook_type == TAPI_SIM_PB_3GSIM) {
246 msg("anr1[%s]", pr->anr1);
247 if(pr->anr1_ton <= TAPI_SIM_TON_RESERVED_FOR_EXT) {
248 msg("anr1_ton[%d][%s]", pr->anr1_ton, dbg_pb_ton_name[pr->anr1_ton]);
250 msg("anr1_ton[%d]", pr->anr1_ton);
252 msg("anr2[%s]", pr->anr2);
253 if(pr->anr2_ton <= TAPI_SIM_TON_RESERVED_FOR_EXT) {
254 msg("anr2_ton[%d][%s]", pr->anr2_ton, dbg_pb_ton_name[pr->anr2_ton]);
256 msg("anr2_ton[%d]", pr->anr2_ton);
258 msg("anr3[%s]", pr->anr3);
259 if(pr->anr3_ton <= TAPI_SIM_TON_RESERVED_FOR_EXT) {
260 msg("anr3_ton[%d][%s]", pr->anr3_ton, dbg_pb_ton_name[pr->anr3_ton]);
262 msg("anr3_ton[%d]", pr->anr3_ton);
264 msg("email1[%s]", pr->email1);
265 msg("email2[%s]", pr->email2);
266 msg("email3[%s]", pr->email3);
267 msg("email4[%s]", pr->email4);
268 msg("group_index[%d]", pr->group_index);
269 msg("pb_control[%d]", pr->pb_control);
274 static int run_pb_read_sim_pb_record(MManager *mm, struct menu_data *menu)
276 TapiHandle *handle = menu_manager_ref_user_data(mm);
277 TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
281 pb_type = atoi(data_pb_type);
282 local_index = atoi(data_pb_index);
284 msg("request pb [%d], local_index[%d]", pb_type, local_index);
285 rt = tel_read_sim_pb_record(handle, pb_type, local_index, on_pb_read_sim_pb_record, NULL);
290 static void on_pb_update_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
292 TelSimPbAccessResult_t access_rt = result;
294 msg("on_pb_update_sim_pb_record received");
295 msg("access_rt[%d]", access_rt);
298 static int run_pb_update_sim_pb_record(MManager *mm, struct menu_data *menu)
300 TapiHandle *handle = menu_manager_ref_user_data(mm);
304 memset(&pb, 0, sizeof(TelSimPbRecord_t));
306 pb.phonebook_type = atoi(data_pb_type);
307 pb.index = atoi(data_pb_index);
308 snprintf((char*)pb.name, strlen(data_pb_name)+1, "%s", data_pb_name);
309 pb.dcs = atoi(data_pb_dcs);
310 snprintf((char*)pb.number, strlen(data_pb_number)+1, "%s", data_pb_number);
311 pb.ton = atoi(data_pb_ton);
313 if (pb.phonebook_type == TAPI_SIM_PB_3GSIM) {
314 snprintf((char*)pb.anr1, strlen(data_pb_anr1) + 1, "%s", data_pb_anr1);
315 pb.anr1_ton = data_pb_anr1_ton[0] - '0';
316 snprintf((char*)pb.anr2, strlen(data_pb_anr2) + 1, "%s", data_pb_anr2);
317 pb.anr2_ton = data_pb_anr2_ton[0] - '0';
318 snprintf((char*)pb.anr3, strlen(data_pb_anr3) + 1, "%s", data_pb_anr3);
319 pb.anr3_ton = data_pb_anr3_ton[0] - '0';
320 snprintf((char*)pb.email1, strlen(data_pb_email1) + 1, "%s", data_pb_email1);
321 snprintf((char*)pb.email2, strlen(data_pb_email2) + 1, "%s", data_pb_email2);
322 snprintf((char*)pb.email3, strlen(data_pb_email3) + 1, "%s", data_pb_email3);
323 snprintf((char*)pb.email4, strlen(data_pb_email4) + 1, "%s", data_pb_email4);
324 pb.group_index = data_pb_group_index[0] - '0';
325 pb.pb_control = data_pb_pb_control[0] - '0';
328 if( pb.phonebook_type <= TAPI_SIM_PB_GAS){
329 msg("phonebook_type[%d][%s]", pb.phonebook_type, dbg_pb_type_name[pb.phonebook_type]);
331 msg("phonebook_type[%d]", pb.phonebook_type);
334 rt = tel_update_sim_pb_record(handle, &pb, on_pb_update_sim_pb_record, NULL);
339 static void on_pb_delete_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
341 TelSimPbAccessResult_t access_rt = result;
343 msg("on_pb_delete_sim_pb_record received");
344 msg("access_rt[%d]", access_rt);
347 static int run_pb_delete_sim_pb_record(MManager *mm, struct menu_data *menu)
349 TapiHandle *handle = menu_manager_ref_user_data(mm);
350 TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
354 pb_type = atoi(data_pb_type);
355 local_index = atoi(data_pb_index);
357 msg("request pb [%d], local_index[%d]", pb_type, local_index);
358 rt = tel_delete_sim_pb_record(handle, pb_type, local_index, on_pb_delete_sim_pb_record, NULL);
363 static struct menu_data menu_pb_get_sim_pb_init_info[] = {
364 { "1", "run", NULL, run_pb_get_sim_pb_init_info, NULL },
368 /*static struct menu_data menu_pb_select_sim_pb[] = {
369 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type},
370 { "2", "run", NULL, run_pb_select_sim_pb, NULL },
374 static struct menu_data menu_pb_get_sim_pb_count[] = {
375 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
376 { "2", "run", NULL, run_pb_get_sim_pb_count, NULL },
380 static struct menu_data menu_pb_get_sim_pb_meta_info[] = {
381 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
382 { "2", "run", NULL, run_pb_get_sim_pb_meta_info, NULL },
386 static struct menu_data menu_pb_get_sim_pb_usim_meta_info[] = {
387 { "1", "run", NULL, run_pb_get_sim_pb_usim_meta_info, NULL },
391 static struct menu_data menu_pb_read_sim_pb_record[] = {
392 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
393 { "2", "index", NULL, NULL, data_pb_index },
394 { "3", "run", NULL, run_pb_read_sim_pb_record, NULL },
398 static struct menu_data menu_pb_update_sim_pb_record[] = {
399 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
400 { "2", "index", NULL, NULL, data_pb_index },
401 { "3", "name", NULL, NULL, data_pb_name },
402 { "4", "dcs", NULL, NULL, data_pb_dcs },
403 { "5", "number", NULL, NULL, data_pb_number },
404 { "6", "ton", NULL, NULL, data_pb_ton },
405 { "7", "anr1", NULL, NULL, data_pb_anr1 },
406 { "8", "anr1_ton", NULL, NULL, data_pb_anr1_ton },
407 { "9", "anr2", NULL, NULL, data_pb_anr2 },
408 { "10", "anr2_ton", NULL, NULL, data_pb_anr2_ton },
409 { "11", "anr3", NULL, NULL, data_pb_anr3 },
410 { "12", "anr3_ton", NULL, NULL, data_pb_anr3_ton },
411 { "13", "email1", NULL, NULL, data_pb_email1 },
412 { "14", "email2", NULL, NULL, data_pb_email2 },
413 { "15", "email3", NULL, NULL, data_pb_email3 },
414 { "16", "email4", NULL, NULL, data_pb_email4 },
415 { "17", "group_index", NULL, NULL, data_pb_group_index },
416 { "18", "pb_control", NULL, NULL, data_pb_pb_control },
417 { "19", "run", NULL, run_pb_update_sim_pb_record, NULL },
421 static struct menu_data menu_pb_delete_sim_pb_record[] = {
422 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
423 { "2", "index", NULL, NULL, data_pb_index },
424 { "3", "run", NULL, run_pb_delete_sim_pb_record, NULL },
428 struct menu_data menu_phonebook[] = {
429 { "1", "phonebook init info", menu_pb_get_sim_pb_init_info, NULL, NULL },
430 { "2", "get pb count", menu_pb_get_sim_pb_count, NULL, NULL },
431 { "3", "get pb meta info", menu_pb_get_sim_pb_meta_info, NULL, NULL },
432 { "4", "get usim pb meta info", menu_pb_get_sim_pb_usim_meta_info, NULL, NULL },
433 { "5", "read record", menu_pb_read_sim_pb_record, NULL, NULL },
434 { "6", "add/update record", menu_pb_update_sim_pb_record, NULL, NULL },
435 { "7", "delete record", menu_pb_delete_sim_pb_record, NULL, NULL },
439 void register_phonebook_event(TapiHandle *handle)
444 ret = tel_register_noti_event(handle, TAPI_NOTI_PB_STATUS, on_noti_pb_status, NULL);
445 if (ret != TAPI_API_SUCCESS) {
446 msg("event register failed(%d)", ret);