4 * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
28 #include <core_object.h>
34 #include <co_phonebook.h>
37 #include "imc_phonebook.h"
38 #include "imc_common.h"
41 GSList *used_index_fdn;
42 gboolean used_index_fdn_valid;
44 GSList *used_index_adn;
45 gboolean used_index_adn_valid;
47 GSList *used_index_sdn;
48 gboolean used_index_sdn_valid;
50 GSList *used_index_usim;
51 gboolean used_index_usim_valid;
54 static gboolean __imc_phonebook_get_sim_type(CoreObject *co_pb,
55 TelSimCardType *sim_type)
59 tcore_check_return_value_assert(co_pb != NULL, FALSE);
60 tcore_check_return_value_assert(sim_type != NULL, FALSE);
62 plugin = tcore_object_ref_plugin(co_pb);
63 co_sim = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SIM);
64 return tcore_sim_get_type(co_sim, sim_type);
67 static gboolean __imc_phonebook_get_pb_type_str(TelPbType pb_type,
70 tcore_check_return_value_assert(req_type_str != NULL, FALSE);
74 *req_type_str = g_strdup("FD");
78 *req_type_str = g_strdup("SM");
81 *req_type_str = g_strdup("SN");
88 static gboolean __imc_phonebook_check_and_select_type(CoreObject *co,
89 TelPbType req_type, gchar **set_pb_cmd)
91 TelPbList *support_list;
92 TelPbType current_type;
94 /* Check whether pb_type is supported or not */
95 tcore_phonebook_get_support_list(co, &support_list);
96 if ((req_type == TEL_PB_FDN && support_list->fdn == FALSE)
97 || (req_type == TEL_PB_ADN && support_list->adn == FALSE)
98 || (req_type == TEL_PB_SDN && support_list->sdn == FALSE)
99 || (req_type == TEL_PB_USIM && support_list->usim == FALSE)) {
100 err("Not supported pb_type");
101 g_free(support_list);
104 g_free(support_list);
106 /* Check Current type & Request type */
107 tcore_phonebook_get_selected_type(co, ¤t_type);
108 if (current_type != req_type) {
109 gchar *req_type_str = NULL;
110 __imc_phonebook_get_pb_type_str(req_type, &req_type_str);
111 dbg("Add AT-Command to change [%s] Type", req_type_str);
112 /* Select Phonebook type */
113 *set_pb_cmd = g_strdup_printf("AT+CPBS=\"%s\";", req_type_str);
115 *set_pb_cmd = g_strdup_printf("AT");
121 static gboolean __imc_phonebook_get_index_list_by_type(CoreObject *co,
122 TelPbType pb_type, GSList **list)
124 PrivateInfo *private_info = tcore_object_ref_user_data(co);
125 tcore_check_return_value_assert(private_info != NULL, FALSE);
129 if (private_info->used_index_fdn_valid != TRUE)
131 *list = private_info->used_index_fdn;
134 if (private_info->used_index_adn_valid != TRUE)
136 *list = private_info->used_index_adn;
139 if (private_info->used_index_sdn_valid != TRUE)
141 *list = private_info->used_index_sdn;
144 if (private_info->used_index_usim_valid != TRUE)
146 *list = private_info->used_index_usim;
153 static void __imc_phonebook_check_used_index(CoreObject *co,
154 TelPbType pb_type, guint req_index, guint *used_index)
158 /* Get used_index list by req_type */
159 if (__imc_phonebook_get_index_list_by_type(co, pb_type, &list) != TRUE) {
160 err("used_index list is NOT valid");
161 *used_index = req_index;
165 /* Use first used_index in case req_index is not used */
166 *used_index = (guint)g_slist_nth_data(list, 0);
168 if ((guint)list->data == req_index) {
169 /* req_index is equal to one of used_index */
170 *used_index = req_index;
173 list = g_slist_next(list);
177 static gint __imc_phonebook_compare_index(gconstpointer a, gconstpointer b)
179 guint index1 = (guint)a;
180 guint index2 = (guint)b;
182 return index1 - index2;
185 static void on_response_imc_phonebook_get_used_index(TcorePending *p,
186 guint data_len, const void *data, void *user_data)
188 const TcoreAtResponse *at_resp = data;
189 ImcRespCbData *resp_cb_data = user_data;
190 CoreObject *co = tcore_pending_ref_core_object(p);
191 tcore_check_return_assert(at_resp != NULL);
192 tcore_check_return_assert(resp_cb_data != NULL);
196 if (at_resp->success != TRUE) {
203 if (at_resp->lines == NULL) {
204 err("at_resp->lines is NULL");
206 GSList *lines = at_resp->lines;
208 GSList **list = NULL;
209 PrivateInfo *private_info = tcore_object_ref_user_data(co);
210 tcore_check_return_assert(private_info != NULL);
212 /* Select used_index_list by req_type */
213 req_type = (TelPbType *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
216 list = &private_info->used_index_fdn;
217 private_info->used_index_fdn_valid = TRUE;
220 list = &private_info->used_index_adn;
221 private_info->used_index_adn_valid = TRUE;
224 list = &private_info->used_index_sdn;
225 private_info->used_index_sdn_valid = TRUE;
228 list = &private_info->used_index_usim;
229 private_info->used_index_usim_valid = TRUE;
234 const gchar *line = lines->data;
235 GSList *tokens = NULL;
238 dbg("Line: [%s]", line);
240 tokens = tcore_at_tok_new(line);
241 if (tokens == NULL) {
242 err("tokens is NULL");
246 /* Get only used_index */
247 temp = g_slist_nth_data(tokens, 0);
249 /* Insert used_index in PrivateInfo sorted in ascending */
250 *list = g_slist_insert_sorted(*list, (gpointer)atoi(temp),
251 __imc_phonebook_compare_index);
253 tcore_at_tok_free(tokens);
256 lines = g_slist_next(lines);
258 dbg("pb_type: [%d], used_index Length: [%d]",
259 *req_type, g_slist_length(*list));
263 static void __imc_phonebook_get_used_index(CoreObject *co, TelPbType pb_type, guint max_index)
266 ImcRespCbData *resp_cb_data;
267 TelReturn ret = TEL_RETURN_FAILURE;
272 at_cmd = g_strdup_printf("AT+CPBR=1,%d", max_index);
274 /* Response callback data */
275 resp_cb_data = imc_create_resp_cb_data(NULL, NULL,
276 (void *)&pb_type, sizeof(TelPbType));
278 /* Send Request to Modem */
279 ret = tcore_at_prepare_and_send_request(co,
281 TCORE_AT_COMMAND_TYPE_MULTILINE,
282 TCORE_PENDING_PRIORITY_DEFAULT,
284 on_response_imc_phonebook_get_used_index, resp_cb_data,
285 on_send_imc_request, NULL,
287 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get Used Index");
293 static void on_response_imc_phonebook_get_support_list(TcorePending *p,
294 guint data_len, const void *data, void *user_data)
296 const TcoreAtResponse *at_resp = data;
297 CoreObject *co = tcore_pending_ref_core_object(p);
298 TelPbInitInfo init_info = {0, };
299 tcore_check_return_assert(at_resp != NULL);
303 if (at_resp->success != TRUE) {
310 if (at_resp->lines == NULL) {
311 err("at_resp->lines is NULL");
314 const gchar *line = (const gchar *)at_resp->lines->data;
315 GSList *tokens = NULL;
319 dbg("Line: [%s]", line);
321 tokens = tcore_at_tok_new(line);
322 if (tokens == NULL) {
323 err("tokens is NULL");
327 pb_type_list = g_slist_nth_data(tokens, 0);
328 pb_type = strtok(pb_type_list, "(,)");
330 pb_type = tcore_at_tok_extract(pb_type);
331 if (g_strcmp0(pb_type, "FD") == 0) {
332 init_info.pb_list.fdn = TRUE;
333 } else if (g_strcmp0(pb_type, "SN") == 0) {
334 init_info.pb_list.sdn = TRUE;
335 } else if (g_strcmp0(pb_type, "SM") == 0) {
336 TelSimCardType sim_type;
337 __imc_phonebook_get_sim_type(co, &sim_type);
338 if (sim_type == TEL_SIM_CARD_TYPE_USIM)
339 init_info.pb_list.usim = TRUE;
341 init_info.pb_list.adn = TRUE;
344 /* Get Next pb_type */
345 pb_type = strtok(NULL, "(,)");
347 tcore_at_tok_free(tokens);
350 dbg("FDN: [%s], ADN: [%s], SDN: [%s], USIM: [%s]",
351 init_info.pb_list.fdn ? "TRUE" : "FALSE",
352 init_info.pb_list.adn ? "TRUE" : "FALSE",
353 init_info.pb_list.sdn ? "TRUE" : "FALSE",
354 init_info.pb_list.usim ? "TRUE" : "FALSE");
356 init_info.init_status = TRUE;
357 tcore_phonebook_set_support_list(co, &init_info.pb_list);
358 tcore_phonebook_set_status(co, init_info.init_status);
360 /* Send Notification */
361 tcore_object_send_notification(co,
362 TCORE_NOTIFICATION_PHONEBOOK_STATUS,
363 sizeof(TelPbInitInfo), &init_info);
367 * Operation - get_support_list
370 * AT-Command: AT+CPBS=?
373 * Success: (Single line)
374 * (list of supported <storage>s)
377 * +CME ERROR: <error>
379 static void __imc_phonebook_get_support_list(CoreObject *co)
385 /* Send Request to Modem */
386 ret = tcore_at_prepare_and_send_request(co,
387 "AT+CPBS=?", "+CPBS",
388 TCORE_AT_COMMAND_TYPE_SINGLELINE,
389 TCORE_PENDING_PRIORITY_DEFAULT,
391 on_response_imc_phonebook_get_support_list, NULL,
392 on_send_imc_request, NULL,
394 IMC_CHECK_REQUEST_RET(ret, NULL, "Get Support List");
397 static gboolean on_notification_imc_phonebook_status(CoreObject *co,
398 const void *event_info, void *user_data)
400 dbg("Phonebook Init Completed");
402 /* Get Supported list */
403 __imc_phonebook_get_support_list(co);
408 static void on_response_imc_phonebook_get_info(TcorePending *p,
409 guint data_len, const void *data, void *user_data)
411 const TcoreAtResponse *at_resp = data;
412 ImcRespCbData *resp_cb_data = user_data;
413 CoreObject *co = tcore_pending_ref_core_object(p);
414 TelPbResult result = TEL_PB_RESULT_FAILURE;
415 TelPbInfo pb_info = {0, };
416 tcore_check_return_assert(at_resp != NULL);
417 tcore_check_return_assert(resp_cb_data != NULL);
421 if (at_resp->success != TRUE) {
428 if (at_resp->lines == NULL) {
429 err("at_resp->lines is NULL");
431 GSList *lines = at_resp->lines;
433 GSList *tokens = NULL;
435 gint used = 0, total = 0;
436 gint nlen = 0, tlen = 0;
438 PrivateInfo *private_info;
440 /* +CPBS: <storage>[,<used>][,total] */
441 line = g_slist_nth_data(lines, 0);
442 dbg("First Line: [%s]", line);
443 tokens = tcore_at_tok_new(line);
444 if (tokens == NULL) {
445 err("tokens is NULL");
450 temp = g_slist_nth_data(tokens, 1);
453 /* Get total_count */
454 temp = g_slist_nth_data(tokens, 2);
458 tcore_at_tok_free(tokens);
460 /* +CPBF: [<nlength>],[<tlength>],[<glength>],[<slength>],[<elength>] */
461 line = g_slist_nth_data(lines, 1);
462 dbg("Second Line: [%s]", line);
463 tokens = tcore_at_tok_new(line);
464 if (tokens == NULL) {
465 err("tokens is NULL");
469 /* Get number Length */
470 temp = g_slist_nth_data(tokens, 0);
473 /* Get text Length */
474 temp = g_slist_nth_data(tokens, 1);
478 /* Set Response Data */
479 req_type = (TelPbType *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
480 pb_info.pb_type = *req_type;
481 if (*req_type == TEL_PB_USIM) {
482 pb_info.info_u.usim.max_count = total;
483 pb_info.info_u.usim.used_count = used;
484 pb_info.info_u.usim.max_num_len = nlen;
485 pb_info.info_u.usim.max_text_len = tlen;
486 /* Get group name Length */
487 temp = g_slist_nth_data(tokens, 2);
489 pb_info.info_u.usim.max_gas_len = atoi(temp);
490 /* Get second name Length */
491 temp = g_slist_nth_data(tokens, 3);
493 pb_info.info_u.usim.max_sne_len = atoi(temp);
494 /* Get email Length */
495 temp = g_slist_nth_data(tokens, 4);
497 pb_info.info_u.usim.max_email_len = atoi(temp);
499 pb_info.info_u.sim.max_count = total;
500 pb_info.info_u.sim.used_count = used;
501 pb_info.info_u.sim.max_num_len = nlen;
502 pb_info.info_u.sim.max_text_len = tlen;
505 /* Set Request type in PrivateObject */
506 tcore_phonebook_set_selected_type(co, *req_type);
507 result = TEL_PB_RESULT_SUCCESS;
508 tcore_at_tok_free(tokens);
510 /* If don't have valid used_index, get used_index by req_type */
511 private_info = tcore_object_ref_user_data(co);
512 if ((*req_type == TEL_PB_FDN && private_info->used_index_fdn_valid == FALSE)
513 || (*req_type == TEL_PB_ADN && private_info->used_index_adn_valid == FALSE)
514 || (*req_type == TEL_PB_SDN && private_info->used_index_sdn_valid == FALSE)
515 || (*req_type == TEL_PB_USIM && private_info->used_index_usim_valid == FALSE))
516 __imc_phonebook_get_used_index(co, *req_type, total);
520 /* Invoke callback */
521 if (resp_cb_data->cb)
522 resp_cb_data->cb(co, (gint)result, &pb_info, resp_cb_data->cb_data);
524 /* Free callback data */
525 imc_destroy_resp_cb_data(resp_cb_data);
528 static void on_response_imc_phonebook_read_record(TcorePending *p,
529 guint data_len, const void *data, void *user_data)
531 const TcoreAtResponse *at_resp = data;
532 ImcRespCbData *resp_cb_data = user_data;
533 CoreObject *co = tcore_pending_ref_core_object(p);
534 TelPbResult result = TEL_PB_RESULT_FAILURE;
535 GSList *tokens = NULL;
536 gchar *index = NULL, *number = NULL, *name = NULL;
537 TelPbReadRecord read_record = {0, };
538 tcore_check_return_assert(at_resp != NULL);
539 tcore_check_return_assert(resp_cb_data != NULL);
543 if (at_resp->success != TRUE) {
550 if (at_resp->lines == NULL) {
551 err("at_resp->lines is NULL");
553 const gchar *line = (const gchar *)at_resp->lines->data;
557 dbg("Line: [%s]", line);
559 tokens = tcore_at_tok_new(line);
560 if (tokens == NULL) {
561 err("tokens is NULL");
566 index = g_slist_nth_data(tokens, 0);
573 number = g_slist_nth_data(tokens, 1);
575 number = tcore_at_tok_extract(number);
582 name = g_slist_nth_data(tokens, 3);
584 name = tcore_at_tok_extract(name);
590 /* Set Request type in PrivateObject */
591 req_type = (TelPbType *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
592 tcore_phonebook_set_selected_type(co, *req_type);
594 /* Set Response Data */
595 read_record.index = atoi(index);
596 read_record.pb_type = *req_type;
598 /* Get used_index list by req_type */
599 if (__imc_phonebook_get_index_list_by_type(co, *req_type, &list) == TRUE) {
601 if ((guint)list->data == read_record.index) {
602 if ((list = g_slist_next(list)) != NULL) {
603 /* If exist, set next_index */
604 read_record.next_index = (guint)list->data;
605 dbg("next_index is [%u]", read_record.next_index);
607 /* read_record.index is the end of used_index */
608 read_record.next_index = -1;
609 dbg("End of used_index");
613 list = g_slist_next(list);
617 read_record.next_index = 0;
620 if (*req_type == TEL_PB_USIM) {
621 gchar *hidden, *group, *anr, *sne, *email;
623 /* Get Name and Number */
624 g_strlcpy(read_record.rec_u.usim.name, name, TEL_PB_TEXT_MAX_LEN + 1);
625 g_strlcpy(read_record.rec_u.usim.number, number, TEL_PB_NUMBER_MAX_LEN + 1);
628 hidden = g_slist_nth_data(tokens, 4);
630 read_record.rec_u.usim.hidden = atoi(hidden);
634 group = g_slist_nth_data(tokens, 5);
636 group = tcore_at_tok_extract(group);
637 g_strlcpy(read_record.rec_u.usim.grp_name, group, TEL_PB_TEXT_MAX_LEN + 1);
642 anr = g_slist_nth_data(tokens, 6);
644 anr = tcore_at_tok_extract(anr);
646 g_strlcpy(read_record.rec_u.usim.anr[0].number,
647 anr, TEL_PB_NUMBER_MAX_LEN + 1);
648 read_record.rec_u.usim.anr_count = 1;
654 sne = g_slist_nth_data(tokens, 8);
656 sne = tcore_at_tok_extract(sne);
657 g_strlcpy(read_record.rec_u.usim.sne, sne, TEL_PB_TEXT_MAX_LEN + 1);
662 email = g_slist_nth_data(tokens, 9);
664 email = tcore_at_tok_extract(email);
666 g_strlcpy(read_record.rec_u.usim.email[0], email, TEL_PB_TEXT_MAX_LEN + 1);
667 read_record.rec_u.usim.email_count = 1;
673 /* Get Name and Number */
674 g_strlcpy(read_record.rec_u.sim.name, name, TEL_PB_TEXT_MAX_LEN + 1);
675 g_strlcpy(read_record.rec_u.sim.number, number, TEL_PB_NUMBER_MAX_LEN + 1);
678 result = TEL_PB_RESULT_SUCCESS;
682 /* Invoke callback */
683 if (resp_cb_data->cb)
684 resp_cb_data->cb(co, (gint)result, &read_record, resp_cb_data->cb_data);
686 /* Free callback data */
687 imc_destroy_resp_cb_data(resp_cb_data);
690 tcore_at_tok_free(tokens);
695 static void on_response_imc_phonebook_update_record(TcorePending *p,
696 guint data_len, const void *data, void *user_data)
698 const TcoreAtResponse *at_resp = data;
699 ImcRespCbData *resp_cb_data = user_data;
700 CoreObject *co = tcore_pending_ref_core_object(p);
701 TelPbUpdateRecord *req_data;
702 TelPbResult result = TEL_PB_RESULT_FAILURE;
704 tcore_check_return_assert(at_resp != NULL);
705 tcore_check_return_assert(resp_cb_data != NULL);
709 if (at_resp->success != TRUE) {
715 result = TEL_PB_RESULT_SUCCESS;
717 /* Set Request type in PrivateObject */
718 req_data = (TelPbUpdateRecord *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
719 tcore_phonebook_set_selected_type(co, req_data->pb_type);
721 /* Get used_index list by req_type */
722 if (__imc_phonebook_get_index_list_by_type(co,
723 req_data->pb_type, &list) != TRUE) {
724 err("used_index list is NOT valid");
726 list = g_slist_insert_sorted(list, (gpointer)req_data->index,
727 __imc_phonebook_compare_index);
731 /* Invoke callback */
732 if (resp_cb_data->cb)
733 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
735 /* Free callback data */
736 imc_destroy_resp_cb_data(resp_cb_data);
739 static void on_response_imc_phonebook_delete_record(TcorePending *p,
740 guint data_len, const void *data, void *user_data)
742 const TcoreAtResponse *at_resp = data;
743 ImcRespCbData *resp_cb_data = user_data;
744 CoreObject *co = tcore_pending_ref_core_object(p);
745 TelPbRecordInfo *req_data;
747 TelPbResult result = TEL_PB_RESULT_FAILURE;
748 tcore_check_return_assert(at_resp != NULL);
749 tcore_check_return_assert(resp_cb_data != NULL);
753 if (at_resp->success != TRUE) {
759 result = TEL_PB_RESULT_SUCCESS;
761 /* Set Request type in PrivateObject */
762 req_data = (TelPbRecordInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
763 tcore_phonebook_set_selected_type(co, req_data->pb_type);
765 /* Get used_index list by req_type */
766 if (__imc_phonebook_get_index_list_by_type(co,
767 req_data->pb_type, &list) != TRUE) {
768 err("used_index list is NOT valid");
770 list = g_slist_remove(list, (gconstpointer)req_data->index);
771 dbg("Remove index: [%u]", req_data->index);
775 /* Invoke callback */
776 if (resp_cb_data->cb)
777 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
779 /* Free callback data */
780 imc_destroy_resp_cb_data(resp_cb_data);
784 * Operation - get_info
787 * AT-Command: AT+CPBS?;+CPBF=?
790 * Success: (Multi line)
791 * +CPBS: <storage>[,<used>][,total]
792 * +CPBF: [<nlength>],[<tlength>],[<glength>],[<slength>],[<elength>]
795 * <nlength> Maximum length of field <number>
796 * <tlength> Maximum length of field <text>
797 * <glength> Maximum length of field <group>
798 * <slength> Maximum length of field <secondtext>
799 * <elength> Maximum length of field <email>
802 * +CME ERROR: <error>
804 static TelReturn imc_phonebook_get_info(CoreObject *co,
805 const TelPbType pb_type,
806 TcoreObjectResponseCallback cb, void *cb_data)
810 ImcRespCbData *resp_cb_data;
811 TelReturn ret = TEL_RETURN_FAILURE;
815 /* Check whether pb_type is supported or not, and Select pb_type */
816 if (__imc_phonebook_check_and_select_type(co, pb_type, &set_pb_cmd) != TRUE) {
821 at_cmd = g_strdup_printf("%s+CPBS?;+CPBF=?", set_pb_cmd);
823 /* Response callback data */
824 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
825 (void *)&pb_type, sizeof(TelPbType));
827 /* Send Request to Modem */
828 ret = tcore_at_prepare_and_send_request(co,
830 TCORE_AT_COMMAND_TYPE_MULTILINE,
831 TCORE_PENDING_PRIORITY_DEFAULT,
833 on_response_imc_phonebook_get_info, resp_cb_data,
834 on_send_imc_request, NULL,
836 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get Info");
846 * Operation - read_record
849 * AT-Command: AT+CPBR=<index>
852 * 1 Integer type values in range of location numbers of phonebook memory
856 * Success: (Single line);
857 * +CPBR: <index>,<number>,<type>,<text>[,<hidden>][,<group>]
858 * [,<adnumber>][,<adtype>][,<secondtext>][,<email>]]
861 * <number> String type phone number of format <type>
862 * <type> Type of address octet in integer format
863 * <text> String type field of maximum length <tlength>
864 * <hidden> Indicates if the entry is hidden or not – only available,
865 * if a UICC with an active USIM application is present
866 * 0 Phonebook entry not hidden
867 * 1 Phonebook entry hidden
868 * <group> String type field of maximum length <glength>
869 * <adnumber> String type phone number of format <adtype>
870 * <adtype> Type of address octet in integer format
871 * <secondtext> String type field of maximum length <slength>
872 * <email> String type field of maximum length <elength>
875 * +CME ERROR: <error>
877 static TelReturn imc_phonebook_read_record(CoreObject *co,
878 const TelPbRecordInfo *record,
879 TcoreObjectResponseCallback cb, void *cb_data)
883 ImcRespCbData *resp_cb_data;
884 guint used_index = 0;
885 TelReturn ret = TEL_RETURN_FAILURE;
889 /* Check whether pb_type is supported or not, and Select pb_type */
890 if (__imc_phonebook_check_and_select_type(co, record->pb_type, &set_pb_cmd) != TRUE) {
894 /* Check whether index is used or not */
895 __imc_phonebook_check_used_index(co, record->pb_type, record->index, &used_index);
898 at_cmd = g_strdup_printf("%s+CPBR=%u", set_pb_cmd, used_index);
900 /* Response callback data */
901 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
902 (void *)&(record->pb_type), sizeof(TelPbType));
904 /* Send Request to Modem */
905 ret = tcore_at_prepare_and_send_request(co,
907 TCORE_AT_COMMAND_TYPE_SINGLELINE,
908 TCORE_PENDING_PRIORITY_DEFAULT,
910 on_response_imc_phonebook_read_record, resp_cb_data,
911 on_send_imc_request, NULL,
913 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Read Record");
923 * Operation - update_record
926 * AT-Command: AT+CPBW=[<index>][,<number>[,<type>[,<text>[,<group>[,<adnumber>
927 * [,<adtype>[,<secondtext>[,<email>[,<hidden>]]]]]]]]]
929 * ... same read_record Operation
932 * Success: (No Result)
935 * +CME ERROR: <error>
937 static TelReturn imc_phonebook_update_record(CoreObject *co,
938 const TelPbUpdateRecord *req_data,
939 TcoreObjectResponseCallback cb, void *cb_data)
943 ImcRespCbData *resp_cb_data;
944 TelReturn ret = TEL_RETURN_FAILURE;
948 /* Check whether pb_type is supported or not, and Select pb_type */
949 if (__imc_phonebook_check_and_select_type(co, req_data->pb_type, &set_pb_cmd) != TRUE) {
953 /* Set AT-Command according pb_type */
954 if (req_data->pb_type == TEL_PB_USIM) {
955 at_cmd = g_strdup_printf("%s+CPBW=%u,\"%s\",,\"%s\",\"%s\",\"%s\",,\"%s\",\"%s\",%d",
956 set_pb_cmd, req_data->index,
957 req_data->rec_u.usim.number, req_data->rec_u.usim.name,
958 req_data->rec_u.usim.grp_name, req_data->rec_u.usim.anr[0].number,
959 req_data->rec_u.usim.sne, req_data->rec_u.usim.email[0],
960 req_data->rec_u.usim.hidden);
962 at_cmd = g_strdup_printf("%s+CPBW=%u,\"%s\",,\"%s\"",
963 set_pb_cmd, req_data->index,
964 req_data->rec_u.sim.number,
965 req_data->rec_u.sim.name);
968 /* Response callback data */
969 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
970 (void *)req_data, sizeof(TelPbUpdateRecord));
972 /* Send Request to Modem */
973 ret = tcore_at_prepare_and_send_request(co,
975 TCORE_AT_COMMAND_TYPE_NO_RESULT,
976 TCORE_PENDING_PRIORITY_DEFAULT,
978 on_response_imc_phonebook_update_record, resp_cb_data,
979 on_send_imc_request, NULL,
981 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Update Record");
991 * Operation - delete_record
994 * AT-Command: AT+CPBW=<index>
997 * 1 Integer type values in range of location numbers of phonebook memory
1001 * Success: (No Result)
1004 * +CME ERROR: <error>
1006 static TelReturn imc_phonebook_delete_record(CoreObject *co,
1007 const TelPbRecordInfo *record,
1008 TcoreObjectResponseCallback cb, void *cb_data)
1012 ImcRespCbData *resp_cb_data;
1013 TelReturn ret = TEL_RETURN_FAILURE;
1017 /* Check whether pb_type is supported or not, and Select pb_type */
1018 if (__imc_phonebook_check_and_select_type(co, record->pb_type, &set_pb_cmd) != TRUE) {
1023 at_cmd = g_strdup_printf("%s+CPBW=%u", set_pb_cmd, record->index);
1025 /* Response callback data */
1026 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
1027 (void *)record, sizeof(TelPbRecordInfo));
1029 /* Send Request to Modem */
1030 ret = tcore_at_prepare_and_send_request(co,
1032 TCORE_AT_COMMAND_TYPE_NO_RESULT,
1033 TCORE_PENDING_PRIORITY_DEFAULT,
1035 on_response_imc_phonebook_delete_record, resp_cb_data,
1036 on_send_imc_request, NULL,
1038 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Delete Record");
1040 /* Free resources */
1047 /* Phonebook Operations */
1048 static TcorePbOps imc_phonebook_ops = {
1049 .get_info = imc_phonebook_get_info,
1050 .read_record = imc_phonebook_read_record,
1051 .update_record = imc_phonebook_update_record,
1052 .delete_record = imc_phonebook_delete_record,
1055 gboolean imc_phonebook_init(TcorePlugin *p, CoreObject *co)
1057 PrivateInfo *private_info;
1061 /* Set PrivateInfo */
1062 private_info = tcore_malloc0(sizeof(PrivateInfo));
1063 tcore_object_link_user_data(co, private_info);
1065 /* Set operations */
1066 tcore_phonebook_set_ops(co, &imc_phonebook_ops);
1069 tcore_object_add_callback(co, "+PBREADY", on_notification_imc_phonebook_status, NULL);
1075 void imc_phonebook_exit(TcorePlugin *p, CoreObject *co)
1077 PrivateInfo *private_info;
1079 private_info = tcore_object_ref_user_data(co);
1080 tcore_check_return_assert(private_info != NULL);
1082 /* Free PrivateInfo */
1083 g_slist_free_full(private_info->used_index_fdn, g_free);
1084 g_slist_free_full(private_info->used_index_adn, g_free);
1085 g_slist_free_full(private_info->used_index_sdn, g_free);
1086 g_slist_free_full(private_info->used_index_usim, g_free);
1087 tcore_free(private_info);