4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
28 #include <vconf-keys.h>
30 #include "bt-internal-types.h"
31 #include "bt-service-common.h"
32 #include "bt-service-agent.h"
33 #include "bt-service-gap-agent.h"
34 #include "bt-service-adapter.h"
35 #include "bt-service-device.h"
37 static DBusGConnection *connection = NULL;
40 GAP_AGENT_EXEC_NO_OPERATION,
41 GAP_AGENT_EXEC_PAIRING,
42 GAP_AGENT_EXEC_AUTHORZATION,
43 GAP_AGENT_EXEC_CONFIRM_MODE,
46 typedef struct _GapAgentPrivate GapAgentPrivate;
48 struct _GapAgentPrivate {
53 DBusGProxy *agent_manager;
55 DBusGProxy *dbus_proxy;
57 GapAgentExecType exec_type;
58 DBusGMethodInvocation *reply_context;
60 char pairing_addr[18];
61 char authorize_addr[18];
69 G_DEFINE_TYPE(GapAgent, gap_agent, G_TYPE_OBJECT);
71 static gboolean gap_agent_request_pin_code(GapAgent *agent,
73 DBusGMethodInvocation *context);
75 static gboolean gap_agent_request_passkey(GapAgent *agent, const char *path,
76 DBusGMethodInvocation *context);
78 static gboolean gap_agent_display_passkey(GapAgent *agent, const char *path,
79 guint passkey, guint16 entered,
80 DBusGMethodInvocation *context);
82 static gboolean gap_agent_request_confirmation(GapAgent *agent,
85 DBusGMethodInvocation *context);
87 static gboolean gap_agent_authorize_service(GapAgent *agent, const char *path,
89 DBusGMethodInvocation *context);
91 static gboolean gap_agent_request_authorization(GapAgent *agent,
93 DBusGMethodInvocation *context);
95 static gboolean gap_agent_cancel(GapAgent *agent,
96 DBusGMethodInvocation *context);
98 static gboolean gap_agent_release(GapAgent *agent,
99 DBusGMethodInvocation *context);
101 static gboolean gap_agent_confirm_mode_change(GapAgent *agent,
103 DBusGMethodInvocation *context);
105 static gboolean gap_agent_get_discoverable_timeout(GapAgent *agent,
106 DBusGMethodInvocation *context);
108 #include "bt-gap-agent-method.h"
111 GAP_AGENT_ERROR_REJECT,
112 GAP_AGENT_ERROR_CANCEL,
113 GAP_AGENT_ERROR_TIMEOUT,
116 #define GAP_AGENT_ERROR (gap_agent_error_quark())
118 static GQuark gap_agent_error_quark(void)
120 static GQuark quark = 0;
122 quark = g_quark_from_static_string("agent");
127 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
129 static GError *gap_agent_error(GapAgentError error, const char *err_msg)
131 return g_error_new(GAP_AGENT_ERROR, error, err_msg, NULL);
134 static void gap_agent_init(GapAgent *agent)
136 BT_DBG("agent %p", agent);
139 static void gap_agent_finalize(GObject *agent)
141 BT_DBG("Free agent %p", agent);
143 G_OBJECT_CLASS(gap_agent_parent_class)->finalize(agent);
146 static void gap_agent_class_init(GapAgentClass *klass)
148 GObjectClass *object_class = (GObjectClass *) klass;
149 GError *error = NULL;
151 BT_DBG("class %p", klass);
153 g_type_class_add_private(klass, sizeof(GapAgentPrivate));
155 object_class->finalize = gap_agent_finalize;
157 connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
160 g_printerr("Connecting to system bus failed: %s",
165 dbus_g_object_type_install_info(GAP_TYPE_AGENT,
166 &dbus_glib_gap_agent_object_info);
169 GapAgent *_gap_agent_new(void)
173 agent = GAP_GET_AGENT(g_object_new(GAP_TYPE_AGENT, NULL));
175 BT_DBG("agent %p", agent);
180 static gboolean gap_agent_request_pin_code(GapAgent *agent,
182 DBusGMethodInvocation *context)
184 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
185 char *sender = dbus_g_method_get_sender(context);
190 DBusGConnection *conn;
195 BT_INFO("Request pin code, Device Path :%s", path);
197 if (g_strcmp0(sender, priv->busname) != 0) {
202 if (!priv->cb.passkey_func) {
207 conn = _bt_get_system_gconn();
213 device = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
214 path, BT_PROPERTIES_INTERFACE);
215 if (device == NULL) {
216 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
217 "No proxy for device");
218 BT_ERR("Fail to make device proxy");
219 dbus_g_method_return_error(context, error);
225 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
226 priv->reply_context = context;
228 addr = strstr(path, "dev_");
232 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
234 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
239 result = priv->cb.pincode_func(agent, device);
241 g_object_unref(device);
247 static gboolean gap_agent_request_passkey(GapAgent *agent, const char *path,
248 DBusGMethodInvocation *context)
250 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
251 char *sender = dbus_g_method_get_sender(context);
255 DBusGConnection *conn;
260 BT_INFO("Request passkey : agent %p sender %s priv->busname %s Device Path :%s", agent,
261 sender, priv->busname, path);
263 if (g_strcmp0(sender, priv->busname) != 0) {
268 if (!priv->cb.passkey_func) {
273 conn = _bt_get_system_gconn();
279 device = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
280 path, BT_PROPERTIES_INTERFACE);
282 if (device == NULL) {
283 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
284 "No proxy for device");
285 BT_ERR("Fail to make device proxy");
286 dbus_g_method_return_error(context, error);
292 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
293 priv->reply_context = context;
295 addr = strstr(path, "dev_");
299 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
301 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
306 result = priv->cb.passkey_func(agent, device);
308 g_object_unref(device);
315 static gboolean gap_agent_display_passkey(GapAgent *agent, const char *path,
316 guint passkey, guint16 entered,
317 DBusGMethodInvocation *context)
319 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
320 char *sender = dbus_g_method_get_sender(context);
323 DBusGConnection *conn;
328 /* Do not show popup for Key event while typing*/
333 BT_INFO("Request passkey display : agent %p sender %s priv->busname %s Device Path :%s\n",
334 agent, sender, priv->busname, path);
336 if (g_strcmp0(sender, priv->busname) != 0) {
341 if (!priv->cb.display_func) {
346 conn = _bt_get_system_gconn();
352 device = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
353 path, BT_PROPERTIES_INTERFACE);
355 if (device == NULL) {
356 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
357 "No proxy for device");
358 BT_ERR("Fail to make device proxy");
359 dbus_g_method_return_error(context, error);
365 dbus_g_method_return(context);
367 result = priv->cb.display_func(agent, device, passkey);
369 g_object_unref(device);
375 static gboolean gap_agent_request_confirmation(GapAgent *agent,
378 DBusGMethodInvocation *context)
380 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
381 char *sender = dbus_g_method_get_sender(context);
385 DBusGConnection *conn;
390 BT_INFO("Request passkey confirmation, Device Path :%s", path);
392 if (g_strcmp0(sender, priv->busname) != 0) {
397 if (!priv->cb.confirm_func) {
402 conn = _bt_get_system_gconn();
408 device = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
409 path, BT_PROPERTIES_INTERFACE);
410 if (device == NULL) {
411 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
412 "No proxy for device");
413 BT_ERR("Fail to make device proxy");
414 dbus_g_method_return_error(context, error);
420 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
421 priv->reply_context = context;
423 addr = strstr(path, "dev_");
427 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
429 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
434 result = priv->cb.confirm_func(agent, device, passkey);
436 g_object_unref(device);
442 static gboolean gap_agent_authorize_service(GapAgent *agent, const char *path,
444 DBusGMethodInvocation *context)
446 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
447 char *sender = dbus_g_method_get_sender(context);
449 DBusGConnection *conn;
456 BT_DBG("Request authorization : agent %p sender %s priv->busname %s Device Path :%s", agent,
457 sender, priv->busname, path);
459 if (g_strcmp0(sender, priv->busname) != 0) {
464 if (!priv->cb.authorize_func) {
469 conn = _bt_get_system_gconn();
475 device = dbus_g_proxy_new_for_name(conn, BT_BLUEZ_NAME,
476 path, BT_PROPERTIES_INTERFACE);
478 if (device == NULL) {
479 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
480 "No proxy for device");
481 BT_DBG("Fail to make device proxy\n");
482 dbus_g_method_return_error(context, error);
488 priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
489 priv->reply_context = context;
491 addr = strstr(path, "dev_");
495 g_strlcpy(priv->authorize_addr, addr,
496 sizeof(priv->authorize_addr));
498 while ((pos = strchr(priv->authorize_addr, '_')) != NULL) {
503 result = priv->cb.authorize_func(agent, device, uuid);
505 g_object_unref(device);
511 static gboolean gap_agent_request_authorization(GapAgent *agent,
513 DBusGMethodInvocation *context)
515 dbus_g_method_return(context);
520 static gboolean gap_agent_confirm_mode_change(GapAgent *agent,
522 DBusGMethodInvocation *context)
526 dbus_g_method_return(context);
530 static gboolean gap_agent_cancel(GapAgent *agent,
531 DBusGMethodInvocation *context)
533 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
534 char *sender = dbus_g_method_get_sender(context);
535 gboolean result = FALSE;
540 BT_DBG("Cancelled : agent %p sender %s", agent, sender);
542 if (g_strcmp0(sender, priv->busname) != 0) {
547 if (priv->cb.authorization_cancel_func &&
548 priv->exec_type == GAP_AGENT_EXEC_AUTHORZATION) {
549 result = priv->cb.authorization_cancel_func(agent,
550 priv->authorize_addr);
551 memset(priv->authorize_addr, 0x00,
552 sizeof(priv->authorize_addr));
553 } else if (priv->cb.pairing_cancel_func &&
554 priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
555 result = priv->cb.pairing_cancel_func(agent,
557 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
560 if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
561 priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
562 priv->reply_context != NULL) {
563 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
564 "Rejected by remote cancel");
565 dbus_g_method_return_error(priv->reply_context, error);
569 /* Canceled flag is set when user cancels pairing request
570 * Since here bluez has cancelled pairing request, we set the flag to false
572 priv->canceled = FALSE;
573 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
574 priv->reply_context = NULL;
580 static gboolean gap_agent_release(GapAgent *agent,
581 DBusGMethodInvocation *context)
583 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
584 char *sender = dbus_g_method_get_sender(context);
589 BT_DBG("Released : agent %p sender %s\n", agent, sender);
591 if (g_strcmp0(sender, priv->busname) != 0) {
596 dbus_g_method_return(context);
598 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
599 priv->reply_context = NULL;
601 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
602 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
608 static bt_agent_osp_server_t *__gap_agent_find_server(GSList *servers,
613 bt_agent_osp_server_t *transfer;
615 for (l = servers; l != NULL; l = l->next) {
618 if (transfer == NULL)
621 /* No uuid in obex server */
622 if (type == BT_OBEX_SERVER &&
623 transfer->type == BT_OBEX_SERVER)
626 if (g_strcmp0(transfer->uuid, uuid) == 0)
633 static void __gap_agent_remove_osp_servers(GSList *osp_servers)
636 bt_agent_osp_server_t *server;
638 for (l = osp_servers; l != NULL; l = g_slist_next(l)) {
644 g_free(server->uuid);
649 gboolean _gap_agent_register_osp_server(GapAgent *agent,
655 bt_agent_osp_server_t *server;
659 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
664 /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
665 if (type > BT_RFCOMM_SERVER)
668 server = g_malloc0(sizeof(bt_agent_osp_server_t));
671 if (type == BT_RFCOMM_SERVER) {
672 server->uuid = g_strdup(uuid);
673 server->path = g_strdup(path);
677 priv->osp_servers = g_slist_append(priv->osp_servers, server);
684 gboolean _gap_agent_unregister_osp_server(GapAgent *agent,
688 bt_agent_osp_server_t *server;
692 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
697 /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
698 if (type > BT_RFCOMM_SERVER)
701 server = __gap_agent_find_server(priv->osp_servers, type, uuid);
706 priv->osp_servers = g_slist_remove(priv->osp_servers, server);
708 g_free(server->uuid);
716 gboolean gap_agent_reply_pin_code(GapAgent *agent, const guint accept,
717 const char *pin_code,
718 DBusGMethodInvocation *context)
722 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
724 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
725 priv->reply_context != NULL) {
726 if (accept == GAP_AGENT_ACCEPT) {
727 dbus_g_method_return(priv->reply_context, pin_code);
728 priv->canceled = FALSE;
730 GError *error = NULL;
732 case GAP_AGENT_CANCEL:
733 error = gap_agent_error(GAP_AGENT_ERROR_CANCEL,
735 priv->canceled = TRUE;
737 case GAP_AGENT_TIMEOUT:
738 case GAP_AGENT_REJECT:
740 error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
741 "Pairing request rejected");
742 priv->canceled = FALSE;
745 dbus_g_method_return_error(priv->reply_context, error);
750 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
751 priv->reply_context = NULL;
752 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
759 gboolean gap_agent_reply_passkey(GapAgent *agent, const guint accept,
761 DBusGMethodInvocation *context)
765 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
767 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
768 priv->reply_context != NULL) {
769 if (accept == GAP_AGENT_ACCEPT) {
770 guint pass_key = atoi(passkey);
771 dbus_g_method_return(priv->reply_context, pass_key);
772 priv->canceled = FALSE;
774 GError *error = NULL;
776 case GAP_AGENT_CANCEL:
777 error = gap_agent_error(GAP_AGENT_ERROR_CANCEL,
779 priv->canceled = TRUE;
781 case GAP_AGENT_TIMEOUT:
782 case GAP_AGENT_REJECT:
784 error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
785 "Passkey request rejected");
786 priv->canceled = FALSE;
789 dbus_g_method_return_error(priv->reply_context, error);
794 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
795 priv->reply_context = NULL;
796 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
803 gboolean gap_agent_reply_confirmation(GapAgent *agent, const guint accept,
804 DBusGMethodInvocation *context)
808 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
810 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
811 priv->reply_context != NULL) {
812 if (accept == GAP_AGENT_ACCEPT) {
813 dbus_g_method_return(priv->reply_context);
814 priv->canceled = FALSE;
816 GError *error = NULL;
818 case GAP_AGENT_CANCEL:
819 error = gap_agent_error(GAP_AGENT_ERROR_CANCEL,
821 priv->canceled = TRUE;
823 case GAP_AGENT_TIMEOUT:
824 case GAP_AGENT_REJECT:
826 error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
827 "Confirmation request rejected");
828 priv->canceled = FALSE;
831 dbus_g_method_return_error(priv->reply_context, error);
836 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
837 priv->reply_context = NULL;
838 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
845 gboolean gap_agent_reply_authorize(GapAgent *agent, const guint accept,
846 DBusGMethodInvocation *context)
852 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
854 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
855 priv->reply_context != NULL) {
856 if (accept == GAP_AGENT_ACCEPT) {
857 dbus_g_method_return(priv->reply_context);
858 } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
859 bluetooth_device_address_t addr = {{0,}};
862 _bt_convert_addr_string_to_type(addr.addr,
863 priv->authorize_addr);
865 result = _bt_set_authorization(&addr, TRUE);
866 if (result == BLUETOOTH_ERROR_NONE) {
867 BT_INFO("[%s] Device added to trusted", priv->authorize_addr);
870 dbus_g_method_return(priv->reply_context);
872 GError *error = NULL;
874 case GAP_AGENT_CANCEL:
875 error = gap_agent_error(GAP_AGENT_ERROR_CANCEL,
878 case GAP_AGENT_TIMEOUT:
879 case GAP_AGENT_REJECT:
881 error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
882 "Authorization request rejected");
885 dbus_g_method_return_error(priv->reply_context, error);
890 dbus_g_method_return(context);
892 GError *error = gap_agent_error(GAP_AGENT_ERROR_REJECT,
894 BT_ERR("No context");
897 dbus_g_method_return_error(context, error);
903 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
904 priv->reply_context = NULL;
905 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
912 static gboolean gap_agent_get_discoverable_timeout(GapAgent *agent,
913 DBusGMethodInvocation *context)
919 _bt_get_timeout_value(&timeout);
921 dbus_g_method_return(context, timeout);
928 gboolean _gap_agent_register(GapAgent *agent)
930 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
931 DBusGProxy *agent_manager;
932 GError *error = NULL;
934 retv_if(priv == NULL, FALSE);
935 retv_if(connection == NULL, FALSE);
937 if (priv->agent_manager == NULL) {
938 agent_manager = dbus_g_proxy_new_for_name(connection,
939 BT_BLUEZ_NAME, BT_BLUEZ_PATH,
940 BT_AGENT_MANAGER_INTERFACE);
942 retv_if(agent_manager == NULL, FALSE);
944 agent_manager = priv->agent_manager;
947 #ifdef __TIZEN_MOBILE_
948 dbus_g_proxy_call(agent_manager, "RegisterAgent", &error,
949 DBUS_TYPE_G_OBJECT_PATH, priv->path,
950 G_TYPE_STRING, "DisplayYesNo", G_TYPE_INVALID,
953 dbus_g_proxy_call(agent_manager, "RegisterAgent", &error,
954 DBUS_TYPE_G_OBJECT_PATH, priv->path,
955 G_TYPE_STRING, "NoInputNoOutput", G_TYPE_INVALID,
959 BT_DBG("Agent registration failed: %s\n", error->message);
961 g_object_unref(agent_manager);
962 priv->agent_manager = NULL;
966 /* Set the defalut agent */
967 dbus_g_proxy_call(agent_manager, "RequestDefaultAgent", &error,
968 DBUS_TYPE_G_OBJECT_PATH, priv->path,
969 G_TYPE_INVALID, G_TYPE_INVALID);
972 BT_DBG("Request agent failed: %s\n", error->message);
974 g_object_unref(agent_manager);
975 priv->agent_manager = NULL;
979 priv->agent_manager = agent_manager;
984 static gboolean __gap_agent_unregister(GapAgent *agent)
986 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
987 DBusGProxy *agent_manager;
988 GError *error = NULL;
990 retv_if(priv == NULL, FALSE);
991 retv_if(priv->path == NULL, FALSE);
992 retv_if(connection == NULL, FALSE);
994 if (priv->agent_manager == NULL) {
995 agent_manager = dbus_g_proxy_new_for_name(connection,
996 BT_BLUEZ_NAME, BT_BLUEZ_PATH,
997 BT_AGENT_MANAGER_INTERFACE);
999 retv_if(agent_manager == NULL, FALSE);
1001 agent_manager = priv->agent_manager;
1004 dbus_g_proxy_call(agent_manager, "UnregisterAgent", &error,
1005 DBUS_TYPE_G_OBJECT_PATH, priv->path,
1006 G_TYPE_INVALID, G_TYPE_INVALID);
1008 g_object_unref(agent_manager);
1009 priv->agent_manager = NULL;
1011 if (error != NULL) {
1012 BT_DBG("Agent unregistration failed: %s\n", error->message);
1013 g_error_free(error);
1020 void _gap_agent_setup_dbus(GapAgent *agent, GAP_AGENT_FUNC_CB *func_cb,
1023 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1027 priv->path = g_strdup(path);
1029 object = dbus_g_connection_lookup_g_object(connection, priv->path);
1031 g_object_unref(object);
1033 dbus_g_connection_register_g_object(connection, priv->path,
1036 memcpy(&priv->cb, func_cb, sizeof(GAP_AGENT_FUNC_CB));
1038 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
1039 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
1040 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
1041 priv->reply_context = NULL;
1043 BT_DBG("patt: %s", path);
1045 proxy = dbus_g_proxy_new_for_name_owner(connection,
1050 if (proxy != NULL) {
1051 priv->busname = g_strdup(dbus_g_proxy_get_bus_name(proxy));
1052 g_object_unref(proxy);
1054 priv->busname = NULL;
1058 void _gap_agent_reset_dbus(GapAgent *agent)
1060 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1062 __gap_agent_unregister(agent);
1064 dbus_g_connection_unregister_g_object(connection, G_OBJECT(agent));
1066 if (priv->osp_servers) {
1067 __gap_agent_remove_osp_servers(priv->osp_servers);
1068 g_slist_free(priv->osp_servers);
1069 priv->osp_servers = NULL;
1072 if (priv->adapter) {
1073 g_object_unref(priv->adapter);
1074 priv->adapter = NULL;
1080 g_free(priv->busname);
1081 priv->busname = NULL;
1084 gboolean _gap_agent_exist_osp_server(GapAgent *agent, int type, char *uuid)
1086 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1091 if (__gap_agent_find_server(priv->osp_servers,
1092 type, uuid) != NULL) {
1099 bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgent *agent, int type,
1102 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1103 bt_agent_osp_server_t *osp_serv = NULL;
1107 osp_serv = __gap_agent_find_server(priv->osp_servers,
1116 gchar* _gap_agent_get_path(GapAgent *agent)
1118 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1123 gboolean _gap_agent_is_canceled(GapAgent *agent)
1125 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1127 return priv->canceled;
1130 void _gap_agent_set_canceled(GapAgent *agent, gboolean value)
1132 GapAgentPrivate *priv = GAP_AGENT_GET_PRIVATE(agent);
1134 priv->canceled = value;