5 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
8 * Girishashok Joshi <girish.joshi@samsung.com>
9 * Chanyeol Park <chanyeol.park@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
29 #include <stacktrim.h>
30 #include <syspopup_caller.h>
33 #include "bt-internal-types.h"
34 #include "bt-service-common.h"
35 //#include "bt-service-agent.h"
36 //#include "bt-service-gap-agent.h"
37 //#include "bt-service-adapter.h"
38 #include "bt-service-event.h"
39 //#include "bt-service-rfcomm-server.h"
40 //#include "bt-service-device.h"
41 //#include "bt-service-audio.h"
42 #include "bt-service-pbap.h"
46 #define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
47 #define PBAP_OBEX_CLIENT_SERVICE "org.bluez.obex"
48 #define PBAP_OBEX_CLIENT_PATH "/org/bluez/obex"
49 #define PBAP_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
51 #define PBAP_SESSION_SERVICE "org.bluez.obex"
52 #define PBAP_SESSION_INTERFACE "org.bluez.obex.PhonebookAccess1"
53 #define PBAP_VCARDLIST_MAXLENGTH 256
81 PBAP_FIELD_CATEGORIES,
84 PBAP_FIELD_SORT_STRING,
85 PBAP_FIELD_X_IRMC_CALL_DATETIME,
94 "pb", //Phonebook for the saved contacts
95 "ich", //Incoming call history
96 "och", //Outgoing call history
97 "mch", //Missed call history
98 "cch", //Combined Call History cch = ich + och + mch
102 "vcard21", // vCard Format 2.1 (Default)
103 "vcard30", // vCard Format 3.0
107 "indexed", // Index (default)
108 "alphanumeric", // Alphanumeric
109 "phonetic", // Phonetic
112 char *SEARCH_FIELD[] = {
113 "name", // Search by Name(default)
114 "number", // Search by Phone Number
115 "sound", // Search by phonetic sound
118 static char *g_pbap_session_path = NULL;
119 static DBusGConnection *dbus_connection = NULL;
120 static DBusGProxy *g_pbap_proxy = NULL;
125 } selected_path = { -1, -1};
134 } bt_pbap_operation_e;
137 bt_pbap_operation_e operation;
146 bt_pbap_operation_e operation;
147 } bt_pbap_transfer_info_t;
149 static GSList *transfers;
151 int __bt_pbap_call_get_phonebook_size(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
152 int __bt_pbap_call_get_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
153 int __bt_pbap_call_get_vcards_list(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
154 int __bt_pbap_call_get_vcard(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
155 int __bt_pbap_call_search_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
157 static void __bt_pbap_free_data(bt_pbap_data_t *pbap_data)
159 g_free(pbap_data->app_param);
160 g_free(pbap_data->data);
164 static bt_pbap_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
167 bt_pbap_transfer_info_t *transfer;
169 retv_if(transfer_path == NULL, NULL);
171 for (l = transfers; l != NULL; l = l->next) {
174 if (transfer == NULL)
177 if (g_strcmp0(transfer->path, transfer_path) == 0)
184 static void __bt_free_transfer_info(bt_pbap_transfer_info_t *transfer_info)
186 ret_if(transfer_info == NULL);
188 g_free(transfer_info->path);
189 g_free(transfer_info->filename);
190 g_free(transfer_info->remote_device);
191 g_free(transfer_info);
194 void _bt_pbap_obex_transfer_completed(const char *transfer_path, gboolean transfer_status)
196 bt_pbap_transfer_info_t *transfer_info;
198 int success = transfer_status;
199 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
201 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
202 : BLUETOOTH_ERROR_CANCEL;
204 transfer_info = __bt_find_transfer_by_path(transfer_path);
205 ret_if(transfer_info == NULL);
207 BT_DBG("Remote Device [%s] FileName: [%s] Operation[%d]",
208 transfer_info->remote_device, transfer_info->filename,
209 transfer_info->operation);
211 switch(transfer_info->operation) {
213 _bt_send_event(BT_PBAP_CLIENT_EVENT,
214 BLUETOOTH_PBAP_PHONEBOOK_PULL,
215 DBUS_TYPE_INT32, &result,
216 DBUS_TYPE_STRING, &transfer_info->remote_device,
217 DBUS_TYPE_STRING, &transfer_info->filename,
218 DBUS_TYPE_INT32, &success,
223 _bt_send_event(BT_PBAP_CLIENT_EVENT,
224 BLUETOOTH_PBAP_VCARD_PULL,
225 DBUS_TYPE_INT32, &result,
226 DBUS_TYPE_STRING, &transfer_info->remote_device,
227 DBUS_TYPE_STRING, &transfer_info->filename,
228 DBUS_TYPE_INT32, &success,
233 BT_INFO("Case not handled");
237 transfers = g_slist_remove(transfers, transfer_info);
238 __bt_free_transfer_info(transfer_info);
241 void __bt_pbap_connect_cb(DBusGProxy *proxy,
242 DBusGProxyCall *call, void *user_data)
244 char *session_path = NULL;
245 char *address_string = user_data;
246 GError *g_error = NULL;
248 int result = BLUETOOTH_ERROR_CANCEL;
250 BT_DBG("Address = %s", address_string);
251 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
252 DBUS_TYPE_G_OBJECT_PATH, &session_path,
254 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
255 g_error_free(g_error);
257 g_pbap_session_path = g_strdup(session_path);
258 BT_DBG("Session Path = %s\n", g_pbap_session_path);
259 result = BLUETOOTH_ERROR_NONE;
263 _bt_send_event(BT_PBAP_CLIENT_EVENT,
264 BLUETOOTH_PBAP_CONNECTED,
265 DBUS_TYPE_INT32, &result,
266 DBUS_TYPE_STRING, &address_string,
267 DBUS_TYPE_INT32, &connected,
270 g_free(address_string);
271 g_free(session_path);
275 int _bt_pbap_connect(const bluetooth_device_address_t *address)
280 GError *error = NULL;
281 char address_string[18] = { 0, };
284 BT_CHECK_PARAMETER(address, return);
286 /* check if already connected */
287 if (g_pbap_session_path)
288 return BLUETOOTH_ERROR_ALREADY_CONNECT;
290 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
291 address->addr[0], address->addr[1],
292 address->addr[2], address->addr[3],
293 address->addr[4], address->addr[5]);
295 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
296 BT_DBG("Address String: %s", address_string);
297 dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
299 BT_ERR("Couldn't connect to system bus[%s]\n", error->message);
304 g_pbap_proxy = dbus_g_proxy_new_for_name(dbus_connection,
305 PBAP_OBEX_CLIENT_SERVICE,
306 PBAP_OBEX_CLIENT_PATH,
307 PBAP_OBEX_CLIENT_INTERFACE);
309 BT_ERR("Failed to get a proxy for D-Bus\n");
313 hash = g_hash_table_new_full(g_str_hash, g_str_equal,
314 NULL, (GDestroyNotify)g_free);
316 tgt_value = g_new0(GValue, 1);
317 g_value_init(tgt_value, G_TYPE_STRING);
318 g_value_set_string(tgt_value, "pbap");
319 g_hash_table_insert(hash, "Target", tgt_value);
322 ptr = g_strdup(address_string);
323 if (!dbus_g_proxy_begin_call(g_pbap_proxy, "CreateSession",
324 (DBusGProxyCallNotify)__bt_pbap_connect_cb,
327 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
328 hash, G_TYPE_INVALID)) {
329 BT_ERR("Connect Dbus Call Error");
331 g_object_unref(g_pbap_proxy);
332 g_hash_table_destroy(hash);
333 return BLUETOOTH_ERROR_INTERNAL;
336 g_hash_table_destroy(hash);
342 void __bt_pbap_disconnect_cb(DBusGProxy *proxy,
343 DBusGProxyCall *call, void *user_data)
345 char *address_string = user_data;
346 GError *g_error = NULL;
348 int result = BLUETOOTH_ERROR_INTERNAL ;
350 BT_DBG("Address = %s", address_string);
351 if (!dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID)) {
352 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
353 g_error_free(g_error);
355 g_free(g_pbap_session_path);
356 g_pbap_session_path = NULL;
357 result = BLUETOOTH_ERROR_NONE;
358 selected_path.folder = -1;
359 selected_path.type = -1;
363 g_object_unref(proxy);
364 _bt_send_event(BT_PBAP_CLIENT_EVENT,
365 BLUETOOTH_PBAP_CONNECTED,
366 DBUS_TYPE_INT32, &result,
367 DBUS_TYPE_STRING, &address_string,
368 DBUS_TYPE_INT32, &connected,
371 g_free(address_string);
375 int _bt_pbap_disconnect(const bluetooth_device_address_t *address)
378 char address_string[18] = { 0, };
380 BT_CHECK_PARAMETER(address, return);
382 /* check if connected */
383 if (g_pbap_session_path == NULL)
384 return BLUETOOTH_ERROR_NOT_CONNECTED;
386 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
387 address->addr[0], address->addr[1],
388 address->addr[2], address->addr[3],
389 address->addr[4], address->addr[5]);
391 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
392 BT_DBG("Address String: %s", address_string);
393 BT_DBG("Session Path: %s", g_pbap_session_path);
395 ptr = g_strdup(address_string);
396 if (!dbus_g_proxy_begin_call(g_pbap_proxy, "RemoveSession",
397 (DBusGProxyCallNotify)__bt_pbap_disconnect_cb,
399 DBUS_TYPE_G_OBJECT_PATH, g_pbap_session_path,
402 BT_ERR("Disconnect Dbus Call Error");
403 return BLUETOOTH_ERROR_INTERNAL;
409 void __bt_pbap_select_cb(DBusGProxy *proxy,
410 DBusGProxyCall *call, void *user_data)
413 GError *g_error = NULL;
414 bt_pbap_data_t *pbap_data = user_data;
415 char *address_string = pbap_data->data;
417 BT_DBG("Address = %s", address_string);
418 if (dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID)) {
419 switch (pbap_data->operation) {
421 __bt_pbap_call_get_phonebook_size(proxy, pbap_data);
425 __bt_pbap_call_get_phonebook(proxy, pbap_data);
429 __bt_pbap_call_get_vcards_list(proxy, pbap_data);
433 __bt_pbap_call_get_vcard(proxy, pbap_data);
437 __bt_pbap_call_search_phonebook(proxy, pbap_data);
441 g_object_unref(proxy);
442 __bt_pbap_free_data(pbap_data);
446 g_object_unref(proxy);
447 __bt_pbap_free_data(pbap_data);
454 void __bt_pbap_get_phonebook_size_cb(DBusGProxy *proxy,
455 DBusGProxyCall *call, void *user_data)
458 GError *g_error = NULL;
459 int result = BLUETOOTH_ERROR_INTERNAL;
460 bt_pbap_data_t *pbap_data = user_data;
461 char *address_string = pbap_data->data;
462 unsigned int size = 0;
464 BT_DBG("Address = %s", address_string);
465 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
468 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
469 g_error_free(g_error);
472 result = BLUETOOTH_ERROR_NONE;
474 BT_DBG("Size of Phonebook: %d", size);
475 _bt_send_event(BT_PBAP_CLIENT_EVENT,
476 BLUETOOTH_PBAP_PHONEBOOK_SIZE,
477 DBUS_TYPE_INT32, &result,
478 DBUS_TYPE_STRING, &address_string,
479 DBUS_TYPE_INT32, &size,
481 g_object_unref(proxy);
482 __bt_pbap_free_data(pbap_data);
486 void __bt_pbap_get_phonebook_cb(DBusGProxy *proxy,
487 DBusGProxyCall *call, void *user_data)
490 GError *g_error = NULL;
491 bt_pbap_data_t *pbap_data = user_data;
492 char *address_string = pbap_data->data;
493 GHashTable *properties;
494 GValue *value = { 0 };
495 bt_pbap_transfer_info_t *transfer_info;
496 char *transfer = NULL;
497 const gchar *filename = NULL;
499 BT_DBG("Address = %s", address_string);
500 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
501 DBUS_TYPE_G_OBJECT_PATH, &transfer,
502 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
505 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
506 g_error_free(g_error);
508 if (properties != NULL) {
509 value = g_hash_table_lookup(properties, "Filename");
510 filename = value ? g_value_get_string(value) : NULL;
513 BT_DBG("Transfer Path: %s", transfer);
514 BT_DBG("File Name: %s", filename);
515 transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
516 transfer_info->path = transfer;
517 transfer_info->remote_device = g_strdup(address_string);
518 transfer_info->filename = (char *)filename;
519 transfer_info->operation = PULL_ALL;
520 transfers = g_slist_append(transfers, transfer_info);
523 g_object_unref(proxy);
524 __bt_pbap_free_data(pbap_data);
528 void __bt_pbap_get_vcard_list_cb(DBusGProxy *proxy,
529 DBusGProxyCall *call, void *user_data)
532 GError *g_error = NULL;
534 int result = BLUETOOTH_ERROR_INTERNAL;
535 GPtrArray *vcardlist = NULL;
536 bt_pbap_data_t *pbap_data = user_data;
537 char *address_string = pbap_data->data;
538 char **vcard_list = NULL;
539 char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
542 BT_DBG("Address = %s", address_string);
543 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
544 dbus_g_type_get_collection("GPtrArray", dbus_g_type_get_struct("GValueArray",
545 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID)),
546 &vcardlist, G_TYPE_INVALID)) {
547 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
548 g_error_free(g_error);
549 vcard_list = g_new0(char *, length + 1);
551 BT_DBG("vcardlist len %d", vcardlist->len);
552 length = vcardlist->len;
553 result = BLUETOOTH_ERROR_NONE;
555 vcard_list = g_new0(char *, length + 1);
557 GValue *v = g_new0(GValue, 1);//g_ptr_array_index(vcardlist, 0);
558 gchar *elname, *elval;
559 g_value_init(v, dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID));
560 for (i = 0; i < length; i++) {
561 g_value_set_boxed(v, g_ptr_array_index(vcardlist, i));
562 if (dbus_g_type_struct_get (v, 0, &elname, 1, &elval, G_MAXUINT)) {
563 memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
564 g_snprintf (list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
565 "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
566 //If possible send as Array of <STRING, STRING>
567 BT_DBG("%s", list_entry);
568 vcard_list[i] = g_strdup(list_entry);
573 _bt_send_event(BT_PBAP_CLIENT_EVENT,
574 BLUETOOTH_PBAP_VCARD_LIST,
575 DBUS_TYPE_INT32, &result,
576 DBUS_TYPE_STRING, &address_string,
577 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
581 g_object_unref(proxy);
582 __bt_pbap_free_data(pbap_data);
586 void __bt_pbap_get_vcard_cb(DBusGProxy *proxy,
587 DBusGProxyCall *call, void *user_data)
590 GError *g_error = NULL;
591 bt_pbap_data_t *pbap_data = user_data;
592 char *address_string = pbap_data->data;
593 GHashTable *properties;
594 GValue *value = { 0 };
595 bt_pbap_transfer_info_t *transfer_info;
596 char *transfer = NULL;
597 const gchar *filename = NULL;
599 BT_DBG("Address = %s", address_string);
600 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
601 DBUS_TYPE_G_OBJECT_PATH, &transfer,
602 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
605 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
606 g_error_free(g_error);
608 if (properties != NULL) {
609 value = g_hash_table_lookup(properties, "Filename");
610 filename = value ? g_value_get_string(value) : NULL;
613 BT_DBG("Transfer Path: %s", transfer);
614 BT_DBG("File Name: %s", filename);
615 transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
616 transfer_info->path = transfer;
617 transfer_info->remote_device = g_strdup(address_string);
618 transfer_info->filename = (char *)filename;
619 transfer_info->operation = GET_VCARD;
620 transfers = g_slist_append(transfers, transfer_info);
623 g_object_unref(proxy);
624 __bt_pbap_free_data(pbap_data);
628 void __bt_pbap_search_phonebook_cb(DBusGProxy *proxy,
629 DBusGProxyCall *call, void *user_data)
632 GError *g_error = NULL;
634 GPtrArray *vcardlist = NULL;
635 bt_pbap_data_t *pbap_data = user_data;
636 char *address_string = pbap_data->data;
637 char **vcard_list = NULL;
638 char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
640 int result = BLUETOOTH_ERROR_INTERNAL;
642 BT_DBG("Address = %s", address_string);
643 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
644 dbus_g_type_get_collection("GPtrArray", dbus_g_type_get_struct("GValueArray",
645 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID)),
646 &vcardlist, G_TYPE_INVALID)) {
647 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
648 g_error_free(g_error);
650 BT_DBG("vcardlist len %d", vcardlist->len);
651 length = vcardlist->len;
652 result = BLUETOOTH_ERROR_NONE;
654 vcard_list = g_new0(char *, length + 1);
656 GValue *v = g_new0(GValue, 1);//g_ptr_array_index(vcardlist, 0);
657 gchar *elname, *elval;
658 g_value_init(v, dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID));
659 for (i = 0; i < length; i++) {
660 g_value_set_boxed(v, g_ptr_array_index(vcardlist, i));
661 if (dbus_g_type_struct_get (v, 0, &elname, 1, &elval, G_MAXUINT)) {
662 memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
663 g_snprintf (list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
664 "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
665 //If possible send as Array of <STRING, STRING>
666 BT_DBG("%s", list_entry);
667 vcard_list[i] = g_strdup(list_entry);
672 _bt_send_event(BT_PBAP_CLIENT_EVENT,
673 BLUETOOTH_PBAP_PHONEBOOK_SEARCH,
674 DBUS_TYPE_INT32, &result,
675 DBUS_TYPE_STRING, &address_string,
676 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
679 g_object_unref(proxy);
680 __bt_pbap_free_data(pbap_data);
684 int __bt_pbap_call_get_phonebook_size(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
687 if (!dbus_g_proxy_begin_call(proxy, "GetSize",
688 (DBusGProxyCallNotify)__bt_pbap_get_phonebook_size_cb,
691 BT_ERR("GetSize Dbus Call Error");
692 __bt_pbap_free_data(pbap_data);
693 return BLUETOOTH_ERROR_INTERNAL;
696 return BLUETOOTH_ERROR_NONE;
700 int __bt_pbap_call_get_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
708 char *format_str = NULL;
709 char *order_str = NULL;
710 char *target_file = "/opt/usr/media/Downloads/pb.vcf";
711 bt_pbap_pull_parameters_t *app_param = pbap_data->app_param;
713 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
714 NULL, (GDestroyNotify)g_free);
716 /* Add Format Filter only if other than vCard 2.1 (default)*/
717 if (app_param->format > 0) {
718 format_str = g_strdup(FORMAT[app_param->format]);
719 format = g_new0(GValue, 1);
720 g_value_init(format, G_TYPE_STRING);
721 g_value_set_string(format, format_str);
722 g_hash_table_insert(filters, "Format", format);
726 /* Add Order Filter only if other than Indexed (default)*/
727 if (app_param->order > 0) {
728 order_str = g_strdup(ORDER[app_param->order]);
729 order = g_new0(GValue, 1);
730 g_value_init(order, G_TYPE_STRING);
731 g_value_set_string(order, order_str);
732 g_hash_table_insert(filters, "Order", order);
736 max_count = g_new0(GValue, 1);
737 g_value_init(max_count, G_TYPE_UINT);
738 g_value_set_uint(max_count, app_param->maxlist);
739 g_hash_table_insert(filters, "MaxCount", max_count);
741 /* Add Offset Filter only if other than 0 (default)*/
742 if (app_param->offset > 0) {
743 offset = g_new0(GValue, 1);
744 g_value_init(offset, G_TYPE_UINT);
745 g_value_set_uint(offset, app_param->offset);
746 g_hash_table_insert(filters, "Offset", offset);
749 //****************************
750 // Add code for Fields
752 //****************************
754 if (!dbus_g_proxy_begin_call(proxy, "PullAll",
755 (DBusGProxyCallNotify)__bt_pbap_get_phonebook_cb,
757 G_TYPE_STRING, target_file,
758 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
761 BT_ERR("GetSize Dbus Call Error");
762 g_hash_table_destroy(filters);
763 return BLUETOOTH_ERROR_INTERNAL;
765 g_hash_table_destroy(filters);
767 return BLUETOOTH_ERROR_NONE;
771 int __bt_pbap_call_get_vcards_list(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
778 char *order_str = NULL;
779 bt_pbap_list_parameters_t *app_param = pbap_data->app_param;
781 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
782 NULL, (GDestroyNotify)g_free);
784 /* Add Order Filter only if other than Indexed (default)*/
785 if (app_param->order > 0) {
786 order_str = g_strdup(ORDER[app_param->order]);
787 order = g_new0(GValue, 1);
788 g_value_init(order, G_TYPE_STRING);
789 g_value_set_string(order, order_str);
790 g_hash_table_insert(filters, "Order", order);
794 max_count = g_new0(GValue, 1);
795 g_value_init(max_count, G_TYPE_UINT);
796 g_value_set_uint(max_count, app_param->maxlist);
797 g_hash_table_insert(filters, "MaxCount", max_count);
799 /* Add Offset Filter only if other than 0 (default)*/
800 if (app_param->offset > 0) {
801 offset = g_new0(GValue, 1);
802 g_value_init(offset, G_TYPE_UINT);
803 g_value_set_uint(offset, app_param->offset);
804 g_hash_table_insert(filters, "Offset", offset);
807 if (!dbus_g_proxy_begin_call(proxy, "List",
808 (DBusGProxyCallNotify)__bt_pbap_get_vcard_list_cb,
810 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
813 BT_ERR("List Dbus Call Error");
814 g_hash_table_destroy(filters);
815 return BLUETOOTH_ERROR_INTERNAL;
818 g_hash_table_destroy(filters);
820 return BLUETOOTH_ERROR_NONE;
824 int __bt_pbap_call_get_vcard(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
829 char *format_str = NULL;
830 char *target_file = "/opt/usr/media/Downloads/pb.vcf";
831 char *vcard_handle = NULL;
832 char vcard[10] = { 0, };
834 bt_pbap_pull_vcard_parameters_t *app_param = pbap_data->app_param;
836 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
837 NULL, (GDestroyNotify)g_free);
839 /* Add Format Filter only if other than vCard 2.1 (default)*/
840 if (app_param->format > 0) {
841 format_str = g_strdup(FORMAT[app_param->format]);
842 format = g_new0(GValue, 1);
843 g_value_init(format, G_TYPE_STRING);
844 g_value_set_string(format, format_str);
845 g_hash_table_insert(filters, "Format", format);
850 //****************************
851 // Add code for Fields
853 //****************************
855 sprintf(vcard, "%d.vcf", app_param->index);
856 BT_DBG("Handle: %s", vcard);
857 vcard_handle = g_strdup(vcard);
859 if (!dbus_g_proxy_begin_call(proxy, "Pull",
860 (DBusGProxyCallNotify)__bt_pbap_get_vcard_cb,
862 G_TYPE_STRING, vcard_handle,
863 G_TYPE_STRING, target_file,
864 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
867 BT_ERR("GetSize Dbus Call Error");
868 g_hash_table_destroy(filters);
869 g_free(vcard_handle);
870 return BLUETOOTH_ERROR_INTERNAL;
873 g_hash_table_destroy(filters);
874 g_free(vcard_handle);
876 return BLUETOOTH_ERROR_NONE;
881 int __bt_pbap_call_search_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
888 char *order_str = NULL;
891 bt_pbap_search_parameters_t *app_param = pbap_data->app_param;
893 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
894 NULL, (GDestroyNotify)g_free);
896 /* Add Order Filter only if other than Indexed (default)*/
897 if (app_param->order > 0) {
898 order_str = g_strdup(ORDER[app_param->order]);
899 order = g_new0(GValue, 1);
900 g_value_init(order, G_TYPE_STRING);
901 g_value_set_string(order, order_str);
902 g_hash_table_insert(filters, "Order", order);
906 max_count = g_new0(GValue, 1);
907 g_value_init(max_count, G_TYPE_UINT);
908 g_value_set_uint(max_count, app_param->maxlist);
909 g_hash_table_insert(filters, "MaxCount", max_count);
911 /* Add Offset Filter only if other than 0 (default)*/
912 if (app_param->offset > 0) {
913 offset = g_new0(GValue, 1);
914 g_value_init(offset, G_TYPE_UINT);
915 g_value_set_uint(offset, app_param->offset);
916 g_hash_table_insert(filters, "Offset", offset);
919 field = g_strdup(SEARCH_FIELD[app_param->search_attribute]);
920 value = g_strdup(app_param->search_value);
921 if (!dbus_g_proxy_begin_call(proxy, "Search",
922 (DBusGProxyCallNotify)__bt_pbap_search_phonebook_cb,
924 G_TYPE_STRING, field,
925 G_TYPE_STRING, value,
926 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
929 BT_ERR("List Dbus Call Error");
930 g_hash_table_destroy(filters);
933 return BLUETOOTH_ERROR_INTERNAL;
936 g_hash_table_destroy(filters);
940 return BLUETOOTH_ERROR_NONE;
944 int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
945 int source, int type)
948 DBusGProxy *g_pbap_session_proxy = NULL;
949 char address_string[18] = { 0, };
950 char *source_string = NULL;
951 char *type_string = NULL;
952 bt_pbap_data_t *pbap_data = NULL;
954 BT_CHECK_PARAMETER(address, return);
956 /* check if connected */
957 if (g_pbap_session_path == NULL) {
958 BT_ERR("NOT CONNECTED");
959 return BLUETOOTH_ERROR_NOT_CONNECTED;
962 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
963 address->addr[0], address->addr[1],
964 address->addr[2], address->addr[3],
965 address->addr[4], address->addr[5]);
967 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
968 BT_DBG("Address String: %s", address_string);
969 BT_DBG("Session Path = %s\n", g_pbap_session_path);
970 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
971 PBAP_SESSION_SERVICE,
973 PBAP_SESSION_INTERFACE);
974 if (!g_pbap_session_proxy) {
975 BT_ERR("Failed to get a proxy for D-Bus\n");
979 pbap_data = g_new0(bt_pbap_data_t, 1);
980 pbap_data->operation = GET_SIZE;
981 pbap_data->data = g_strdup(address_string);
983 if (source == selected_path.folder && type == selected_path.type) {
984 return __bt_pbap_call_get_phonebook_size(g_pbap_session_proxy, pbap_data);
987 source_string = g_strdup(SOURCE[source]);
988 type_string = g_strdup(TYPE[type]);
990 BT_DBG("Address[%s] Source[%s] Type[%s]",
991 address_string, source_string, type_string);
993 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
994 (DBusGProxyCallNotify)__bt_pbap_select_cb,
996 G_TYPE_STRING, source_string,
997 G_TYPE_STRING, type_string,
999 BT_ERR("Select Dbus Call Error");
1000 g_free(source_string);
1001 g_free(type_string);
1002 g_object_unref(g_pbap_session_proxy);
1003 return BLUETOOTH_ERROR_INTERNAL;
1006 selected_path.folder = source;
1007 selected_path.type = type;
1009 g_free(source_string);
1010 g_free(type_string);
1015 int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
1016 int source, int type, bt_pbap_pull_parameters_t *app_param)
1019 DBusGProxy *g_pbap_session_proxy = NULL;
1020 char address_string[18] = { 0, };
1021 char *source_string = NULL;
1022 char *type_string = NULL;
1024 bt_pbap_data_t *pbap_data = NULL;
1025 bt_pbap_pull_parameters_t *param = NULL;
1027 BT_CHECK_PARAMETER(address, return);
1029 /* check if connected */
1030 if (g_pbap_session_path == NULL) {
1031 BT_ERR("NOT CONNECTED");
1032 return BLUETOOTH_ERROR_NOT_CONNECTED;
1035 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1036 address->addr[0], address->addr[1],
1037 address->addr[2], address->addr[3],
1038 address->addr[4], address->addr[5]);
1040 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1041 BT_DBG("Address String: %s", address_string);
1043 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1044 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1045 PBAP_SESSION_SERVICE,
1046 g_pbap_session_path,
1047 PBAP_SESSION_INTERFACE);
1048 if (!g_pbap_session_proxy) {
1049 BT_ERR("Failed to get a proxy for D-Bus\n");
1053 pbap_data = g_new0(bt_pbap_data_t, 1);
1054 pbap_data->operation = PULL_ALL;
1055 pbap_data->data = g_strdup(address_string);
1056 param = g_new0(bt_pbap_pull_parameters_t, 1);
1057 memcpy(param, app_param, sizeof(bt_pbap_pull_parameters_t));
1058 pbap_data->app_param = param;
1060 if (source == selected_path.folder && type == selected_path.type) {
1061 return __bt_pbap_call_get_phonebook(g_pbap_session_proxy, pbap_data);
1064 source_string = g_strdup(SOURCE[source]);
1065 type_string = g_strdup(TYPE[type]);
1067 BT_DBG("Address[%s] Source[%s] Type[%s]",
1068 address_string, source_string, type_string);
1070 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1071 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1073 G_TYPE_STRING, source_string,
1074 G_TYPE_STRING, type_string,
1076 BT_ERR("Select Dbus Call Error");
1077 g_free(source_string);
1078 g_free(type_string);
1079 g_object_unref(g_pbap_session_proxy);
1080 return BLUETOOTH_ERROR_INTERNAL;
1083 selected_path.folder = source;
1084 selected_path.type = type;
1086 g_free(source_string);
1087 g_free(type_string);
1092 int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
1093 int type, bt_pbap_list_parameters_t *app_param)
1096 DBusGProxy *g_pbap_session_proxy = NULL;
1097 char address_string[18] = { 0, };
1098 char *source_string = NULL;
1099 char *type_string = NULL;
1101 bt_pbap_data_t *pbap_data = NULL;
1102 bt_pbap_list_parameters_t *param = NULL;
1104 BT_CHECK_PARAMETER(address, return);
1106 /* check if connected */
1107 if (g_pbap_session_path == NULL) {
1108 BT_ERR("NOT CONNECTED");
1109 return BLUETOOTH_ERROR_NOT_CONNECTED;
1112 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1113 address->addr[0], address->addr[1],
1114 address->addr[2], address->addr[3],
1115 address->addr[4], address->addr[5]);
1117 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1118 BT_DBG("Address String: %s", address_string);
1120 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1121 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1122 PBAP_SESSION_SERVICE,
1123 g_pbap_session_path,
1124 PBAP_SESSION_INTERFACE);
1125 if (!g_pbap_session_proxy) {
1126 BT_ERR("Failed to get a proxy for D-Bus\n");
1130 pbap_data = g_new0(bt_pbap_data_t, 1);
1131 pbap_data->operation = GET_LIST;
1132 pbap_data->data = g_strdup(address_string);
1133 param = g_new0(bt_pbap_list_parameters_t, 1);
1134 memcpy(param, app_param, sizeof(bt_pbap_list_parameters_t));
1135 pbap_data->app_param = param;
1137 if (source == selected_path.folder && type == selected_path.type) {
1138 return __bt_pbap_call_get_vcards_list(g_pbap_session_proxy, pbap_data);
1141 source_string = g_strdup(SOURCE[source]);
1142 type_string = g_strdup(TYPE[type]);
1144 BT_DBG("Address[%s] Source[%s] Type[%s]",
1145 address_string, source_string, type_string);
1147 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1148 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1150 G_TYPE_STRING, source_string,
1151 G_TYPE_STRING, type_string,
1153 BT_ERR("Select Dbus Call Error");
1154 g_free(source_string);
1155 g_free(type_string);
1156 g_object_unref(g_pbap_session_proxy);
1157 return BLUETOOTH_ERROR_INTERNAL;
1160 selected_path.folder = source;
1161 selected_path.type = type;
1163 g_free(source_string);
1164 g_free(type_string);
1170 int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
1171 int source, int type, bt_pbap_pull_vcard_parameters_t *app_param)
1174 DBusGProxy *g_pbap_session_proxy = NULL;
1175 char address_string[18] = { 0, };
1176 char *source_string = NULL;
1177 char *type_string = NULL;
1178 bt_pbap_data_t *pbap_data = NULL;
1179 bt_pbap_pull_vcard_parameters_t *param = NULL;
1181 BT_CHECK_PARAMETER(address, return);
1183 /* check if connected */
1184 if (g_pbap_session_path == NULL) {
1185 BT_ERR("NOT CONNECTED");
1186 return BLUETOOTH_ERROR_NOT_CONNECTED;
1189 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1190 address->addr[0], address->addr[1],
1191 address->addr[2], address->addr[3],
1192 address->addr[4], address->addr[5]);
1194 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1195 BT_DBG("Address String: %s", address_string);
1197 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1198 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1199 PBAP_SESSION_SERVICE,
1200 g_pbap_session_path,
1201 PBAP_SESSION_INTERFACE);
1202 if (!g_pbap_session_proxy) {
1203 BT_ERR("Failed to get a proxy for D-Bus\n");
1207 pbap_data = g_new0(bt_pbap_data_t, 1);
1208 pbap_data->operation = GET_VCARD;
1209 pbap_data->data = g_strdup(address_string);
1210 param = g_new0(bt_pbap_pull_vcard_parameters_t, 1);
1211 memcpy(param, app_param, sizeof(bt_pbap_pull_vcard_parameters_t));
1212 pbap_data->app_param = param;
1214 if (source == selected_path.folder && type == selected_path.type) {
1215 return __bt_pbap_call_get_vcard(g_pbap_session_proxy, pbap_data);
1218 source_string = g_strdup(SOURCE[source]);
1219 type_string = g_strdup(TYPE[type]);
1221 BT_DBG("Address[%s] Source[%s] Type[%s]",
1222 address_string, source_string, type_string);
1224 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1225 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1227 G_TYPE_STRING, source_string,
1228 G_TYPE_STRING, type_string,
1230 BT_ERR("Select Dbus Call Error");
1231 g_free(source_string);
1232 g_free(type_string);
1233 g_object_unref(g_pbap_session_proxy);
1234 return BLUETOOTH_ERROR_INTERNAL;
1237 selected_path.folder = source;
1238 selected_path.type = type;
1240 g_free(source_string);
1241 g_free(type_string);
1246 int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
1247 int source, int type, bt_pbap_search_parameters_t *app_param)
1250 DBusGProxy *g_pbap_session_proxy = NULL;
1251 char address_string[18] = { 0, };
1252 char *source_string = NULL;
1253 char *type_string = NULL;
1254 bt_pbap_data_t *pbap_data = NULL;
1255 bt_pbap_search_parameters_t *param = NULL;
1257 BT_CHECK_PARAMETER(address, return);
1259 /* check if connected */
1260 if (g_pbap_session_path == NULL) {
1261 BT_ERR("NOT CONNECTED");
1262 return BLUETOOTH_ERROR_NOT_CONNECTED;
1265 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1266 address->addr[0], address->addr[1],
1267 address->addr[2], address->addr[3],
1268 address->addr[4], address->addr[5]);
1270 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1271 BT_DBG("Address String: %s", address_string);
1273 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1274 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1275 PBAP_SESSION_SERVICE,
1276 g_pbap_session_path,
1277 PBAP_SESSION_INTERFACE);
1278 if (!g_pbap_session_proxy) {
1279 BT_ERR("Failed to get a proxy for D-Bus\n");
1283 pbap_data = g_new0(bt_pbap_data_t, 1);
1284 pbap_data->operation = PB_SEARCH;
1285 pbap_data->data = g_strdup(address_string);
1286 param = g_new0(bt_pbap_search_parameters_t, 1);
1287 memcpy(param, app_param, sizeof(bt_pbap_search_parameters_t));
1288 pbap_data->app_param = param;
1290 if (source == selected_path.folder && type == selected_path.type) {
1291 return __bt_pbap_call_search_phonebook(g_pbap_session_proxy, pbap_data);
1294 source_string = g_strdup(SOURCE[source]);
1295 type_string = g_strdup(TYPE[type]);
1297 BT_DBG("Address[%s] Source[%s] Type[%s]",
1298 address_string, source_string, type_string);
1300 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1301 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1303 G_TYPE_STRING, source_string,
1304 G_TYPE_STRING, type_string,
1306 BT_ERR("Select Dbus Call Error");
1307 g_object_unref(g_pbap_session_proxy);
1308 g_free(source_string);
1309 g_free(type_string);
1310 return BLUETOOTH_ERROR_INTERNAL;
1313 selected_path.folder = source;
1314 selected_path.type = type;
1316 g_free(source_string);
1317 g_free(type_string);