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 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
31 #include <syspopup_caller.h>
35 #include "bt-internal-types.h"
36 #include "bt-service-common.h"
37 //#include "bt-service-agent.h"
38 //#include "bt-service-gap-agent.h"
39 //#include "bt-service-adapter.h"
40 #include "bt-service-event.h"
41 //#include "bt-service-rfcomm-server.h"
42 //#include "bt-service-device.h"
43 //#include "bt-service-audio.h"
44 #include "bt-service-pbap.h"
48 #define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb"
49 #define PBAP_OBEX_CLIENT_SERVICE "org.bluez.obex"
50 #define PBAP_OBEX_CLIENT_PATH "/org/bluez/obex"
51 #define PBAP_OBEX_CLIENT_INTERFACE "org.bluez.obex.Client1"
53 #define PBAP_SESSION_SERVICE "org.bluez.obex"
54 #define PBAP_SESSION_INTERFACE "org.bluez.obex.PhonebookAccess1"
55 #define PBAP_VCARDLIST_MAXLENGTH 256
83 PBAP_FIELD_CATEGORIES,
86 PBAP_FIELD_SORT_STRING,
87 PBAP_FIELD_X_IRMC_CALL_DATETIME,
96 "pb", //Phonebook for the saved contacts
97 "ich", //Incoming call history
98 "och", //Outgoing call history
99 "mch", //Missed call history
100 "cch", //Combined Call History cch = ich + och + mch
104 "vcard21", // vCard Format 2.1 (Default)
105 "vcard30", // vCard Format 3.0
109 "indexed", // Index (default)
110 "alphanumeric", // Alphanumeric
111 "phonetic", // Phonetic
114 char *SEARCH_FIELD[] = {
115 "name", // Search by Name(default)
116 "number", // Search by Phone Number
117 "sound", // Search by phonetic sound
120 static char *g_pbap_session_path = NULL;
121 static DBusGConnection *dbus_connection = NULL;
122 static DBusGProxy *g_pbap_proxy = NULL;
127 } selected_path = { -1, -1};
136 } bt_pbap_operation_e;
139 bt_pbap_operation_e operation;
148 bt_pbap_operation_e operation;
149 } bt_pbap_transfer_info_t;
151 static GSList *transfers;
153 int __bt_pbap_call_get_phonebook_size(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
154 int __bt_pbap_call_get_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
155 int __bt_pbap_call_get_vcards_list(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
156 int __bt_pbap_call_get_vcard(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
157 int __bt_pbap_call_search_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data);
159 static void __bt_pbap_free_data(bt_pbap_data_t *pbap_data)
161 g_free(pbap_data->app_param);
162 g_free(pbap_data->data);
166 static bt_pbap_transfer_info_t *__bt_find_transfer_by_path(const char *transfer_path)
169 bt_pbap_transfer_info_t *transfer;
171 retv_if(transfer_path == NULL, NULL);
173 for (l = transfers; l != NULL; l = l->next) {
176 if (transfer == NULL)
179 if (g_strcmp0(transfer->path, transfer_path) == 0)
186 static void __bt_free_transfer_info(bt_pbap_transfer_info_t *transfer_info)
188 ret_if(transfer_info == NULL);
190 g_free(transfer_info->path);
191 g_free(transfer_info->filename);
192 g_free(transfer_info->remote_device);
193 g_free(transfer_info);
196 void _bt_pbap_obex_transfer_completed(const char *transfer_path, gboolean transfer_status)
198 bt_pbap_transfer_info_t *transfer_info;
200 int success = transfer_status;
201 BT_DBG("Transfer [%s] Success [%d] \n", transfer_path, success);
203 result = (success == TRUE) ? BLUETOOTH_ERROR_NONE
204 : BLUETOOTH_ERROR_CANCEL;
206 transfer_info = __bt_find_transfer_by_path(transfer_path);
207 ret_if(transfer_info == NULL);
209 BT_DBG("Remote Device [%s] FileName: [%s] Operation[%d]",
210 transfer_info->remote_device, transfer_info->filename,
211 transfer_info->operation);
213 switch(transfer_info->operation) {
215 _bt_send_event(BT_PBAP_CLIENT_EVENT,
216 BLUETOOTH_PBAP_PHONEBOOK_PULL,
217 DBUS_TYPE_INT32, &result,
218 DBUS_TYPE_STRING, &transfer_info->remote_device,
219 DBUS_TYPE_STRING, &transfer_info->filename,
220 DBUS_TYPE_INT32, &success,
225 _bt_send_event(BT_PBAP_CLIENT_EVENT,
226 BLUETOOTH_PBAP_VCARD_PULL,
227 DBUS_TYPE_INT32, &result,
228 DBUS_TYPE_STRING, &transfer_info->remote_device,
229 DBUS_TYPE_STRING, &transfer_info->filename,
230 DBUS_TYPE_INT32, &success,
235 BT_INFO("Case not handled");
239 transfers = g_slist_remove(transfers, transfer_info);
240 __bt_free_transfer_info(transfer_info);
243 void __bt_pbap_connect_cb(DBusGProxy *proxy,
244 DBusGProxyCall *call, void *user_data)
246 char *session_path = NULL;
247 char *address_string = user_data;
248 GError *g_error = NULL;
250 int result = BLUETOOTH_ERROR_CANCEL;
252 BT_DBG("Address = %s", address_string);
253 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
254 DBUS_TYPE_G_OBJECT_PATH, &session_path,
256 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
257 g_error_free(g_error);
259 g_pbap_session_path = g_strdup(session_path);
260 BT_DBG("Session Path = %s\n", g_pbap_session_path);
261 result = BLUETOOTH_ERROR_NONE;
265 _bt_send_event(BT_PBAP_CLIENT_EVENT,
266 BLUETOOTH_PBAP_CONNECTED,
267 DBUS_TYPE_INT32, &result,
268 DBUS_TYPE_STRING, &address_string,
269 DBUS_TYPE_INT32, &connected,
272 g_free(address_string);
273 g_free(session_path);
277 int _bt_pbap_connect(const bluetooth_device_address_t *address)
282 GError *error = NULL;
283 char address_string[18] = { 0, };
286 BT_CHECK_PARAMETER(address, return);
288 /* check if already connected */
289 if (g_pbap_session_path)
290 return BLUETOOTH_ERROR_ALREADY_CONNECT;
292 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
293 address->addr[0], address->addr[1],
294 address->addr[2], address->addr[3],
295 address->addr[4], address->addr[5]);
297 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
298 BT_DBG("Address String: %s", address_string);
299 dbus_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
301 BT_ERR("Couldn't connect to system bus[%s]\n", error->message);
306 g_pbap_proxy = dbus_g_proxy_new_for_name(dbus_connection,
307 PBAP_OBEX_CLIENT_SERVICE,
308 PBAP_OBEX_CLIENT_PATH,
309 PBAP_OBEX_CLIENT_INTERFACE);
311 BT_ERR("Failed to get a proxy for D-Bus\n");
315 hash = g_hash_table_new_full(g_str_hash, g_str_equal,
316 NULL, (GDestroyNotify)g_free);
318 tgt_value = g_new0(GValue, 1);
319 g_value_init(tgt_value, G_TYPE_STRING);
320 g_value_set_string(tgt_value, "pbap");
321 g_hash_table_insert(hash, "Target", tgt_value);
324 ptr = g_strdup(address_string);
325 if (!dbus_g_proxy_begin_call(g_pbap_proxy, "CreateSession",
326 (DBusGProxyCallNotify)__bt_pbap_connect_cb,
329 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
330 hash, G_TYPE_INVALID)) {
331 BT_ERR("Connect Dbus Call Error");
333 g_object_unref(g_pbap_proxy);
334 g_hash_table_destroy(hash);
335 return BLUETOOTH_ERROR_INTERNAL;
338 g_hash_table_destroy(hash);
344 void __bt_pbap_disconnect_cb(DBusGProxy *proxy,
345 DBusGProxyCall *call, void *user_data)
347 char *address_string = user_data;
348 GError *g_error = NULL;
350 int result = BLUETOOTH_ERROR_INTERNAL ;
352 BT_DBG("Address = %s", address_string);
353 if (!dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID)) {
354 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
355 g_error_free(g_error);
357 g_free(g_pbap_session_path);
358 g_pbap_session_path = NULL;
359 result = BLUETOOTH_ERROR_NONE;
360 selected_path.folder = -1;
361 selected_path.type = -1;
365 g_object_unref(proxy);
366 _bt_send_event(BT_PBAP_CLIENT_EVENT,
367 BLUETOOTH_PBAP_CONNECTED,
368 DBUS_TYPE_INT32, &result,
369 DBUS_TYPE_STRING, &address_string,
370 DBUS_TYPE_INT32, &connected,
373 g_free(address_string);
377 int _bt_pbap_disconnect(const bluetooth_device_address_t *address)
380 char address_string[18] = { 0, };
382 BT_CHECK_PARAMETER(address, return);
384 /* check if connected */
385 if (g_pbap_session_path == NULL)
386 return BLUETOOTH_ERROR_NOT_CONNECTED;
388 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
389 address->addr[0], address->addr[1],
390 address->addr[2], address->addr[3],
391 address->addr[4], address->addr[5]);
393 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
394 BT_DBG("Address String: %s", address_string);
395 BT_DBG("Session Path: %s", g_pbap_session_path);
397 ptr = g_strdup(address_string);
398 if (!dbus_g_proxy_begin_call(g_pbap_proxy, "RemoveSession",
399 (DBusGProxyCallNotify)__bt_pbap_disconnect_cb,
401 DBUS_TYPE_G_OBJECT_PATH, g_pbap_session_path,
404 BT_ERR("Disconnect Dbus Call Error");
405 return BLUETOOTH_ERROR_INTERNAL;
411 void __bt_pbap_select_cb(DBusGProxy *proxy,
412 DBusGProxyCall *call, void *user_data)
415 GError *g_error = NULL;
416 bt_pbap_data_t *pbap_data = user_data;
417 char *address_string = pbap_data->data;
419 BT_DBG("Address = %s", address_string);
420 if (dbus_g_proxy_end_call(proxy, call, &g_error, G_TYPE_INVALID)) {
421 switch (pbap_data->operation) {
423 __bt_pbap_call_get_phonebook_size(proxy, pbap_data);
427 __bt_pbap_call_get_phonebook(proxy, pbap_data);
431 __bt_pbap_call_get_vcards_list(proxy, pbap_data);
435 __bt_pbap_call_get_vcard(proxy, pbap_data);
439 __bt_pbap_call_search_phonebook(proxy, pbap_data);
443 g_object_unref(proxy);
444 __bt_pbap_free_data(pbap_data);
448 g_object_unref(proxy);
449 __bt_pbap_free_data(pbap_data);
456 void __bt_pbap_get_phonebook_size_cb(DBusGProxy *proxy,
457 DBusGProxyCall *call, void *user_data)
460 GError *g_error = NULL;
461 int result = BLUETOOTH_ERROR_INTERNAL;
462 bt_pbap_data_t *pbap_data = user_data;
463 char *address_string = pbap_data->data;
464 unsigned int size = 0;
466 BT_DBG("Address = %s", address_string);
467 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
470 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
471 g_error_free(g_error);
474 result = BLUETOOTH_ERROR_NONE;
476 BT_DBG("Size of Phonebook: %d", size);
477 _bt_send_event(BT_PBAP_CLIENT_EVENT,
478 BLUETOOTH_PBAP_PHONEBOOK_SIZE,
479 DBUS_TYPE_INT32, &result,
480 DBUS_TYPE_STRING, &address_string,
481 DBUS_TYPE_INT32, &size,
483 g_object_unref(proxy);
484 __bt_pbap_free_data(pbap_data);
488 void __bt_pbap_get_phonebook_cb(DBusGProxy *proxy,
489 DBusGProxyCall *call, void *user_data)
492 GError *g_error = NULL;
493 bt_pbap_data_t *pbap_data = user_data;
494 char *address_string = pbap_data->data;
495 GHashTable *properties;
496 GValue *value = { 0 };
497 bt_pbap_transfer_info_t *transfer_info;
498 char *transfer = NULL;
499 const gchar *filename = NULL;
501 BT_DBG("Address = %s", address_string);
502 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
503 DBUS_TYPE_G_OBJECT_PATH, &transfer,
504 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
507 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
508 g_error_free(g_error);
510 if (properties != NULL) {
511 value = g_hash_table_lookup(properties, "Filename");
512 filename = value ? g_value_get_string(value) : NULL;
515 BT_DBG("Transfer Path: %s", transfer);
516 BT_DBG("File Name: %s", filename);
517 transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
518 transfer_info->path = transfer;
519 transfer_info->remote_device = g_strdup(address_string);
520 transfer_info->filename = (char *)filename;
521 transfer_info->operation = PULL_ALL;
522 transfers = g_slist_append(transfers, transfer_info);
525 g_object_unref(proxy);
526 __bt_pbap_free_data(pbap_data);
530 void __bt_pbap_get_vcard_list_cb(DBusGProxy *proxy,
531 DBusGProxyCall *call, void *user_data)
534 GError *g_error = NULL;
536 int result = BLUETOOTH_ERROR_INTERNAL;
537 GPtrArray *vcardlist = NULL;
538 bt_pbap_data_t *pbap_data = user_data;
539 char *address_string = pbap_data->data;
540 char **vcard_list = NULL;
541 char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
544 BT_DBG("Address = %s", address_string);
545 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
546 dbus_g_type_get_collection("GPtrArray", dbus_g_type_get_struct("GValueArray",
547 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID)),
548 &vcardlist, G_TYPE_INVALID)) {
549 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
550 g_error_free(g_error);
551 vcard_list = g_new0(char *, length + 1);
553 BT_DBG("vcardlist len %d", vcardlist->len);
554 length = vcardlist->len;
555 result = BLUETOOTH_ERROR_NONE;
557 vcard_list = g_new0(char *, length + 1);
559 GValue *v = g_new0(GValue, 1);//g_ptr_array_index(vcardlist, 0);
560 gchar *elname, *elval;
561 g_value_init(v, dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID));
562 for (i = 0; i < length; i++) {
563 g_value_set_boxed(v, g_ptr_array_index(vcardlist, i));
564 if (dbus_g_type_struct_get (v, 0, &elname, 1, &elval, G_MAXUINT)) {
565 memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
566 g_snprintf (list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
567 "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
568 //If possible send as Array of <STRING, STRING>
569 BT_DBG("%s", list_entry);
570 vcard_list[i] = g_strdup(list_entry);
575 _bt_send_event(BT_PBAP_CLIENT_EVENT,
576 BLUETOOTH_PBAP_VCARD_LIST,
577 DBUS_TYPE_INT32, &result,
578 DBUS_TYPE_STRING, &address_string,
579 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
583 g_object_unref(proxy);
584 __bt_pbap_free_data(pbap_data);
588 void __bt_pbap_get_vcard_cb(DBusGProxy *proxy,
589 DBusGProxyCall *call, void *user_data)
592 GError *g_error = NULL;
593 bt_pbap_data_t *pbap_data = user_data;
594 char *address_string = pbap_data->data;
595 GHashTable *properties;
596 GValue *value = { 0 };
597 bt_pbap_transfer_info_t *transfer_info;
598 char *transfer = NULL;
599 const gchar *filename = NULL;
601 BT_DBG("Address = %s", address_string);
602 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
603 DBUS_TYPE_G_OBJECT_PATH, &transfer,
604 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
607 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
608 g_error_free(g_error);
610 if (properties != NULL) {
611 value = g_hash_table_lookup(properties, "Filename");
612 filename = value ? g_value_get_string(value) : NULL;
615 BT_DBG("Transfer Path: %s", transfer);
616 BT_DBG("File Name: %s", filename);
617 transfer_info = g_new0(bt_pbap_transfer_info_t, 1);
618 transfer_info->path = transfer;
619 transfer_info->remote_device = g_strdup(address_string);
620 transfer_info->filename = (char *)filename;
621 transfer_info->operation = GET_VCARD;
622 transfers = g_slist_append(transfers, transfer_info);
625 g_object_unref(proxy);
626 __bt_pbap_free_data(pbap_data);
630 void __bt_pbap_search_phonebook_cb(DBusGProxy *proxy,
631 DBusGProxyCall *call, void *user_data)
634 GError *g_error = NULL;
636 GPtrArray *vcardlist = NULL;
637 bt_pbap_data_t *pbap_data = user_data;
638 char *address_string = pbap_data->data;
639 char **vcard_list = NULL;
640 char list_entry[PBAP_VCARDLIST_MAXLENGTH] = { 0, };
642 int result = BLUETOOTH_ERROR_INTERNAL;
644 BT_DBG("Address = %s", address_string);
645 if (!dbus_g_proxy_end_call(proxy, call, &g_error,
646 dbus_g_type_get_collection("GPtrArray", dbus_g_type_get_struct("GValueArray",
647 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID)),
648 &vcardlist, G_TYPE_INVALID)) {
649 BT_ERR("Error Code[%d]: Message %s \n", g_error->code, g_error->message);
650 g_error_free(g_error);
652 BT_DBG("vcardlist len %d", vcardlist->len);
653 length = vcardlist->len;
654 result = BLUETOOTH_ERROR_NONE;
656 vcard_list = g_new0(char *, length + 1);
658 GValue *v = g_new0(GValue, 1);//g_ptr_array_index(vcardlist, 0);
659 gchar *elname, *elval;
660 g_value_init(v, dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID));
661 for (i = 0; i < length; i++) {
662 g_value_set_boxed(v, g_ptr_array_index(vcardlist, i));
663 if (dbus_g_type_struct_get (v, 0, &elname, 1, &elval, G_MAXUINT)) {
664 memset(list_entry, 0, PBAP_VCARDLIST_MAXLENGTH);
665 g_snprintf (list_entry, PBAP_VCARDLIST_MAXLENGTH - 1,
666 "<card handle = \"%s\" name = \"%s\"/>", elname, elval);
667 //If possible send as Array of <STRING, STRING>
668 BT_DBG("%s", list_entry);
669 vcard_list[i] = g_strdup(list_entry);
674 _bt_send_event(BT_PBAP_CLIENT_EVENT,
675 BLUETOOTH_PBAP_PHONEBOOK_SEARCH,
676 DBUS_TYPE_INT32, &result,
677 DBUS_TYPE_STRING, &address_string,
678 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
681 g_object_unref(proxy);
682 __bt_pbap_free_data(pbap_data);
686 int __bt_pbap_call_get_phonebook_size(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
689 if (!dbus_g_proxy_begin_call(proxy, "GetSize",
690 (DBusGProxyCallNotify)__bt_pbap_get_phonebook_size_cb,
693 BT_ERR("GetSize Dbus Call Error");
694 __bt_pbap_free_data(pbap_data);
695 return BLUETOOTH_ERROR_INTERNAL;
698 return BLUETOOTH_ERROR_NONE;
702 int __bt_pbap_call_get_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
710 char *format_str = NULL;
711 char *order_str = NULL;
712 char *target_file = "/opt/usr/media/Downloads/pb.vcf";
713 bt_pbap_pull_parameters_t *app_param = pbap_data->app_param;
715 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
716 NULL, (GDestroyNotify)g_free);
718 /* Add Format Filter only if other than vCard 2.1 (default)*/
719 if (app_param->format > 0) {
720 format_str = g_strdup(FORMAT[app_param->format]);
721 format = g_new0(GValue, 1);
722 g_value_init(format, G_TYPE_STRING);
723 g_value_set_string(format, format_str);
724 g_hash_table_insert(filters, "Format", format);
728 /* Add Order Filter only if other than Indexed (default)*/
729 if (app_param->order > 0) {
730 order_str = g_strdup(ORDER[app_param->order]);
731 order = g_new0(GValue, 1);
732 g_value_init(order, G_TYPE_STRING);
733 g_value_set_string(order, order_str);
734 g_hash_table_insert(filters, "Order", order);
738 max_count = g_new0(GValue, 1);
739 g_value_init(max_count, G_TYPE_UINT);
740 g_value_set_uint(max_count, app_param->maxlist);
741 g_hash_table_insert(filters, "MaxCount", max_count);
743 /* Add Offset Filter only if other than 0 (default)*/
744 if (app_param->offset > 0) {
745 offset = g_new0(GValue, 1);
746 g_value_init(offset, G_TYPE_UINT);
747 g_value_set_uint(offset, app_param->offset);
748 g_hash_table_insert(filters, "Offset", offset);
751 //****************************
752 // Add code for Fields
754 //****************************
756 if (!dbus_g_proxy_begin_call(proxy, "PullAll",
757 (DBusGProxyCallNotify)__bt_pbap_get_phonebook_cb,
759 G_TYPE_STRING, target_file,
760 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
763 BT_ERR("GetSize Dbus Call Error");
764 g_hash_table_destroy(filters);
765 return BLUETOOTH_ERROR_INTERNAL;
767 g_hash_table_destroy(filters);
769 return BLUETOOTH_ERROR_NONE;
773 int __bt_pbap_call_get_vcards_list(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
780 char *order_str = NULL;
781 bt_pbap_list_parameters_t *app_param = pbap_data->app_param;
783 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
784 NULL, (GDestroyNotify)g_free);
786 /* Add Order Filter only if other than Indexed (default)*/
787 if (app_param->order > 0) {
788 order_str = g_strdup(ORDER[app_param->order]);
789 order = g_new0(GValue, 1);
790 g_value_init(order, G_TYPE_STRING);
791 g_value_set_string(order, order_str);
792 g_hash_table_insert(filters, "Order", order);
796 max_count = g_new0(GValue, 1);
797 g_value_init(max_count, G_TYPE_UINT);
798 g_value_set_uint(max_count, app_param->maxlist);
799 g_hash_table_insert(filters, "MaxCount", max_count);
801 /* Add Offset Filter only if other than 0 (default)*/
802 if (app_param->offset > 0) {
803 offset = g_new0(GValue, 1);
804 g_value_init(offset, G_TYPE_UINT);
805 g_value_set_uint(offset, app_param->offset);
806 g_hash_table_insert(filters, "Offset", offset);
809 if (!dbus_g_proxy_begin_call(proxy, "List",
810 (DBusGProxyCallNotify)__bt_pbap_get_vcard_list_cb,
812 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
815 BT_ERR("List Dbus Call Error");
816 g_hash_table_destroy(filters);
817 return BLUETOOTH_ERROR_INTERNAL;
820 g_hash_table_destroy(filters);
822 return BLUETOOTH_ERROR_NONE;
826 int __bt_pbap_call_get_vcard(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
831 char *format_str = NULL;
832 char *target_file = "/opt/usr/media/Downloads/pb.vcf";
833 char *vcard_handle = NULL;
834 char vcard[10] = { 0, };
836 bt_pbap_pull_vcard_parameters_t *app_param = pbap_data->app_param;
838 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
839 NULL, (GDestroyNotify)g_free);
841 /* Add Format Filter only if other than vCard 2.1 (default)*/
842 if (app_param->format > 0) {
843 format_str = g_strdup(FORMAT[app_param->format]);
844 format = g_new0(GValue, 1);
845 g_value_init(format, G_TYPE_STRING);
846 g_value_set_string(format, format_str);
847 g_hash_table_insert(filters, "Format", format);
852 //****************************
853 // Add code for Fields
855 //****************************
857 sprintf(vcard, "%d.vcf", app_param->index);
858 BT_DBG("Handle: %s", vcard);
859 vcard_handle = g_strdup(vcard);
861 if (!dbus_g_proxy_begin_call(proxy, "Pull",
862 (DBusGProxyCallNotify)__bt_pbap_get_vcard_cb,
864 G_TYPE_STRING, vcard_handle,
865 G_TYPE_STRING, target_file,
866 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
869 BT_ERR("GetSize Dbus Call Error");
870 g_hash_table_destroy(filters);
871 g_free(vcard_handle);
872 return BLUETOOTH_ERROR_INTERNAL;
875 g_hash_table_destroy(filters);
876 g_free(vcard_handle);
878 return BLUETOOTH_ERROR_NONE;
883 int __bt_pbap_call_search_phonebook(DBusGProxy *proxy, bt_pbap_data_t *pbap_data)
890 char *order_str = NULL;
893 bt_pbap_search_parameters_t *app_param = pbap_data->app_param;
895 filters = g_hash_table_new_full(g_str_hash, g_str_equal,
896 NULL, (GDestroyNotify)g_free);
898 /* Add Order Filter only if other than Indexed (default)*/
899 if (app_param->order > 0) {
900 order_str = g_strdup(ORDER[app_param->order]);
901 order = g_new0(GValue, 1);
902 g_value_init(order, G_TYPE_STRING);
903 g_value_set_string(order, order_str);
904 g_hash_table_insert(filters, "Order", order);
908 max_count = g_new0(GValue, 1);
909 g_value_init(max_count, G_TYPE_UINT);
910 g_value_set_uint(max_count, app_param->maxlist);
911 g_hash_table_insert(filters, "MaxCount", max_count);
913 /* Add Offset Filter only if other than 0 (default)*/
914 if (app_param->offset > 0) {
915 offset = g_new0(GValue, 1);
916 g_value_init(offset, G_TYPE_UINT);
917 g_value_set_uint(offset, app_param->offset);
918 g_hash_table_insert(filters, "Offset", offset);
921 field = g_strdup(SEARCH_FIELD[app_param->search_attribute]);
922 value = g_strdup(app_param->search_value);
923 if (!dbus_g_proxy_begin_call(proxy, "Search",
924 (DBusGProxyCallNotify)__bt_pbap_search_phonebook_cb,
926 G_TYPE_STRING, field,
927 G_TYPE_STRING, value,
928 dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
931 BT_ERR("List Dbus Call Error");
932 g_hash_table_destroy(filters);
935 return BLUETOOTH_ERROR_INTERNAL;
938 g_hash_table_destroy(filters);
942 return BLUETOOTH_ERROR_NONE;
946 int _bt_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
947 int source, int type)
950 DBusGProxy *g_pbap_session_proxy = NULL;
951 char address_string[18] = { 0, };
952 char *source_string = NULL;
953 char *type_string = NULL;
954 bt_pbap_data_t *pbap_data = NULL;
956 BT_CHECK_PARAMETER(address, return);
958 /* check if connected */
959 if (g_pbap_session_path == NULL) {
960 BT_ERR("NOT CONNECTED");
961 return BLUETOOTH_ERROR_NOT_CONNECTED;
964 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
965 address->addr[0], address->addr[1],
966 address->addr[2], address->addr[3],
967 address->addr[4], address->addr[5]);
969 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
970 BT_DBG("Address String: %s", address_string);
971 BT_DBG("Session Path = %s\n", g_pbap_session_path);
972 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
973 PBAP_SESSION_SERVICE,
975 PBAP_SESSION_INTERFACE);
976 if (!g_pbap_session_proxy) {
977 BT_ERR("Failed to get a proxy for D-Bus\n");
981 pbap_data = g_new0(bt_pbap_data_t, 1);
982 pbap_data->operation = GET_SIZE;
983 pbap_data->data = g_strdup(address_string);
985 if (source == selected_path.folder && type == selected_path.type) {
986 return __bt_pbap_call_get_phonebook_size(g_pbap_session_proxy, pbap_data);
989 source_string = g_strdup(SOURCE[source]);
990 type_string = g_strdup(TYPE[type]);
992 BT_DBG("Address[%s] Source[%s] Type[%s]",
993 address_string, source_string, type_string);
995 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
996 (DBusGProxyCallNotify)__bt_pbap_select_cb,
998 G_TYPE_STRING, source_string,
999 G_TYPE_STRING, type_string,
1001 BT_ERR("Select Dbus Call Error");
1002 g_free(source_string);
1003 g_free(type_string);
1004 g_object_unref(g_pbap_session_proxy);
1005 return BLUETOOTH_ERROR_INTERNAL;
1008 selected_path.folder = source;
1009 selected_path.type = type;
1011 g_free(source_string);
1012 g_free(type_string);
1017 int _bt_pbap_get_phonebook(const bluetooth_device_address_t *address,
1018 int source, int type, bt_pbap_pull_parameters_t *app_param)
1021 DBusGProxy *g_pbap_session_proxy = NULL;
1022 char address_string[18] = { 0, };
1023 char *source_string = NULL;
1024 char *type_string = NULL;
1026 bt_pbap_data_t *pbap_data = NULL;
1027 bt_pbap_pull_parameters_t *param = NULL;
1029 BT_CHECK_PARAMETER(address, return);
1031 /* check if connected */
1032 if (g_pbap_session_path == NULL) {
1033 BT_ERR("NOT CONNECTED");
1034 return BLUETOOTH_ERROR_NOT_CONNECTED;
1037 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1038 address->addr[0], address->addr[1],
1039 address->addr[2], address->addr[3],
1040 address->addr[4], address->addr[5]);
1042 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1043 BT_DBG("Address String: %s", address_string);
1045 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1046 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1047 PBAP_SESSION_SERVICE,
1048 g_pbap_session_path,
1049 PBAP_SESSION_INTERFACE);
1050 if (!g_pbap_session_proxy) {
1051 BT_ERR("Failed to get a proxy for D-Bus\n");
1055 pbap_data = g_new0(bt_pbap_data_t, 1);
1056 pbap_data->operation = PULL_ALL;
1057 pbap_data->data = g_strdup(address_string);
1058 param = g_new0(bt_pbap_pull_parameters_t, 1);
1059 memcpy(param, app_param, sizeof(bt_pbap_pull_parameters_t));
1060 pbap_data->app_param = param;
1062 if (source == selected_path.folder && type == selected_path.type) {
1063 return __bt_pbap_call_get_phonebook(g_pbap_session_proxy, pbap_data);
1066 source_string = g_strdup(SOURCE[source]);
1067 type_string = g_strdup(TYPE[type]);
1069 BT_DBG("Address[%s] Source[%s] Type[%s]",
1070 address_string, source_string, type_string);
1072 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1073 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1075 G_TYPE_STRING, source_string,
1076 G_TYPE_STRING, type_string,
1078 BT_ERR("Select Dbus Call Error");
1079 g_free(source_string);
1080 g_free(type_string);
1081 g_object_unref(g_pbap_session_proxy);
1082 return BLUETOOTH_ERROR_INTERNAL;
1085 selected_path.folder = source;
1086 selected_path.type = type;
1088 g_free(source_string);
1089 g_free(type_string);
1094 int _bt_pbap_get_list(const bluetooth_device_address_t *address, int source,
1095 int type, bt_pbap_list_parameters_t *app_param)
1098 DBusGProxy *g_pbap_session_proxy = NULL;
1099 char address_string[18] = { 0, };
1100 char *source_string = NULL;
1101 char *type_string = NULL;
1103 bt_pbap_data_t *pbap_data = NULL;
1104 bt_pbap_list_parameters_t *param = NULL;
1106 BT_CHECK_PARAMETER(address, return);
1108 /* check if connected */
1109 if (g_pbap_session_path == NULL) {
1110 BT_ERR("NOT CONNECTED");
1111 return BLUETOOTH_ERROR_NOT_CONNECTED;
1114 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1115 address->addr[0], address->addr[1],
1116 address->addr[2], address->addr[3],
1117 address->addr[4], address->addr[5]);
1119 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1120 BT_DBG("Address String: %s", address_string);
1122 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1123 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1124 PBAP_SESSION_SERVICE,
1125 g_pbap_session_path,
1126 PBAP_SESSION_INTERFACE);
1127 if (!g_pbap_session_proxy) {
1128 BT_ERR("Failed to get a proxy for D-Bus\n");
1132 pbap_data = g_new0(bt_pbap_data_t, 1);
1133 pbap_data->operation = GET_LIST;
1134 pbap_data->data = g_strdup(address_string);
1135 param = g_new0(bt_pbap_list_parameters_t, 1);
1136 memcpy(param, app_param, sizeof(bt_pbap_list_parameters_t));
1137 pbap_data->app_param = param;
1139 if (source == selected_path.folder && type == selected_path.type) {
1140 return __bt_pbap_call_get_vcards_list(g_pbap_session_proxy, pbap_data);
1143 source_string = g_strdup(SOURCE[source]);
1144 type_string = g_strdup(TYPE[type]);
1146 BT_DBG("Address[%s] Source[%s] Type[%s]",
1147 address_string, source_string, type_string);
1149 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1150 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1152 G_TYPE_STRING, source_string,
1153 G_TYPE_STRING, type_string,
1155 BT_ERR("Select Dbus Call Error");
1156 g_free(source_string);
1157 g_free(type_string);
1158 g_object_unref(g_pbap_session_proxy);
1159 return BLUETOOTH_ERROR_INTERNAL;
1162 selected_path.folder = source;
1163 selected_path.type = type;
1165 g_free(source_string);
1166 g_free(type_string);
1172 int _bt_pbap_pull_vcard(const bluetooth_device_address_t *address,
1173 int source, int type, bt_pbap_pull_vcard_parameters_t *app_param)
1176 DBusGProxy *g_pbap_session_proxy = NULL;
1177 char address_string[18] = { 0, };
1178 char *source_string = NULL;
1179 char *type_string = NULL;
1180 bt_pbap_data_t *pbap_data = NULL;
1181 bt_pbap_pull_vcard_parameters_t *param = NULL;
1183 BT_CHECK_PARAMETER(address, return);
1185 /* check if connected */
1186 if (g_pbap_session_path == NULL) {
1187 BT_ERR("NOT CONNECTED");
1188 return BLUETOOTH_ERROR_NOT_CONNECTED;
1191 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1192 address->addr[0], address->addr[1],
1193 address->addr[2], address->addr[3],
1194 address->addr[4], address->addr[5]);
1196 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1197 BT_DBG("Address String: %s", address_string);
1199 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1200 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1201 PBAP_SESSION_SERVICE,
1202 g_pbap_session_path,
1203 PBAP_SESSION_INTERFACE);
1204 if (!g_pbap_session_proxy) {
1205 BT_ERR("Failed to get a proxy for D-Bus\n");
1209 pbap_data = g_new0(bt_pbap_data_t, 1);
1210 pbap_data->operation = GET_VCARD;
1211 pbap_data->data = g_strdup(address_string);
1212 param = g_new0(bt_pbap_pull_vcard_parameters_t, 1);
1213 memcpy(param, app_param, sizeof(bt_pbap_pull_vcard_parameters_t));
1214 pbap_data->app_param = param;
1216 if (source == selected_path.folder && type == selected_path.type) {
1217 return __bt_pbap_call_get_vcard(g_pbap_session_proxy, pbap_data);
1220 source_string = g_strdup(SOURCE[source]);
1221 type_string = g_strdup(TYPE[type]);
1223 BT_DBG("Address[%s] Source[%s] Type[%s]",
1224 address_string, source_string, type_string);
1226 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1227 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1229 G_TYPE_STRING, source_string,
1230 G_TYPE_STRING, type_string,
1232 BT_ERR("Select Dbus Call Error");
1233 g_free(source_string);
1234 g_free(type_string);
1235 g_object_unref(g_pbap_session_proxy);
1236 return BLUETOOTH_ERROR_INTERNAL;
1239 selected_path.folder = source;
1240 selected_path.type = type;
1242 g_free(source_string);
1243 g_free(type_string);
1248 int _bt_pbap_phonebook_search(const bluetooth_device_address_t *address,
1249 int source, int type, bt_pbap_search_parameters_t *app_param)
1252 DBusGProxy *g_pbap_session_proxy = NULL;
1253 char address_string[18] = { 0, };
1254 char *source_string = NULL;
1255 char *type_string = NULL;
1256 bt_pbap_data_t *pbap_data = NULL;
1257 bt_pbap_search_parameters_t *param = NULL;
1259 BT_CHECK_PARAMETER(address, return);
1261 /* check if connected */
1262 if (g_pbap_session_path == NULL) {
1263 BT_ERR("NOT CONNECTED");
1264 return BLUETOOTH_ERROR_NOT_CONNECTED;
1267 BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X]",
1268 address->addr[0], address->addr[1],
1269 address->addr[2], address->addr[3],
1270 address->addr[4], address->addr[5]);
1272 _bt_convert_addr_type_to_string(address_string, (unsigned char *)address->addr);
1273 BT_DBG("Address String: %s", address_string);
1275 BT_DBG("Session Path = %s\n", g_pbap_session_path);
1276 g_pbap_session_proxy = dbus_g_proxy_new_for_name(dbus_connection,
1277 PBAP_SESSION_SERVICE,
1278 g_pbap_session_path,
1279 PBAP_SESSION_INTERFACE);
1280 if (!g_pbap_session_proxy) {
1281 BT_ERR("Failed to get a proxy for D-Bus\n");
1285 pbap_data = g_new0(bt_pbap_data_t, 1);
1286 pbap_data->operation = PB_SEARCH;
1287 pbap_data->data = g_strdup(address_string);
1288 param = g_new0(bt_pbap_search_parameters_t, 1);
1289 memcpy(param, app_param, sizeof(bt_pbap_search_parameters_t));
1290 pbap_data->app_param = param;
1292 if (source == selected_path.folder && type == selected_path.type) {
1293 return __bt_pbap_call_search_phonebook(g_pbap_session_proxy, pbap_data);
1296 source_string = g_strdup(SOURCE[source]);
1297 type_string = g_strdup(TYPE[type]);
1299 BT_DBG("Address[%s] Source[%s] Type[%s]",
1300 address_string, source_string, type_string);
1302 if (!dbus_g_proxy_begin_call(g_pbap_session_proxy, "Select",
1303 (DBusGProxyCallNotify)__bt_pbap_select_cb,
1305 G_TYPE_STRING, source_string,
1306 G_TYPE_STRING, type_string,
1308 BT_ERR("Select Dbus Call Error");
1309 g_object_unref(g_pbap_session_proxy);
1310 g_free(source_string);
1311 g_free(type_string);
1312 return BLUETOOTH_ERROR_INTERNAL;
1315 selected_path.folder = source;
1316 selected_path.type = type;
1318 g_free(source_string);
1319 g_free(type_string);