Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / wearable / test_src / phonebook.c
1 /*
2  * Telephony test application
3  *
4  * Copyright (c) 2012 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 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 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 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 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 index = 0;
280
281         pb_type = data_pb_type[0] - '0';
282         index = data_pb_index[0] -'0';
283         msg("request pb [%d], index[%d]", pb_type, index);
284         rt = tel_read_sim_pb_record(handle, pb_type, index, on_pb_read_sim_pb_record, NULL);
285         CHECK_RT(rt);
286         return 0;
287 }
288
289 static void on_pb_update_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
290 {
291         TelSimPbAccessResult_t access_rt = result;
292
293         msg("on_pb_update_sim_pb_record received");
294         msg("access_rt[%d]", access_rt);
295 }
296
297 static int run_pb_update_sim_pb_record(MManager *mm, struct menu_data *menu)
298 {
299         TapiHandle *handle = menu_manager_ref_user_data(mm);
300         int rt = 0;
301         TelSimPbRecord_t pb;
302
303         memset(&pb, 0, sizeof(TelSimPbRecord_t));
304
305         pb.phonebook_type = data_pb_type[0] - '0';
306         pb.index = data_pb_index[0] - '0';
307         snprintf((char*)pb.name, strlen(data_pb_name)+1, "%s", data_pb_name);
308         pb.dcs = data_pb_dcs[0] - '0';
309         snprintf((char*)pb.number, strlen(data_pb_number)+1, "%s", data_pb_number);
310         pb.ton = data_pb_ton[0] - '0';
311
312         if (pb.phonebook_type == TAPI_SIM_PB_3GSIM) {
313                 snprintf((char*)pb.anr1, strlen(data_pb_anr1) + 1, "%s", data_pb_anr1);
314                 pb.anr1_ton = data_pb_anr1_ton[0] - '0';
315                 snprintf((char*)pb.anr2, strlen(data_pb_anr2) + 1, "%s", data_pb_anr2);
316                 pb.anr2_ton = data_pb_anr2_ton[0] - '0';
317                 snprintf((char*)pb.anr3, strlen(data_pb_anr3) + 1, "%s", data_pb_anr3);
318                 pb.anr3_ton = data_pb_anr3_ton[0] - '0';
319                 snprintf((char*)pb.email1, strlen(data_pb_email1) + 1, "%s", data_pb_email1);
320                 snprintf((char*)pb.email2, strlen(data_pb_email2) + 1, "%s", data_pb_email2);
321                 snprintf((char*)pb.email3, strlen(data_pb_email3) + 1, "%s", data_pb_email3);
322                 snprintf((char*)pb.email4, strlen(data_pb_email4) + 1, "%s", data_pb_email4);
323                 pb.group_index = data_pb_group_index[0] - '0';
324                 pb.pb_control = data_pb_pb_control[0] - '0';
325         }
326
327         if( pb.phonebook_type <= TAPI_SIM_PB_GAS){
328                 msg("phonebook_type[%d][%s]", pb.phonebook_type, dbg_pb_type_name[pb.phonebook_type]);
329         } else {
330                 msg("phonebook_type[%d]", pb.phonebook_type);
331         }
332
333         rt = tel_update_sim_pb_record(handle, &pb, on_pb_update_sim_pb_record, NULL);
334         CHECK_RT(rt);
335         return 0;
336 }
337
338 static void on_pb_delete_sim_pb_record(TapiHandle *handle, int result, void *data, void *user_data)
339 {
340         TelSimPbAccessResult_t access_rt = result;
341
342         msg("on_pb_delete_sim_pb_record received");
343         msg("access_rt[%d]", access_rt);
344 }
345
346 static int run_pb_delete_sim_pb_record(MManager *mm, struct menu_data *menu)
347 {
348         TapiHandle *handle = menu_manager_ref_user_data(mm);
349         TelSimPbType_t pb_type = TAPI_SIM_PB_UNKNOWNN;
350         int rt = 0;
351         int index = 0;
352
353         pb_type = data_pb_type[0] - '0';
354         index = data_pb_index[0] -'0';
355         msg("request pb [%d], index[%d]", pb_type, index);
356         rt = tel_delete_sim_pb_record(handle, pb_type, index, on_pb_delete_sim_pb_record, NULL);
357         CHECK_RT(rt);
358         return 0;
359 }
360
361 static struct menu_data menu_pb_get_sim_pb_init_info[] = {
362                 { "1", "run", NULL, run_pb_get_sim_pb_init_info, NULL },
363                 { NULL, NULL, },
364 };
365
366 /*static struct menu_data menu_pb_select_sim_pb[] = {
367                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type},
368                 { "2", "run", NULL, run_pb_select_sim_pb, NULL },
369                 { NULL, NULL, },
370 };*/
371
372 static struct menu_data menu_pb_get_sim_pb_count[] = {
373                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
374                 { "2", "run", NULL, run_pb_get_sim_pb_count, NULL },
375                 { NULL, NULL, },
376 };
377
378 static struct menu_data menu_pb_get_sim_pb_meta_info[] = {
379                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
380                 { "2", "run", NULL, run_pb_get_sim_pb_meta_info,        NULL },
381                 { NULL, NULL, },
382 };
383
384 static struct menu_data menu_pb_get_sim_pb_usim_meta_info[] = {
385                 { "1", "run", NULL, run_pb_get_sim_pb_usim_meta_info, NULL },
386                 { NULL, NULL, },
387 };
388
389 static struct menu_data menu_pb_read_sim_pb_record[] = {
390                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
391                 { "2", "index", NULL, NULL, data_pb_index },
392                 { "3", "run", NULL, run_pb_read_sim_pb_record,  NULL },
393                 { NULL, NULL, },
394 };
395
396 static struct menu_data menu_pb_update_sim_pb_record[] = {
397                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
398                 { "2", "index", NULL, NULL, data_pb_index },
399                 { "3", "name", NULL, NULL, data_pb_name },
400                 { "4", "dcs", NULL, NULL, data_pb_dcs },
401                 { "5", "number", NULL, NULL, data_pb_number },
402                 { "6", "ton", NULL, NULL, data_pb_ton },
403                 { "7", "anr1", NULL, NULL, data_pb_anr1 },
404                 { "8", "anr1_ton", NULL, NULL, data_pb_anr1_ton },
405                 { "9", "anr2", NULL, NULL, data_pb_anr2 },
406                 { "10", "anr2_ton", NULL, NULL, data_pb_anr2_ton },
407                 { "11", "anr3", NULL, NULL, data_pb_anr3 },
408                 { "12", "anr3_ton", NULL, NULL, data_pb_anr3_ton },
409                 { "13", "email1", NULL, NULL, data_pb_email1 },
410                 { "14", "email2", NULL, NULL, data_pb_email2 },
411                 { "15", "email3", NULL, NULL, data_pb_email3 },
412                 { "16", "email4", NULL, NULL, data_pb_email4 },
413                 { "17", "group_index", NULL, NULL, data_pb_group_index },
414                 { "18", "pb_control", NULL, NULL, data_pb_pb_control },
415                 { "19", "run", NULL, run_pb_update_sim_pb_record, NULL },
416                 { NULL, NULL, },
417 };
418
419 static struct menu_data menu_pb_delete_sim_pb_record[] = {
420                 { "1", "type- 0:fdn, 1:adn, 2:sdn, 3:usim, 4:aas, 5:gas", NULL, NULL, data_pb_type },
421                 { "2", "index", NULL, NULL, data_pb_index },
422                 { "3", "run", NULL, run_pb_delete_sim_pb_record, NULL },
423                 { NULL, NULL, },
424 };
425
426 struct menu_data menu_phonebook[] = {
427                 { "1", "phonebook init info", menu_pb_get_sim_pb_init_info, NULL,       NULL },
428                 { "2", "get pb count",  menu_pb_get_sim_pb_count, NULL, NULL },
429                 { "3", "get pb meta info", menu_pb_get_sim_pb_meta_info, NULL, NULL },
430                 { "4", "get usim pb meta info", menu_pb_get_sim_pb_usim_meta_info, NULL, NULL },
431                 { "5", "read record", menu_pb_read_sim_pb_record, NULL, NULL },
432                 { "6", "add/update record", menu_pb_update_sim_pb_record, NULL, NULL },
433                 { "7", "delete record", menu_pb_delete_sim_pb_record, NULL, NULL },
434                 { NULL, NULL, },
435 };
436
437 void register_phonebook_event(TapiHandle *handle)
438 {
439         int ret;
440
441         /* PHONEBOOK */
442         ret = tel_register_noti_event(handle, TAPI_NOTI_PB_STATUS, on_noti_pb_status, NULL);
443         if (ret != TAPI_API_SUCCESS) {
444                 msg("event register failed(%d)", ret);
445         }
446 }