4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Ankit Jogi <ankit.jogi@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.
27 #include <core_object.h>
30 #include <co_phonebook.h>
32 #include <user_request.h>
37 #include "s_phonebook.h"
50 /* Type Of Number and Number Plan */
51 #define TON_INTERNATIONAL 145
52 #define TON_UNKNOWN 129
53 #define NUM_PLAN_INTERNATIONAL 0x0070
54 #define NUM_PLAN_UNKNOWN 0x0060
56 enum pb_usim_file_type {
57 PB_USIM_NAME = 0x01, /**< Name */
58 PB_USIM_NUMBER, /**< Number */
59 PB_USIM_ANR, /**< Another number */
60 PB_USIM_EMAIL, /**< Email */
61 PB_USIM_SNE, /**< Second name entry */
62 PB_USIM_GRP, /**< Group file */
63 PB_USIM_PBC, /** <1 byte control info and 1 byte hidden info*/
64 PB_USIM_ANRA, /**< Another number a*/
65 PB_USIM_ANRB, /**< Another number b*/
66 PB_USIM_ANRC, /**< Another number c*/
67 PB_USIM_EMAILA, /**< email a*/
68 PB_USIM_EMAILB, /**< email b*/
69 PB_USIM_EMAILC, /**< email c*/
72 static TReturn _get_support_list(CoreObject *o);
73 static TReturn s_get_count(CoreObject *o, UserRequest *ur);
74 static TReturn s_get_info(CoreObject *o, UserRequest *ur);
75 static TReturn s_get_usim_info(CoreObject *o, UserRequest *ur);
76 static TReturn s_read_record(CoreObject *o, UserRequest *ur);
77 static TReturn s_update_record(CoreObject *o, UserRequest *ur);
78 static TReturn s_delete_record(CoreObject *o, UserRequest *ur);
80 static enum tcore_response_command _find_resp_command(UserRequest *ur)
82 switch(tcore_user_request_get_command(ur))
84 case TREQ_PHONEBOOK_GETCOUNT:
85 return TRESP_PHONEBOOK_GETCOUNT;
86 case TREQ_PHONEBOOK_GETMETAINFO:
87 return TRESP_PHONEBOOK_GETMETAINFO;
88 case TREQ_PHONEBOOK_GETUSIMINFO:
89 return TRESP_PHONEBOOK_GETUSIMINFO;
90 case TREQ_PHONEBOOK_READRECORD:
91 return TRESP_PHONEBOOK_READRECORD;
92 case TREQ_PHONEBOOK_UPDATERECORD:
93 return TRESP_PHONEBOOK_UPDATERECORD;
94 case TREQ_PHONEBOOK_DELETERECORD:
95 return TRESP_PHONEBOOK_DELETERECORD;
101 static enum tel_phonebook_ton _find_num_plan(int number_plan)
103 enum tel_phonebook_ton result;
104 dbg("number_plan : 0x%04x", number_plan);
106 if(number_plan & NUM_PLAN_INTERNATIONAL) {
107 result = PB_TON_INTERNATIONAL;
110 result = PB_TON_UNKNOWN;
112 dbg("result : %d", result);
116 static void on_confirmation_phonebook_message_send(TcorePending *p, gboolean result, void *user_data)
118 dbg("msg out from queue");
120 if (result == FALSE) { /* Fail */
128 static char* _get_phonebook_type(enum tel_phonebook_type pb_type)
130 char *phonebook_type = NULL;
131 dbg(" Function entry ");
132 dbg("pb_type = %d", pb_type);
134 phonebook_type = (char*)calloc(sizeof(char), VAL_FIVE);
135 if(NULL == phonebook_type) {
136 err("Memory allcoation failed");
137 return phonebook_type;
143 phonebook_type = "FD";
148 phonebook_type = "SM";
151 phonebook_type = "SN";
154 phonebook_type = "AP";
157 dbg("Invalid pb_type [%02x]", pb_type);
158 free(phonebook_type);
159 phonebook_type = NULL;
162 dbg(" Function exit");
163 return phonebook_type;
166 static enum tel_phonebook_type _get_phonebook_enum(const char* pb_type)
168 enum tel_phonebook_type phonebook_type = PB_TYPE_UNKNOWNN;
169 dbg(" Function entry ");
170 dbg("pb_type = %s", pb_type);
172 if(strcmp("FD", pb_type) == VAL_ZERO) {
173 phonebook_type = PB_TYPE_FDN;
175 else if(strcmp("SM", pb_type) == VAL_ZERO) {
176 phonebook_type = PB_TYPE_ADN;
178 else if(strcmp("SN", pb_type) == VAL_ZERO) {
179 phonebook_type = PB_TYPE_SDN;
181 else if(strcmp("AP", pb_type) == VAL_ZERO) {
182 phonebook_type = PB_TYPE_USIM;
185 dbg(" Function exit");
186 return phonebook_type;
189 static gboolean on_event_phonebook_status(CoreObject *o, const void *event_info, void *user_data)
191 dbg("Phonebook init received from modem");
193 _get_support_list(o);
198 static void _on_response_select(TcorePending *p, int data_len, const void *data, void *user_data)
200 const TcoreATResponse *resp = data;
201 UserRequest *ur = NULL;
202 CoreObject *o = NULL;
203 enum tcore_request_command req_cmd = TREQ_UNKNOWN;
204 int *selected_pb = user_data;
205 GQueue *queue = NULL;
206 dbg(" Function entry ");
208 o = tcore_pending_ref_core_object(p);
209 ur = tcore_pending_ref_user_request(p);
211 dbg("error - current ur is NULL");
215 queue = tcore_object_ref_user_data(o);
217 ur = tcore_user_request_ref(ur);
220 req_cmd = tcore_user_request_get_command(ur);
221 dbg("origin treq command [%x]", req_cmd);
223 if(resp->success > VAL_ZERO) {
225 tcore_phonebook_set_selected_type(o, *selected_pb);
228 case TREQ_PHONEBOOK_GETCOUNT:
231 case TREQ_PHONEBOOK_GETMETAINFO:
234 case TREQ_PHONEBOOK_GETUSIMINFO:
235 s_get_usim_info(o, ur);
237 case TREQ_PHONEBOOK_READRECORD:
238 s_read_record(o, ur);
240 case TREQ_PHONEBOOK_UPDATERECORD:
241 s_update_record(o, ur);
243 case TREQ_PHONEBOOK_DELETERECORD:
244 s_delete_record(o, ur);
247 dbg("not handled treq cmd[%d]", req_cmd);
256 case TREQ_PHONEBOOK_GETCOUNT:
258 struct tresp_phonebook_get_count resp_getcount;
259 dbg("error TREQ_PHONEBOOK_GETCOUNT");
260 memset(&resp_getcount, 0x00, sizeof(struct tresp_phonebook_get_count));
261 resp_getcount.result = PB_FAIL;
262 tcore_user_request_send_response(ur, TRESP_PHONEBOOK_GETCOUNT, sizeof(struct tresp_phonebook_get_count), &resp_getcount);
265 case TREQ_PHONEBOOK_GETMETAINFO:
267 dbg("error TREQ_PHONEBOOK_GETMETAINFO");
270 case TREQ_PHONEBOOK_GETUSIMINFO:
272 dbg("error TREQ_PHONEBOOK_GETUSIMINFO");
275 case TREQ_PHONEBOOK_READRECORD:
277 struct tresp_phonebook_read_record resp_readrecord;
278 dbg("error TREQ_PHONEBOOK_READRECORD");
279 memset(&resp_readrecord, 0x00, sizeof(struct tresp_phonebook_read_record));
280 resp_readrecord.result = PB_FAIL;
281 resp_readrecord.phonebook_type = *selected_pb;
282 tcore_user_request_send_response(ur, TRESP_PHONEBOOK_READRECORD, sizeof(struct tresp_phonebook_read_record), &resp_readrecord);
285 case TREQ_PHONEBOOK_UPDATERECORD:
287 struct tresp_phonebook_update_record resp_updaterecord;
288 dbg("error TREQ_PHONEBOOK_UPDATERECORD");
289 memset(&resp_updaterecord, 0x00, sizeof(struct tresp_phonebook_update_record));
290 resp_updaterecord.result = PB_FAIL;
291 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_update_record), &resp_updaterecord);
294 case TREQ_PHONEBOOK_DELETERECORD:
296 struct tresp_phonebook_delete_record resp_deleterecord;
297 dbg("error TREQ_PHONEBOOK_DELETERECORD");
298 memset(&resp_deleterecord, 0x00, sizeof(struct tresp_phonebook_delete_record));
299 resp_deleterecord.result = PB_FAIL;
300 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_delete_record), &resp_deleterecord);
304 dbg("not handled treq cmd[%d]", req_cmd);
312 dbg(" Function exit");
315 static void on_response_get_count(TcorePending *p, int data_len, const void *data, void *user_data)
317 const TcoreATResponse *resp = data;
318 UserRequest *ur = NULL;
320 const char *temp = NULL;
321 struct tresp_phonebook_get_count res;
323 dbg(" Function entry ");
325 ur = tcore_pending_ref_user_request(p);
327 dbg("error - current ur is NULL");
331 memset(&res, 0x00, sizeof(struct tresp_phonebook_get_count));
332 if(resp->success > VAL_ZERO) {
335 temp = (const char*)resp->lines->data;
336 tokens = tcore_at_tok_new(temp);
337 if (g_slist_length(tokens) < VAL_ONE) {
338 msg("invalid message");
339 tcore_at_tok_free(tokens);
343 res.result = PB_SUCCESS;
345 temp = (const char*)g_slist_nth_data(tokens, VAL_ZERO);
346 pbtype = util_removeQuotes((void*)temp);
347 res.type = _get_phonebook_enum(pbtype);
349 if(NULL != g_slist_nth_data(tokens, VAL_ONE)){
350 res.used_count = atoi(g_slist_nth_data(tokens, VAL_ONE));
353 if(NULL != g_slist_nth_data(tokens, VAL_TWO)){
354 res.total_count = atoi(g_slist_nth_data(tokens, VAL_TWO));
356 dbg("used count = %d, total count= %d", res.used_count, res.total_count);
362 res.result = PB_FAIL;
365 tcore_user_request_send_response(ur, TRESP_PHONEBOOK_GETCOUNT, sizeof(struct tresp_phonebook_get_count), &res);
367 tcore_at_tok_free(tokens);
368 dbg(" Function exit");
371 static void on_response_get_info(TcorePending *p, int data_len, const void *data, void *user_data)
373 struct tresp_phonebook_get_info res = {0,};
374 const TcoreATResponse *resp = data;
375 UserRequest *ur = NULL;
378 int *selected_pb = (int*)user_data;
380 dbg(" Function entry ");
382 ur = tcore_pending_ref_user_request(p);
384 dbg("error - current ur is NULL");
388 memset(&res, 0x00, sizeof(struct tresp_phonebook_get_info));
389 res.type = *selected_pb;
390 if(resp->success > VAL_ZERO) {
393 line = (const char*)resp->lines->data;
394 tokens = tcore_at_tok_new(line);
395 if (g_slist_length(tokens) < VAL_ONE) {
396 msg("invalid message");
397 tcore_at_tok_free(tokens);
401 res.result = PB_SUCCESS;
403 res.number_length_max = atoi(g_slist_nth_data(tokens, VAL_ZERO));
404 res.text_length_max = atoi(g_slist_nth_data(tokens, VAL_ONE));
405 dbg("number_length_max %d text_length_max %d",res.number_length_max,res.text_length_max);
409 res.result = PB_FAIL;
412 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_get_info), &res);
414 tcore_at_tok_free(tokens);
417 dbg(" Function exit");
420 static void on_response_read_record(TcorePending *p, int data_len, const void *data, void *user_data)
422 const TcoreATResponse *resp = data;
423 UserRequest *ur = NULL;
426 struct tresp_phonebook_read_record res;
427 int num_len = VAL_ZERO;
428 int name_len = VAL_ZERO;
429 int num_plan = VAL_ZERO;
432 int *selected_pb = (int*)user_data;
434 dbg(" Function entry ");
436 ur = tcore_pending_ref_user_request(p);
438 dbg("error - current ur is NULL");
442 memset(&res, 0x00, sizeof(struct tresp_phonebook_read_record));
443 res.phonebook_type = *selected_pb;
445 if(resp->success > VAL_ZERO) {
448 line = (const char*)resp->lines->data;
449 tokens = tcore_at_tok_new(line);
450 if (g_slist_length(tokens) < VAL_ONE) {
451 msg("invalid message");
452 tcore_at_tok_free(tokens);
456 res.result = PB_SUCCESS;
458 res.index = atoi(g_slist_nth_data(tokens, VAL_ZERO));
459 res.next_index = (res.index + VAL_ONE);
460 num_plan = atoi(g_slist_nth_data(tokens, VAL_TWO));
461 res.ton = _find_num_plan(num_plan);
463 temp = g_slist_nth_data(tokens, VAL_ONE);
464 member = util_removeQuotes((void*)temp);
465 dbg("number %s - %d", member, (num_len-VAL_TWO));
466 memcpy(res.number, member, strlen(member));
470 temp = g_slist_nth_data(tokens, VAL_THREE);
471 member = util_removeQuotes((void*)temp);
472 dbg("name %s - %d", member, strlen(member));
473 memcpy(res.name, member, strlen(member));
477 if(NULL != g_slist_nth_data(tokens, VAL_FOUR)) {
478 if(atoi(g_slist_nth_data(tokens, VAL_FOUR)) == VAL_ZERO) {
479 dbg("phonebook entry not hidden");
482 dbg("phonebook entry hidden");
486 if(NULL != g_slist_nth_data(tokens, VAL_SIX)){
487 num_len = strlen(g_slist_nth_data(tokens, VAL_SIX));
488 snprintf((char *)res.anr1, num_len+1, "%s", (char*)g_slist_nth_data(tokens, VAL_SIX));
491 if(NULL != g_slist_nth_data(tokens, VAL_SEVEN)){
492 num_plan = atoi(g_slist_nth_data(tokens, VAL_SEVEN));
493 res.anr1_ton = _find_num_plan(num_plan);
496 if(NULL != g_slist_nth_data(tokens, VAL_NINE)){
497 name_len = strlen(g_slist_nth_data(tokens, VAL_NINE));
498 memcpy(res.email1, g_slist_nth_data(tokens, VAL_NINE), name_len);
503 res.result = PB_FAIL;
506 tcore_user_request_send_response(ur, TRESP_PHONEBOOK_READRECORD, sizeof(struct tresp_phonebook_read_record), &res);
508 tcore_at_tok_free(tokens);
511 dbg(" Function exit");
514 static void on_response_update_record(TcorePending *p, int data_len, const void *data, void *user_data)
516 const TcoreATResponse *resp = data;
517 UserRequest *ur = NULL;
518 struct tresp_phonebook_update_record res;
519 dbg(" Function entry ");
521 if(resp->success > VAL_ZERO) {
523 res.result = PB_SUCCESS;
527 res.result = PB_FAIL;
530 ur = tcore_pending_ref_user_request(p);
532 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_update_record),
536 dbg("error - current ur is NULL");
541 static void on_response_delete_record(TcorePending *p, int data_len, const void *data, void *user_data)
543 const TcoreATResponse *resp = data;
544 UserRequest *ur = NULL;
545 struct tresp_phonebook_delete_record res;
547 if(resp->success > VAL_ZERO) {
549 res.result = PB_SUCCESS;
553 res.result = PB_FAIL;
556 ur = tcore_pending_ref_user_request(p);
558 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_delete_record), &res);
561 dbg("error - current ur is NULL");
565 static void _response_get_support_list(TcorePending *p, int data_len, const void *data, void *user_data)
567 const TcoreATResponse *resp = data;
573 struct tnoti_phonebook_status noti_data = {0,};
575 dbg(" Function entry ");
577 o = tcore_pending_ref_core_object(p);
579 dbg("error - core object is null");
583 if(resp->success > VAL_ZERO) {
586 line = (const char*)resp->lines->data;
587 tokens = tcore_at_tok_new(line);
588 if (g_slist_length(tokens) < VAL_ONE) {
589 msg("invalid message");
590 tcore_at_tok_free(tokens);
595 temp = (char*)g_slist_nth_data(tokens, VAL_ZERO);
596 pbtype = strtok(temp, "(,)");
597 while(pbtype != NULL) {
598 temp = util_removeQuotes((void*)pbtype);
599 dbg("pbtype %s", temp);
600 if (VAL_ZERO == strcmp(temp, "FD")) {
601 dbg("SIM fixed-dialing phonebook");
602 noti_data.support_list.b_fdn = VAL_ONE;
604 else if (VAL_ZERO == strcmp(temp, "SN")) {
605 dbg("Service Dialing Number");
606 noti_data.support_list.b_sdn = VAL_ONE;
608 else if (VAL_ZERO == strcmp(temp, "SM")) {
609 dbg("2G SIM ADN phonebook");
610 noti_data.support_list.b_adn = VAL_ONE;
612 else if (VAL_ZERO == strcmp(temp, "LD")) {
613 dbg("SIM/UICC last-dialling-phonebook");
615 else if (VAL_ZERO == strcmp(temp, "ON")) {
616 dbg("SIM (or MT) own numbers (MSISDNs) list");
618 else if (VAL_ZERO == strcmp(temp, "BL")) {
619 dbg("Blacklist phonebook");
621 else if (VAL_ZERO == strcmp(temp, "EC")) {
622 dbg("SIM emergency-call-codes phonebook");
624 else if (VAL_ZERO == strcmp(temp, "AP")) {
625 dbg("Selected application phonebook");
627 else if (VAL_ZERO == strcmp(temp, "BN")) {
628 dbg("SIM barred-dialling-number");
630 pbtype = strtok (NULL, "(,)");
634 noti_data.b_init = TRUE;
635 tcore_phonebook_set_support_list(o, ¬i_data.support_list);
636 tcore_phonebook_set_status(o, noti_data.b_init);
637 tcore_at_tok_free(tokens);
641 noti_data.b_init = FALSE;
642 tcore_phonebook_set_status(o, noti_data.b_init);
645 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_PHONEBOOK_STATUS,
646 sizeof(struct tnoti_phonebook_status), ¬i_data);
649 static TReturn _get_support_list(CoreObject *o)
651 TcoreHal *hal = NULL;
652 TcoreATRequest *req = NULL;
653 TcorePending *pending = NULL;
654 char *cmd_str = NULL;
656 dbg(" Function entry ");
659 return TCORE_RETURN_EINVAL;
662 hal = tcore_object_get_hal(o);
663 pending = tcore_pending_new(o, VAL_ZERO);
665 cmd_str = g_strdup_printf("AT+CPBS=?");
666 req = tcore_at_request_new(cmd_str, "+CPBS:", TCORE_AT_SINGLELINE);
667 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
669 tcore_pending_set_request_data(pending, VAL_ZERO, req);
670 tcore_pending_set_response_callback(pending, _response_get_support_list, NULL);
671 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
673 tcore_hal_send_request(hal, pending);
676 dbg(" Function exit");
677 return TCORE_RETURN_SUCCESS;
680 static TReturn _select(CoreObject *o, UserRequest *ur, enum tel_phonebook_type pbt)
682 TcoreHal *hal = NULL;
683 TcoreATRequest *req = NULL;
684 TcorePending *pending = NULL;
685 char *cmd_str = NULL;
686 const struct treq_phonebook_get_count *req_data;
688 char *phonebook_type = NULL;
690 dbg(" Function entry ");
693 return TCORE_RETURN_EINVAL;
695 req_data = tcore_user_request_ref_data(ur, NULL);
697 phonebook_type = (char*)_get_phonebook_type(req_data->phonebook_type);
698 if(NULL == phonebook_type){
699 err("phonebook_type is NULL");
700 return TCORE_RETURN_FAILURE;
703 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
704 if(pb_type == NULL) {
705 err("Failed to allocate memory");
706 return TCORE_RETURN_FAILURE;
710 cmd_str = g_strdup_printf("AT+CPBS=\"%s\"", phonebook_type);
711 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
712 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
714 hal = tcore_object_get_hal(o);
715 pending = tcore_pending_new(o, VAL_ZERO);
716 tcore_pending_set_request_data(pending, VAL_ZERO, req);
717 tcore_pending_set_response_callback(pending, _on_response_select, (void*)pb_type);
718 tcore_pending_link_user_request(pending, ur);
719 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
721 tcore_hal_send_request(hal, pending);
723 free(phonebook_type);
725 dbg(" Function exit");
726 return TCORE_RETURN_SUCCESS;
729 static TReturn s_get_count(CoreObject *o, UserRequest *ur)
731 TcoreHal *hal = NULL;
732 TcoreATRequest *req = NULL;
733 TcorePending *pending = NULL;
734 char *cmd_str = NULL;
735 const struct treq_phonebook_get_count *req_data = NULL;
736 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
738 dbg("Function Entry");
740 return TCORE_RETURN_EINVAL;
742 req_data = tcore_user_request_ref_data(ur, NULL);
743 pbt = tcore_phonebook_get_selected_type(o);
744 if (req_data->phonebook_type != pbt) {
745 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
746 _select(o, ur, req_data->phonebook_type);
747 return TCORE_RETURN_SUCCESS;
750 cmd_str = g_strdup_printf("AT+CPBS?");
751 req = tcore_at_request_new(cmd_str, "+CPBS:", TCORE_AT_SINGLELINE);
752 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
754 hal = tcore_object_get_hal(o);
755 pending = tcore_pending_new(o, VAL_ZERO);
757 tcore_pending_set_request_data(pending, VAL_ZERO, req);
758 tcore_pending_set_response_callback(pending, on_response_get_count, hal);
759 tcore_pending_link_user_request(pending, ur);
760 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
762 tcore_hal_send_request(hal, pending);
765 dbg("Function exit");
766 return TCORE_RETURN_SUCCESS;
769 static TReturn s_get_info(CoreObject *o, UserRequest *ur)
771 TcoreHal *hal = NULL;
772 TcoreATRequest *req = NULL;
773 TcorePending *pending = NULL;
774 char *cmd_str = NULL;
775 const struct treq_phonebook_get_info *req_data = NULL;
776 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
779 dbg(" Function entry ");
782 return TCORE_RETURN_EINVAL;
784 req_data = tcore_user_request_ref_data(ur, NULL);
785 pbt = tcore_phonebook_get_selected_type(o);
786 if (req_data->phonebook_type != pbt) {
787 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
788 _select(o, ur, req_data->phonebook_type);
789 return TCORE_RETURN_SUCCESS;
792 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
793 if(pb_type == NULL) {
794 err("Failed to allocate memory");
795 return TCORE_RETURN_FAILURE;
798 dbg("pb_type %d", *pb_type);
800 cmd_str = g_strdup_printf("AT+CPBF=?");
801 req = tcore_at_request_new(cmd_str, "+CPBF:", TCORE_AT_SINGLELINE);
802 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
804 hal = tcore_object_get_hal(o);
805 pending = tcore_pending_new(o, VAL_ZERO);
807 tcore_pending_set_request_data(pending, VAL_ZERO, req);
808 tcore_pending_set_response_callback(pending, on_response_get_info, (void*)pb_type);
809 tcore_pending_link_user_request(pending, ur);
810 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
812 tcore_hal_send_request(hal, pending);
815 dbg(" Function exit");
816 return TCORE_RETURN_SUCCESS;
820 static TReturn s_get_usim_info(CoreObject *o, UserRequest *ur)
822 dbg("NOT IMPLEMENTED");
824 return TCORE_RETURN_SUCCESS;
827 static TReturn s_read_record(CoreObject *o, UserRequest *ur)
830 TcoreATRequest *req = NULL;
831 TcorePending *pending = NULL;
832 char *cmd_str = NULL;
833 const struct treq_phonebook_read_record *req_data = NULL;
834 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
837 dbg(" Function entry ");
840 return TCORE_RETURN_EINVAL;
842 req_data = tcore_user_request_ref_data(ur, NULL);
843 pbt = tcore_phonebook_get_selected_type(o);
844 if (req_data->phonebook_type != pbt) {
845 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
846 _select(o, ur, req_data->phonebook_type);
847 return TCORE_RETURN_SUCCESS;
850 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
851 if(pb_type == NULL) {
852 err("Failed to allocate memory");
853 return TCORE_RETURN_FAILURE;
856 dbg("pb_type %d", *pb_type);
858 cmd_str = g_strdup_printf("AT+CPBR=%d,%d", req_data->index, req_data->index);
859 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_SINGLELINE);
860 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
862 hal = tcore_object_get_hal(o);
863 pending = tcore_pending_new(o, VAL_ZERO);
865 tcore_pending_set_request_data(pending, VAL_ZERO, req);
866 tcore_pending_set_response_callback(pending, on_response_read_record, (void*)pb_type);
867 tcore_pending_link_user_request(pending, ur);
868 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
870 tcore_hal_send_request(hal, pending);
873 dbg(" Function exit");
874 return TCORE_RETURN_SUCCESS;
877 static TReturn s_update_record(CoreObject *o, UserRequest *ur)
879 TcoreHal *hal = NULL;
880 TcoreATRequest *req = NULL;
881 TcorePending *pending = NULL;
882 char *cmd_str = NULL;
883 const struct treq_phonebook_update_record *req_data = NULL;
884 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
886 dbg(" Function entry ");
889 return TCORE_RETURN_EINVAL;
891 req_data = tcore_user_request_ref_data(ur, NULL);
892 pbt = tcore_phonebook_get_selected_type(o);
893 if (req_data->phonebook_type != pbt) {
894 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
895 _select(o, ur, req_data->phonebook_type);
896 return TCORE_RETURN_SUCCESS;
899 cmd_str = g_strdup_printf("AT+CPBW=,\"%s\",%d,\"%s\"", req_data->number, ((PB_TON_INTERNATIONAL == req_data->ton) ? TON_INTERNATIONAL: TON_UNKNOWN), req_data->name);
900 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_SINGLELINE);
901 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
903 hal = tcore_object_get_hal(o);
904 pending = tcore_pending_new(o, VAL_ZERO);
906 tcore_pending_set_request_data(pending, VAL_ZERO, req);
907 tcore_pending_set_response_callback(pending, on_response_update_record, hal);
908 tcore_pending_link_user_request(pending, ur);
909 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
911 tcore_hal_send_request(hal, pending);
914 dbg(" Function exit");
915 return TCORE_RETURN_SUCCESS;
918 static TReturn s_delete_record(CoreObject *o, UserRequest *ur)
920 TcoreHal *hal = NULL;
921 TcoreATRequest *req = NULL;
922 TcorePending *pending = NULL;
923 char *cmd_str = NULL;
924 const struct treq_phonebook_delete_record *req_data;
925 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
927 dbg(" Function entry ");
930 return TCORE_RETURN_EINVAL;
932 req_data = tcore_user_request_ref_data(ur, NULL);
933 pbt = tcore_phonebook_get_selected_type(o);
934 if (req_data->phonebook_type != pbt) {
935 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
936 _select(o, ur, req_data->phonebook_type);
937 return TCORE_RETURN_SUCCESS;
940 cmd_str = g_strdup_printf("AT+CPBW=%d", req_data->index);
941 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_SINGLELINE);
942 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
944 hal = tcore_object_get_hal(o);
945 pending = tcore_pending_new(o, VAL_ZERO);
947 tcore_pending_set_request_data(pending, VAL_ZERO, req);
948 tcore_pending_set_response_callback(pending, on_response_delete_record, hal);
949 tcore_pending_link_user_request(pending, ur);
950 tcore_pending_set_send_callback(pending, on_confirmation_phonebook_message_send, NULL);
952 tcore_hal_send_request(hal, pending);
955 dbg(" Function exit");
956 return TCORE_RETURN_SUCCESS;
959 static struct tcore_phonebook_operations phonebook_ops = {
960 .get_count = s_get_count,
961 .get_info = s_get_info,
962 .get_usim_info = s_get_usim_info,
963 .read_record = s_read_record,
964 .update_record = s_update_record,
965 .delete_record = s_delete_record,
968 gboolean s_phonebook_init(TcorePlugin *p, TcoreHal *h)
970 CoreObject *o = NULL;
973 o = tcore_phonebook_new(p, "phonebook", &phonebook_ops, h);
977 tcore_object_add_callback(o, "+PBREADY", on_event_phonebook_status, NULL);
982 void s_phonebook_exit(TcorePlugin *p)
984 CoreObject *o = NULL;
985 o = tcore_plugin_ref_core_object(p, "phonebook");
989 tcore_phonebook_free(o);