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 struct valid_pb_index{
59 int indexlist_populated;
63 static struct valid_pb_index __pbindex;
65 enum pb_usim_file_type {
66 PB_USIM_NAME = 0x01, /**< Name */
67 PB_USIM_NUMBER, /**< Number */
68 PB_USIM_ANR, /**< Another number */
69 PB_USIM_EMAIL, /**< Email */
70 PB_USIM_SNE, /**< Second name entry */
71 PB_USIM_GRP, /**< Group file */
72 PB_USIM_PBC, /** <1 byte control info and 1 byte hidden info*/
73 PB_USIM_ANRA, /**< Another number a*/
74 PB_USIM_ANRB, /**< Another number b*/
75 PB_USIM_ANRC, /**< Another number c*/
76 PB_USIM_EMAILA, /**< email a*/
77 PB_USIM_EMAILB, /**< email b*/
78 PB_USIM_EMAILC, /**< email c*/
81 static TReturn _get_support_list(CoreObject *o);
82 static TReturn s_get_count(CoreObject *o, UserRequest *ur);
83 static TReturn s_get_info(CoreObject *o, UserRequest *ur);
84 static TReturn s_get_usim_info(CoreObject *o, UserRequest *ur);
85 static TReturn s_read_record(CoreObject *o, UserRequest *ur);
86 static TReturn s_update_record(CoreObject *o, UserRequest *ur);
87 static TReturn s_delete_record(CoreObject *o, UserRequest *ur);
90 static void pbindex_reset()
92 if(__pbindex.indexlist){
93 free(__pbindex.indexlist);
95 memset(&__pbindex, 0x00, sizeof(struct valid_pb_index));
98 static enum tcore_response_command _find_resp_command(UserRequest *ur)
100 switch(tcore_user_request_get_command(ur))
102 case TREQ_PHONEBOOK_GETCOUNT:
103 return TRESP_PHONEBOOK_GETCOUNT;
104 case TREQ_PHONEBOOK_GETMETAINFO:
105 return TRESP_PHONEBOOK_GETMETAINFO;
106 case TREQ_PHONEBOOK_GETUSIMINFO:
107 return TRESP_PHONEBOOK_GETUSIMINFO;
108 case TREQ_PHONEBOOK_READRECORD:
109 return TRESP_PHONEBOOK_READRECORD;
110 case TREQ_PHONEBOOK_UPDATERECORD:
111 return TRESP_PHONEBOOK_UPDATERECORD;
112 case TREQ_PHONEBOOK_DELETERECORD:
113 return TRESP_PHONEBOOK_DELETERECORD;
115 return TRESP_UNKNOWN;
119 static enum tel_phonebook_ton _find_num_plan(int number_plan)
121 enum tel_phonebook_ton result;
122 dbg("number_plan : 0x%04x", number_plan);
124 if(number_plan & NUM_PLAN_INTERNATIONAL) {
125 result = PB_TON_INTERNATIONAL;
128 result = PB_TON_UNKNOWN;
130 dbg("result : %d", result);
134 static char* _get_phonebook_type(enum tel_phonebook_type pb_type)
136 dbg("pb_type = %d", pb_type);
150 dbg("Invalid pb_type [%02x]", pb_type);
155 static enum tel_phonebook_type _get_phonebook_enum(const char* pb_type)
157 enum tel_phonebook_type phonebook_type = PB_TYPE_UNKNOWNN;
158 dbg(" Function entry ");
159 dbg("pb_type = %s", pb_type);
161 if(strcmp("FD", pb_type) == VAL_ZERO) {
162 phonebook_type = PB_TYPE_FDN;
164 else if(strcmp("SM", pb_type) == VAL_ZERO) {
165 phonebook_type = PB_TYPE_ADN;
167 else if(strcmp("SN", pb_type) == VAL_ZERO) {
168 phonebook_type = PB_TYPE_SDN;
170 else if(strcmp("AP", pb_type) == VAL_ZERO) {
171 phonebook_type = PB_TYPE_USIM;
174 dbg(" Function exit");
175 return phonebook_type;
178 static gboolean on_event_phonebook_status(CoreObject *o, const void *event_info, void *user_data)
180 dbg("Phonebook init received from modem");
182 _get_support_list(o);
187 static void _on_response_select(TcorePending *p, int data_len, const void *data, void *user_data)
189 const TcoreATResponse *resp = data;
190 UserRequest *ur = NULL;
191 enum tcore_request_command req_cmd = TREQ_UNKNOWN;
192 int *selected_pb = user_data;
194 dbg(" Function entry ");
196 ur = tcore_pending_ref_user_request(p);
198 dbg("error - current ur is NULL");
202 req_cmd = tcore_user_request_get_command(ur);
203 dbg("origin treq command [%x]", req_cmd);
205 if(resp->success > VAL_ZERO) {
206 CoreObject *o = NULL;
207 o = tcore_pending_ref_core_object(p);
210 tcore_phonebook_set_selected_type(o, *selected_pb);
213 case TREQ_PHONEBOOK_GETCOUNT:
216 case TREQ_PHONEBOOK_GETMETAINFO:
219 case TREQ_PHONEBOOK_GETUSIMINFO:
220 s_get_usim_info(o, ur);
222 case TREQ_PHONEBOOK_READRECORD:
223 s_read_record(o, ur);
225 case TREQ_PHONEBOOK_UPDATERECORD:
226 s_update_record(o, ur);
228 case TREQ_PHONEBOOK_DELETERECORD:
229 s_delete_record(o, ur);
232 dbg("not handled treq cmd[%d]", req_cmd);
241 case TREQ_PHONEBOOK_GETCOUNT:
243 struct tresp_phonebook_get_count resp_getcount;
244 dbg("error TREQ_PHONEBOOK_GETCOUNT");
245 memset(&resp_getcount, 0x00, sizeof(struct tresp_phonebook_get_count));
246 resp_getcount.result = PB_FAIL;
247 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_get_count), &resp_getcount);
250 case TREQ_PHONEBOOK_GETMETAINFO:
252 dbg("error TREQ_PHONEBOOK_GETMETAINFO");
255 case TREQ_PHONEBOOK_GETUSIMINFO:
257 dbg("error TREQ_PHONEBOOK_GETUSIMINFO");
260 case TREQ_PHONEBOOK_READRECORD:
262 struct tresp_phonebook_read_record resp_readrecord;
263 dbg("error TREQ_PHONEBOOK_READRECORD");
265 memset(&resp_readrecord, 0x00, sizeof(struct tresp_phonebook_read_record));
266 resp_readrecord.result = PB_FAIL;
267 resp_readrecord.phonebook_type = *selected_pb;
268 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_read_record), &resp_readrecord);
271 case TREQ_PHONEBOOK_UPDATERECORD:
273 struct tresp_phonebook_update_record resp_updaterecord;
274 dbg("error TREQ_PHONEBOOK_UPDATERECORD");
275 memset(&resp_updaterecord, 0x00, sizeof(struct tresp_phonebook_update_record));
276 resp_updaterecord.result = PB_FAIL;
277 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_update_record), &resp_updaterecord);
280 case TREQ_PHONEBOOK_DELETERECORD:
282 struct tresp_phonebook_delete_record resp_deleterecord;
283 dbg("error TREQ_PHONEBOOK_DELETERECORD");
284 memset(&resp_deleterecord, 0x00, sizeof(struct tresp_phonebook_delete_record));
285 resp_deleterecord.result = PB_FAIL;
286 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_delete_record), &resp_deleterecord);
290 dbg("not handled treq cmd[%d]", req_cmd);
298 dbg(" Function exit");
301 static void _on_response_getindexlist(TcorePending *p, int data_len, const void *data, void *user_data)
303 const TcoreATResponse *resp = data;
304 UserRequest *ur = NULL;
305 struct tresp_phonebook_read_record resp_readrecord;
306 int *selected_pb = user_data;
312 dbg(" Function entry ");
314 ur = tcore_pending_ref_user_request(p);
316 dbg("error - current ur is NULL");
319 memset(&resp_readrecord, 0x00, sizeof(struct tresp_phonebook_read_record));
320 resp_readrecord.result = PB_FAIL;
321 resp_readrecord.phonebook_type = *selected_pb;
323 if(resp->success > 0)
325 CoreObject *o = NULL;
326 o = tcore_pending_ref_core_object(p);
329 tcore_phonebook_set_selected_type(o, *selected_pb);
331 total_lines = g_slist_length(resp->lines);
332 dbg("Total number of PB entry %d\n", total_lines);
333 if (total_lines < 1) {
334 msg("invalid message");
338 __pbindex.indexlist = (int*)malloc(__pbindex.used_count * sizeof(int));
339 if(__pbindex.indexlist == NULL){
340 dbg("Failed to allocate memory");
344 resp_readrecord.result = PB_SUCCESS;
345 for (count = 0; count < total_lines; count++) {
346 /* Take each line response at a time & parse it */
347 line = tcore_at_tok_nth(resp->lines, count);
348 tokens = tcore_at_tok_new(line);
349 __pbindex.indexlist[count] = atoi(g_slist_nth_data(tokens, 0));
350 dbg("__pbindex.indexlist[%d] = %d", count, __pbindex.indexlist[count]);
351 tcore_at_tok_free(tokens);
354 __pbindex.indexlist_populated = 1;
355 s_read_record(o, ur);
364 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_read_record), &resp_readrecord);
368 dbg(" Function exit");
371 static void on_response_get_count(TcorePending *p, int data_len, const void *data, void *user_data)
373 const TcoreATResponse *resp = data;
374 UserRequest *ur = NULL;
376 const char *temp = NULL;
377 struct tresp_phonebook_get_count res;
379 dbg(" Function entry ");
381 ur = tcore_pending_ref_user_request(p);
383 dbg("error - current ur is NULL");
387 memset(&res, 0x00, sizeof(struct tresp_phonebook_get_count));
388 res.result = PB_FAIL;
390 if(resp->success > VAL_ZERO) {
393 temp = (const char*)resp->lines->data;
394 tokens = tcore_at_tok_new(temp);
395 if (g_slist_length(tokens) < VAL_THREE) {
396 //No of tokens must be three. We cannot proceed without used and total count.
397 msg("invalid message");
401 res.result = PB_SUCCESS;
403 temp = (const char*)g_slist_nth_data(tokens, VAL_ZERO);
404 pbtype = util_removeQuotes((void*)temp);
405 res.type = _get_phonebook_enum(pbtype);
407 if(NULL != g_slist_nth_data(tokens, VAL_ONE)){
408 res.used_count = atoi(g_slist_nth_data(tokens, VAL_ONE));
409 __pbindex.used_count = res.used_count;
410 dbg("used_count %d", __pbindex.used_count);
413 if(NULL != g_slist_nth_data(tokens, VAL_TWO)){
414 res.total_count = atoi(g_slist_nth_data(tokens, VAL_TWO));
415 __pbindex.total_count = res.total_count;
417 dbg("used count = %d, total count= %d", res.used_count, res.total_count);
425 tcore_at_tok_free(tokens);
426 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_get_count), &res);
427 dbg(" Function exit");
430 static void on_response_get_info(TcorePending *p, int data_len, const void *data, void *user_data)
432 struct tresp_phonebook_get_info res = {0,};
433 const TcoreATResponse *resp = data;
434 UserRequest *ur = NULL;
437 int *selected_pb = (int*)user_data;
439 dbg(" Function entry ");
441 ur = tcore_pending_ref_user_request(p);
443 dbg("error - current ur is NULL");
447 memset(&res, 0x00, sizeof(struct tresp_phonebook_get_info));
448 res.result = PB_FAIL;
449 res.type = *selected_pb;
451 if(resp->success > VAL_ZERO) {
454 line = (const char*)resp->lines->data;
455 tokens = tcore_at_tok_new(line);
456 if (g_slist_length(tokens) < VAL_ONE) {
457 msg("invalid message");
461 res.result = PB_SUCCESS;
463 res.number_length_max = atoi(g_slist_nth_data(tokens, VAL_ZERO));
464 res.text_length_max = atoi(g_slist_nth_data(tokens, VAL_ONE));
465 dbg("number_length_max %d text_length_max %d",res.number_length_max,res.text_length_max);
471 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_get_info), &res);
474 tcore_at_tok_free(tokens);
475 dbg(" Function exit");
479 static void on_response_read_record(TcorePending *p, int data_len, const void *data, void *user_data)
481 const TcoreATResponse *resp = data;
482 UserRequest *ur = NULL;
485 struct tresp_phonebook_read_record res;
486 int num_len = VAL_ZERO;
487 int name_len = VAL_ZERO;
488 int num_plan = VAL_ZERO;
491 int *selected_pb = (int*)user_data;
493 dbg(" Function entry ");
495 ur = tcore_pending_ref_user_request(p);
497 dbg("error - current ur is NULL");
501 memset(&res, 0x00, sizeof(struct tresp_phonebook_read_record));
502 res.result = PB_FAIL;
503 res.phonebook_type = *selected_pb;
505 if(resp->success > VAL_ZERO) {
508 line = (const char*)resp->lines->data;
509 tokens = tcore_at_tok_new(line);
510 if (g_slist_length(tokens) < VAL_ONE) {
511 msg("invalid message");
516 res.result = PB_SUCCESS;
517 res.index = atoi(g_slist_nth_data(tokens, 0));
518 __pbindex.current_index++;
519 if(__pbindex.current_index >= __pbindex.used_count){
524 dbg("__pbindex.current_index %d", __pbindex.current_index);
525 res.next_index = __pbindex.indexlist[__pbindex.current_index];
527 num_plan = atoi(g_slist_nth_data(tokens, 2));
528 res.ton = _find_num_plan(num_plan);
530 /*Remove the quotes("") from the number string*/
531 temp = g_slist_nth_data(tokens, 1);
532 member = util_removeQuotes((void*)temp);
533 memcpy(res.number, member, strlen(member));
534 dbg("number %s - %d", res.number, strlen((const char*)res.number));
538 /*Remove the quotes("") from the name string*/
539 temp = g_slist_nth_data(tokens, 3);
540 member = util_removeQuotes((void*)temp);
541 memcpy(res.name, member, strlen(member));
542 dbg("name %s - %d", res.name, strlen((const char*)res.name));
545 res.dcs = PB_TEXT_ASCII;
546 res.name_len = strlen((const char*)res.name);
547 if(NULL != g_slist_nth_data(tokens, VAL_FOUR)) {
548 if(atoi(g_slist_nth_data(tokens, VAL_FOUR)) == VAL_ZERO) {
549 dbg("phonebook entry not hidden");
552 dbg("phonebook entry hidden");
556 if(NULL != g_slist_nth_data(tokens, VAL_SIX)){
557 num_len = strlen(g_slist_nth_data(tokens, VAL_SIX));
558 snprintf((char *)res.anr1, num_len+1, "%s", (char*)g_slist_nth_data(tokens, VAL_SIX));
561 if(NULL != g_slist_nth_data(tokens, VAL_SEVEN)){
562 num_plan = atoi(g_slist_nth_data(tokens, VAL_SEVEN));
563 res.anr1_ton = _find_num_plan(num_plan);
566 if(NULL != g_slist_nth_data(tokens, VAL_NINE)){
567 name_len = strlen(g_slist_nth_data(tokens, VAL_NINE));
568 memcpy(res.email1, g_slist_nth_data(tokens, VAL_NINE), name_len);
576 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_read_record), &res);
579 tcore_at_tok_free(tokens);
580 dbg(" Function exit");
584 static void on_response_update_record(TcorePending *p, int data_len, const void *data, void *user_data)
586 const TcoreATResponse *resp = data;
587 UserRequest *ur = NULL;
588 struct tresp_phonebook_update_record res;
589 dbg(" Function entry ");
591 if(resp->success > VAL_ZERO) {
593 res.result = PB_SUCCESS;
597 res.result = PB_FAIL;
600 ur = tcore_pending_ref_user_request(p);
602 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_update_record),
606 dbg("error - current ur is NULL");
608 dbg(" Function exit");
611 static void on_response_delete_record(TcorePending *p, int data_len, const void *data, void *user_data)
613 const TcoreATResponse *resp = data;
614 UserRequest *ur = NULL;
615 struct tresp_phonebook_delete_record res;
617 dbg(" Function entry ");
619 if(resp->success > VAL_ZERO) {
621 res.result = PB_SUCCESS;
625 res.result = PB_FAIL;
628 ur = tcore_pending_ref_user_request(p);
630 tcore_user_request_send_response(ur, _find_resp_command(ur), sizeof(struct tresp_phonebook_delete_record), &res);
633 dbg("error - current ur is NULL");
635 dbg(" Function exit");
638 static void _response_get_support_list(TcorePending *p, int data_len, const void *data, void *user_data)
640 const TcoreATResponse *resp = data;
646 struct tnoti_phonebook_status noti_data = {0,};
648 dbg(" Function entry ");
650 o = tcore_pending_ref_core_object(p);
652 dbg("error - core object is null");
656 noti_data.b_init = FALSE;
658 if(resp->success > VAL_ZERO) {
661 line = (const char*)resp->lines->data;
662 tokens = tcore_at_tok_new(line);
663 if (g_slist_length(tokens) < VAL_ONE) {
664 msg("invalid message");
669 temp = (char*)g_slist_nth_data(tokens, VAL_ZERO);
670 pbtype = strtok(temp, "(,)");
671 while(pbtype != NULL) {
672 temp = util_removeQuotes((void*)pbtype);
673 dbg("pbtype %s", temp);
674 if (VAL_ZERO == strcmp(temp, "FD")) {
675 dbg("SIM fixed-dialing phonebook");
676 noti_data.support_list.b_fdn = VAL_ONE;
678 else if (VAL_ZERO == strcmp(temp, "SN")) {
679 dbg("Service Dialing Number");
680 noti_data.support_list.b_sdn = VAL_ONE;
682 else if (VAL_ZERO == strcmp(temp, "SM")) {
683 dbg("2G SIM ADN phonebook");
684 noti_data.support_list.b_adn = VAL_ONE;
686 else if (VAL_ZERO == strcmp(temp, "LD")) {
687 dbg("SIM/UICC last-dialling-phonebook");
689 else if (VAL_ZERO == strcmp(temp, "ON")) {
690 dbg("SIM (or MT) own numbers (MSISDNs) list");
692 else if (VAL_ZERO == strcmp(temp, "BL")) {
693 dbg("Blacklist phonebook");
695 else if (VAL_ZERO == strcmp(temp, "EC")) {
696 dbg("SIM emergency-call-codes phonebook");
698 else if (VAL_ZERO == strcmp(temp, "AP")) {
699 dbg("Selected application phonebook");
701 else if (VAL_ZERO == strcmp(temp, "BN")) {
702 dbg("SIM barred-dialling-number");
704 pbtype = strtok (NULL, "(,)");
708 noti_data.b_init = TRUE;
709 tcore_phonebook_set_support_list(o, ¬i_data.support_list);
710 tcore_phonebook_set_status(o, noti_data.b_init);
714 tcore_phonebook_set_status(o, noti_data.b_init);
717 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_PHONEBOOK_STATUS,
718 sizeof(struct tnoti_phonebook_status), ¬i_data);
719 tcore_at_tok_free(tokens);
720 dbg(" Function exit");
723 static TReturn _get_support_list(CoreObject *o)
725 TcoreHal *hal = NULL;
726 TcoreATRequest *req = NULL;
727 TcorePending *pending = NULL;
728 char *cmd_str = NULL;
730 dbg(" Function entry ");
733 return TCORE_RETURN_EINVAL;
736 hal = tcore_object_get_hal(o);
737 pending = tcore_pending_new(o, VAL_ZERO);
739 cmd_str = g_strdup_printf("AT+CPBS=?");
740 req = tcore_at_request_new(cmd_str, "+CPBS:", TCORE_AT_SINGLELINE);
741 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
743 tcore_pending_set_request_data(pending, VAL_ZERO, req);
744 tcore_pending_set_response_callback(pending, _response_get_support_list, NULL);
746 tcore_hal_send_request(hal, pending);
749 dbg(" Function exit");
750 return TCORE_RETURN_SUCCESS;
753 static TReturn _select(CoreObject *o, UserRequest *ur, enum tel_phonebook_type pbt)
755 TcoreHal *hal = NULL;
756 TcoreATRequest *req = NULL;
757 TcorePending *pending = NULL;
758 char *cmd_str = NULL;
759 const struct treq_phonebook_get_count *req_data;
761 char *phonebook_type = NULL;
762 UserRequest *ur_dup = NULL;
764 dbg(" Function entry ");
767 return TCORE_RETURN_EINVAL;
769 req_data = tcore_user_request_ref_data(ur, NULL);
770 ur_dup = tcore_user_request_ref(ur);
772 phonebook_type = (char*)_get_phonebook_type(req_data->phonebook_type);
773 if(NULL == phonebook_type){
774 err("phonebook_type is NULL");
775 return TCORE_RETURN_FAILURE;
778 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
779 if(pb_type == NULL) {
780 err("Failed to allocate memory");
781 return TCORE_RETURN_FAILURE;
785 cmd_str = g_strdup_printf("AT+CPBS=\"%s\"", phonebook_type);
786 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
787 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
789 hal = tcore_object_get_hal(o);
790 pending = tcore_pending_new(o, VAL_ZERO);
791 tcore_pending_set_request_data(pending, VAL_ZERO, req);
792 tcore_pending_set_response_callback(pending, _on_response_select, (void*)pb_type);
793 tcore_pending_link_user_request(pending, ur_dup);
795 tcore_hal_send_request(hal, pending);
798 dbg(" Function exit");
799 return TCORE_RETURN_SUCCESS;
802 static TReturn _getindexlist(CoreObject *o, UserRequest *ur, enum tel_phonebook_type pbt)
804 TcoreHal *hal = NULL;
805 TcoreATRequest *req = NULL;
806 TcorePending *pending = NULL;
807 char *cmd_str = NULL;
808 const struct treq_phonebook_get_count *req_data;
811 UserRequest *ur_dup = NULL;
813 dbg(" Function entry ");
816 return TCORE_RETURN_EINVAL;
818 pb_type = calloc(sizeof(enum tel_phonebook_type),1);
819 if(pb_type == NULL) {
820 err("Failed to allocate memory");
821 return TCORE_RETURN_FAILURE;
825 req_data = tcore_user_request_ref_data(ur, NULL);
826 ur_dup = tcore_user_request_ref(ur);
828 cmd_str = g_strdup_printf("AT+CPBR=%d,%d", start_index, __pbindex.total_count);
829 req = tcore_at_request_new(cmd_str, "+CPBR:", TCORE_AT_MULTILINE);
830 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
832 hal = tcore_object_get_hal(o);
833 pending = tcore_pending_new(o, 0);
835 tcore_pending_set_request_data(pending, 0, req);
836 tcore_pending_set_response_callback(pending, _on_response_getindexlist, (void*)pb_type);
837 tcore_pending_link_user_request(pending, ur_dup);
838 tcore_hal_send_request(hal, pending);
841 dbg(" Function exit");
842 return TCORE_RETURN_SUCCESS;
845 static TReturn s_get_count(CoreObject *o, UserRequest *ur)
847 TcoreHal *hal = NULL;
848 TcoreATRequest *req = NULL;
849 TcorePending *pending = NULL;
850 char *cmd_str = NULL;
851 const struct treq_phonebook_get_count *req_data = NULL;
852 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
854 dbg("Function Entry");
856 return TCORE_RETURN_EINVAL;
858 req_data = tcore_user_request_ref_data(ur, NULL);
859 pbt = tcore_phonebook_get_selected_type(o);
860 if (req_data->phonebook_type != pbt) {
861 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
862 return _select(o, ur, req_data->phonebook_type);
865 cmd_str = g_strdup_printf("AT+CPBS?");
866 req = tcore_at_request_new(cmd_str, "+CPBS:", TCORE_AT_SINGLELINE);
867 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
869 hal = tcore_object_get_hal(o);
870 pending = tcore_pending_new(o, VAL_ZERO);
872 tcore_pending_set_request_data(pending, VAL_ZERO, req);
873 tcore_pending_set_response_callback(pending, on_response_get_count, hal);
874 tcore_pending_link_user_request(pending, ur);
876 tcore_hal_send_request(hal, pending);
879 dbg("Function exit");
880 return TCORE_RETURN_SUCCESS;
883 static TReturn s_get_info(CoreObject *o, UserRequest *ur)
885 TcoreHal *hal = NULL;
886 TcoreATRequest *req = NULL;
887 TcorePending *pending = NULL;
888 char *cmd_str = NULL;
889 const struct treq_phonebook_get_info *req_data = NULL;
890 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
893 dbg(" Function entry ");
896 return TCORE_RETURN_EINVAL;
898 req_data = tcore_user_request_ref_data(ur, NULL);
899 pbt = tcore_phonebook_get_selected_type(o);
900 if (req_data->phonebook_type != pbt) {
901 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
902 return _select(o, ur, req_data->phonebook_type);
905 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
906 if(pb_type == NULL) {
907 err("Failed to allocate memory");
908 return TCORE_RETURN_FAILURE;
911 dbg("pb_type %d", *pb_type);
913 cmd_str = g_strdup_printf("AT+CPBF=?");
914 req = tcore_at_request_new(cmd_str, "+CPBF:", TCORE_AT_SINGLELINE);
915 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
917 hal = tcore_object_get_hal(o);
918 pending = tcore_pending_new(o, VAL_ZERO);
920 tcore_pending_set_request_data(pending, VAL_ZERO, req);
921 tcore_pending_set_response_callback(pending, on_response_get_info, (void*)pb_type);
922 tcore_pending_link_user_request(pending, ur);
924 tcore_hal_send_request(hal, pending);
927 dbg(" Function exit");
928 return TCORE_RETURN_SUCCESS;
932 static TReturn s_get_usim_info(CoreObject *o, UserRequest *ur)
934 dbg("NOT IMPLEMENTED");
936 return TCORE_RETURN_SUCCESS;
939 static TReturn s_read_record(CoreObject *o, UserRequest *ur)
942 TcoreATRequest *req = NULL;
943 TcorePending *pending = NULL;
944 char *cmd_str = NULL;
945 const struct treq_phonebook_read_record *req_data = NULL;
946 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
949 dbg(" Function entry ");
952 return TCORE_RETURN_EINVAL;
954 req_data = tcore_user_request_ref_data(ur, NULL);
955 pbt = tcore_phonebook_get_selected_type(o);
956 if (req_data->phonebook_type != pbt) {
957 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
958 return _select(o, ur, req_data->phonebook_type);
960 if(!__pbindex.indexlist_populated){
961 return _getindexlist(o, ur, req_data->phonebook_type);
963 pb_type = calloc(sizeof(enum tel_phonebook_type),VAL_ONE);
964 if(pb_type == NULL) {
965 err("Failed to allocate memory");
966 return TCORE_RETURN_FAILURE;
969 dbg("pb_type %d", *pb_type);
970 cmd_str = g_strdup_printf("AT+CPBR=%d", __pbindex.indexlist[__pbindex.current_index]);
971 req = tcore_at_request_new(cmd_str, "+CPBR", TCORE_AT_MULTILINE);
972 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
974 hal = tcore_object_get_hal(o);
975 pending = tcore_pending_new(o, VAL_ZERO);
977 tcore_pending_set_request_data(pending, VAL_ZERO, req);
978 tcore_pending_set_response_callback(pending, on_response_read_record, (void*)pb_type);
979 tcore_pending_link_user_request(pending, ur);
981 tcore_hal_send_request(hal, pending);
984 dbg(" Function exit");
985 return TCORE_RETURN_SUCCESS;
988 static TReturn s_update_record(CoreObject *o, UserRequest *ur)
990 TcoreHal *hal = NULL;
991 TcoreATRequest *req = NULL;
992 TcorePending *pending = NULL;
993 char *cmd_str = NULL;
994 const struct treq_phonebook_update_record *req_data = NULL;
995 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
997 dbg(" Function entry ");
1000 return TCORE_RETURN_EINVAL;
1002 req_data = tcore_user_request_ref_data(ur, NULL);
1003 pbt = tcore_phonebook_get_selected_type(o);
1004 if (req_data->phonebook_type != pbt) {
1005 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
1006 return _select(o, ur, req_data->phonebook_type);
1009 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);
1010 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_SINGLELINE);
1011 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1013 hal = tcore_object_get_hal(o);
1014 pending = tcore_pending_new(o, VAL_ZERO);
1016 tcore_pending_set_request_data(pending, VAL_ZERO, req);
1017 tcore_pending_set_response_callback(pending, on_response_update_record, hal);
1018 tcore_pending_link_user_request(pending, ur);
1020 tcore_hal_send_request(hal, pending);
1023 dbg(" Function exit");
1024 return TCORE_RETURN_SUCCESS;
1027 static TReturn s_delete_record(CoreObject *o, UserRequest *ur)
1029 TcoreHal *hal = NULL;
1030 TcoreATRequest *req = NULL;
1031 TcorePending *pending = NULL;
1032 char *cmd_str = NULL;
1033 const struct treq_phonebook_delete_record *req_data;
1034 enum tel_phonebook_type pbt = PB_TYPE_UNKNOWNN;
1036 dbg(" Function entry ");
1039 return TCORE_RETURN_EINVAL;
1041 req_data = tcore_user_request_ref_data(ur, NULL);
1042 pbt = tcore_phonebook_get_selected_type(o);
1043 if (req_data->phonebook_type != pbt) {
1044 dbg("req pb[%d] is different with tcore pb[%d]", req_data->phonebook_type, pbt);
1045 return _select(o, ur, req_data->phonebook_type);
1048 cmd_str = g_strdup_printf("AT+CPBW=%d", req_data->index);
1049 req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_SINGLELINE);
1050 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
1052 hal = tcore_object_get_hal(o);
1053 pending = tcore_pending_new(o, VAL_ZERO);
1055 tcore_pending_set_request_data(pending, VAL_ZERO, req);
1056 tcore_pending_set_response_callback(pending, on_response_delete_record, hal);
1057 tcore_pending_link_user_request(pending, ur);
1059 tcore_hal_send_request(hal, pending);
1062 dbg(" Function exit");
1063 return TCORE_RETURN_SUCCESS;
1066 static struct tcore_phonebook_operations phonebook_ops = {
1067 .get_count = s_get_count,
1068 .get_info = s_get_info,
1069 .get_usim_info = s_get_usim_info,
1070 .read_record = s_read_record,
1071 .update_record = s_update_record,
1072 .delete_record = s_delete_record,
1075 gboolean s_phonebook_init(TcorePlugin *cp, CoreObject *co_phonebook)
1079 tcore_phonebook_override_ops(co_phonebook, &phonebook_ops);
1081 tcore_object_override_callback(co_phonebook, "+PBREADY", on_event_phonebook_status, NULL);
1088 void s_phonebook_exit(TcorePlugin *cp, CoreObject *co_phonebook)