tizen 2.3.1 release
[framework/telephony/libslp-tapi.git] / test_src / phonebook.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #include <glib.h>
27
28 #include <tapi_common.h>
29 #include <ITapiPhonebook.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "sim.h"
34 #include "phonebook.h"
35
36 #define CHECK_RT(x) \
37 { \
38     if((x) != 0) { \
39                 msg("api call failed with[%d]",x); \
40                 return 0; \
41         }\
42 }
43
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", };
56
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] = {};
75
76
77 static void on_noti_pb_status(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
78 {
79         TelSimPbStatus_t *status = data;
80         msgb("event(%s) receive !!", TAPI_NOTI_PB_STATUS);
81         if (!status)
82                 return;
83
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,
89                 status->pb_list.b_3g,
90                 status->pb_list.b_aas,
91                 status->pb_list.b_gas);
92 }
93
94 static int run_pb_get_sim_pb_init_info(MManager *mm, struct menu_data *menu)
95 {
96         TapiHandle *handle = menu_manager_ref_user_data(mm);
97         int rt = 0;
98         int o_status = 0;
99         TelSimPbList_t list;
100
101         msg("run_pb_get_sim_pb_init_info service!");
102         memset(&list, 0, sizeof(TelSimPbList_t));
103
104         rt = tel_get_sim_pb_init_info(handle, &o_status, &list);
105         CHECK_RT(rt);
106
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);
114         return 0;
115 }
116
117 static void on_pb_get_sim_pb_count(TapiHandle *handle, int result, void *data, void *user_data)
118 {
119         TelSimPbAccessResult_t access_rt = result;
120         TelSimPbStorageInfo_t *ps = data;
121
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]);
127                 } else {
128                         msg("StorageFileType[%d]", ps->StorageFileType);
129                 }
130                 msg("TotalRecordCount[%d]", ps->TotalRecordCount);
131                 msg("UsedRecordCount[%d]", ps->UsedRecordCount);
132         }
133 }
134
135 static int run_pb_get_sim_pb_count(MManager *mm, struct menu_data *menu)
136 {
137         TapiHandle *handle = menu_manager_ref_user_data(mm);
138         TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
139         int rt = 0;
140
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);
144         CHECK_RT(rt);
145         return 0;
146 }
147
148 static void on_pb_get_sim_pb_meta_info(TapiHandle *handle, int result, void *data, void *user_data)
149 {
150         TelSimPbAccessResult_t access_rt = result;
151         TelSimPbEntryInfo_t *pe = data;
152
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]);
158                 } else {
159                         msg("StorageFileType[%d]", pe->StorageFileType);
160                 }
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);
166         }
167
168 }
169
170 static int run_pb_get_sim_pb_meta_info(MManager *mm, struct menu_data *menu)
171 {
172         TapiHandle *handle = menu_manager_ref_user_data(mm);
173         TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
174         int rt = 0;
175
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);
179         CHECK_RT(rt);
180         return 0;
181 }
182
183 static void on_pb_get_sim_pb_usim_meta_info(TapiHandle *handle, int result, void *data, void *user_data)
184 {
185         TelSimPbAccessResult_t access_rt = result;
186         TelSimPbCapabilityInfo_t *capa = data;
187         int i = 0;
188
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]);
195                         } else {
196                                 msg("capa->FileTypeInfo[%d].field_type[%d]", i, capa->FileTypeInfo[i].field_type);
197                         }
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);
201                 }
202         }
203 }
204
205 static int run_pb_get_sim_pb_usim_meta_info(MManager *mm, struct menu_data *menu)
206 {
207         TapiHandle *handle = menu_manager_ref_user_data(mm);
208         int rt = 0;
209
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);
212         CHECK_RT(rt);
213         return 0;
214 }
215
216 static void on_pb_read_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
217 {
218         TelSimPbAccessResult_t access_rt = result;
219         TelSimPbRecord_t *pr = data;
220
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]);
226                 } else {
227                         msg("phonebook_type[%d]", pr->phonebook_type);
228                 }
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]);
234                 } else {
235                         msg("dcs[%d]", pr->dcs);
236                 }
237                 msg("number[%s]", pr->number);
238
239                 if(pr->ton <= TAPI_SIM_TON_RESERVED_FOR_EXT) {
240                         msg("ton[%d][%s]", pr->ton, dbg_pb_ton_name[pr->ton]);
241                 } else {
242                         msg("ton[%d]", pr->ton);
243                 }
244
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]);
249                         } else {
250                                 msg("anr1_ton[%d]", pr->anr1_ton);
251                         }
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]);
255                         } else {
256                                 msg("anr2_ton[%d]", pr->anr2_ton);
257                         }
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]);
261                         } else {
262                                 msg("anr3_ton[%d]", pr->anr3_ton);
263                         }
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);
270                 }
271         }
272 }
273
274 static int run_pb_read_sim_pb_record(MManager *mm, struct menu_data *menu)
275 {
276         TapiHandle *handle = menu_manager_ref_user_data(mm);
277         TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
278         int rt = 0;
279         int local_index = 0;
280
281         pb_type = atoi(data_pb_type);
282         local_index = atoi(data_pb_index);
283
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);
286         CHECK_RT(rt);
287         return 0;
288 }
289
290 static void on_pb_update_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
291 {
292         TelSimPbAccessResult_t access_rt = result;
293
294         msg("on_pb_update_sim_pb_record received");
295         msg("access_rt[%d]", access_rt);
296 }
297
298 static int run_pb_update_sim_pb_record(MManager *mm, struct menu_data *menu)
299 {
300         TapiHandle *handle = menu_manager_ref_user_data(mm);
301         int rt = 0;
302         TelSimPbRecord_t pb;
303
304         memset(&pb, 0, sizeof(TelSimPbRecord_t));
305
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);
312
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';
326         }
327
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]);
330         } else {
331                 msg("phonebook_type[%d]", pb.phonebook_type);
332         }
333
334         rt = tel_update_sim_pb_record(handle, &pb, on_pb_update_sim_pb_record, NULL);
335         CHECK_RT(rt);
336         return 0;
337 }
338
339 static void on_pb_delete_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
340 {
341         TelSimPbAccessResult_t access_rt = result;
342
343         msg("on_pb_delete_sim_pb_record received");
344         msg("access_rt[%d]", access_rt);
345 }
346
347 static int run_pb_delete_sim_pb_record(MManager *mm, struct menu_data *menu)
348 {
349         TapiHandle *handle = menu_manager_ref_user_data(mm);
350         TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
351         int rt = 0;
352         int local_index = 0;
353
354         pb_type = atoi(data_pb_type);
355         local_index = atoi(data_pb_index);
356
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);
359         CHECK_RT(rt);
360         return 0;
361 }
362
363 static struct menu_data menu_pb_get_sim_pb_init_info[] = {
364                 { "1", "run", NULL, run_pb_get_sim_pb_init_info, NULL },
365                 { NULL, NULL, },
366 };
367
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 },
371                 { NULL, NULL, },
372 };*/
373
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 },
377                 { NULL, NULL, },
378 };
379
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 },
383                 { NULL, NULL, },
384 };
385
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 },
388                 { NULL, NULL, },
389 };
390
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 },
395                 { NULL, NULL, },
396 };
397
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 },
418                 { NULL, NULL, },
419 };
420
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 },
425                 { NULL, NULL, },
426 };
427
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 },
436                 { NULL, NULL, },
437 };
438
439 void register_phonebook_event(TapiHandle *handle)
440 {
441         int ret;
442
443         /* PHONEBOOK */
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);
447         }
448 }