2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <vconf-keys.h>
24 #include "bt-internal-types.h"
25 #include "bt-service-common.h"
26 #include "bt-service-agent.h"
27 #include "bt-service-gap-agent.h"
28 #include "bt-service-adapter.h"
29 #include "bt-service-device.h"
31 static GDBusConnection *connection = NULL;
34 GAP_AGENT_ERROR_REJECT,
35 GAP_AGENT_ERROR_CANCEL,
36 GAP_AGENT_ERROR_TIMEOUT,
39 #define GAP_AGENT_ERROR (gap_agent_error_quark())
41 static GQuark gap_agent_error_quark(void)
43 static GQuark quark = 0;
45 quark = g_quark_from_static_string("agent");
50 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
52 static gint gap_agent_id = -1;
54 static bt_agent_osp_server_t *__gap_agent_find_server(GSList *servers,
59 bt_agent_osp_server_t *transfer;
61 for (l = servers; l != NULL; l = l->next) {
67 /* No uuid in obex server */
68 if (type == BT_OBEX_SERVER &&
69 transfer->type == BT_OBEX_SERVER)
72 if (g_strcmp0(transfer->uuid, uuid) == 0)
79 static void __gap_agent_remove_osp_servers(GSList *osp_servers)
82 bt_agent_osp_server_t *server;
84 for (l = osp_servers; l != NULL; l = g_slist_next(l)) {
95 gboolean _gap_agent_register_osp_server(GapAgentPrivate *agent,
101 bt_agent_osp_server_t *server;
105 GapAgentPrivate *priv = agent;
110 /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
111 if (type > BT_RFCOMM_SERVER)
114 server = g_malloc0(sizeof(bt_agent_osp_server_t));
116 /* Fix : NULL_RETURNS */
117 retv_if(server == NULL, FALSE);
120 if (type == BT_RFCOMM_SERVER) {
121 server->uuid = g_strdup(uuid);
122 server->path = g_strdup(path);
126 priv->osp_servers = g_slist_append(priv->osp_servers, server);
133 gboolean _gap_agent_unregister_osp_server(GapAgentPrivate *agent,
137 bt_agent_osp_server_t *server;
141 GapAgentPrivate *priv = agent;
146 /* type: BT_OBEX_SERVER / BT_RFCOMM_SERVER*/
147 if (type > BT_RFCOMM_SERVER)
150 server = __gap_agent_find_server(priv->osp_servers, type, uuid);
155 priv->osp_servers = g_slist_remove(priv->osp_servers, server);
157 g_free(server->uuid);
165 gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
166 const char *pin_code,
167 GDBusMethodInvocation *context)
171 GapAgentPrivate *priv = agent;
173 /* Fix : NULL_RETURNS */
174 retv_if(priv == NULL, FALSE);
176 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
177 priv->reply_context != NULL) {
178 if (accept == GAP_AGENT_ACCEPT) {
179 g_dbus_method_invocation_return_value(priv->reply_context,
180 g_variant_new("(s)", pin_code));
181 priv->canceled = FALSE;
184 case GAP_AGENT_CANCEL:
185 g_dbus_method_invocation_return_error(priv->reply_context,
186 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
188 priv->canceled = TRUE;
190 case GAP_AGENT_TIMEOUT:
191 case GAP_AGENT_REJECT:
193 g_dbus_method_invocation_return_error(priv->reply_context,
194 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
195 "Pairing request rejected");
196 priv->canceled = FALSE;
202 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
203 priv->reply_context = NULL;
204 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
211 gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
213 GDBusMethodInvocation *context)
217 GapAgentPrivate *priv = agent;
219 /* Fix : NULL_RETURNS */
220 retv_if(priv == NULL, FALSE);
222 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
223 priv->reply_context != NULL) {
224 if (accept == GAP_AGENT_ACCEPT) {
225 guint pass_key = atoi(passkey);
226 g_dbus_method_invocation_return_value(priv->reply_context,
227 g_variant_new("(u)", pass_key));
228 priv->canceled = FALSE;
231 case GAP_AGENT_CANCEL:
232 g_dbus_method_invocation_return_error(priv->reply_context,
233 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
235 priv->canceled = TRUE;
237 case GAP_AGENT_TIMEOUT:
238 case GAP_AGENT_REJECT:
240 g_dbus_method_invocation_return_error(priv->reply_context,
241 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
242 "Passkey request rejected");
243 priv->canceled = FALSE;
249 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
250 priv->reply_context = NULL;
251 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
258 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
259 GDBusMethodInvocation *context)
263 GapAgentPrivate *priv = agent;
265 /* Fix : NULL_RETURNS */
266 retv_if(priv == NULL, FALSE);
268 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
269 priv->reply_context != NULL) {
270 if (accept == GAP_AGENT_ACCEPT) {
271 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
272 priv->canceled = FALSE;
275 case GAP_AGENT_CANCEL:
276 g_dbus_method_invocation_return_error(priv->reply_context,
277 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
279 priv->canceled = TRUE;
281 case GAP_AGENT_TIMEOUT:
282 case GAP_AGENT_REJECT:
284 g_dbus_method_invocation_return_error(priv->reply_context,
285 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
286 "Confirmation request rejected");
287 priv->canceled = FALSE;
293 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
294 priv->reply_context = NULL;
295 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
302 gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
303 GDBusMethodInvocation *context)
309 GapAgentPrivate *priv = agent;
311 /* Fix : NULL_RETURNS */
312 retv_if(priv == NULL, FALSE);
314 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
315 priv->reply_context != NULL) {
316 if (accept == GAP_AGENT_ACCEPT) {
317 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
318 } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
319 bluetooth_device_address_t addr = {{0,}};
322 _bt_convert_addr_string_to_type(addr.addr,
323 priv->authorize_addr);
325 result = _bt_set_authorization(&addr, TRUE);
326 if (result == BLUETOOTH_ERROR_NONE) {
327 BT_INFO("[%s] Device added to trusted", priv->authorize_addr);
330 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
333 case GAP_AGENT_CANCEL:
334 g_dbus_method_invocation_return_error(priv->reply_context,
335 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
338 case GAP_AGENT_TIMEOUT:
339 case GAP_AGENT_REJECT:
341 g_dbus_method_invocation_return_error(priv->reply_context,
342 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
343 "Authorization request rejected");
349 g_dbus_method_invocation_return_value(context, NULL);
351 BT_ERR("No context");
354 g_dbus_method_invocation_return_error(context,
355 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
360 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
361 priv->reply_context = NULL;
362 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
369 gboolean _gap_agent_register(GapAgentPrivate *agent)
371 GapAgentPrivate *priv = agent;
372 GDBusProxy *agent_manager;
373 GError *error = NULL;
376 retv_if(priv == NULL, FALSE);
377 retv_if(connection == NULL, FALSE);
379 if (priv->agent_manager == NULL) {
380 agent_manager = g_dbus_proxy_new_sync(connection,
381 G_DBUS_PROXY_FLAGS_NONE, NULL,
382 BT_BLUEZ_NAME, BT_BLUEZ_PATH,
383 BT_AGENT_MANAGER_INTERFACE, NULL, &error);
384 if (!agent_manager) {
386 ERR("Unable to create proxy: %s", error->message);
387 g_clear_error(&error);
392 agent_manager = priv->agent_manager;
395 reply = g_dbus_proxy_call_sync(agent_manager, "RegisterAgent",
396 #ifdef TIZEN_BT_IO_CAPA_NO_INPUT_OUTPUT
397 g_variant_new("(os)", priv->path, "NoInputNoOutput"),
399 g_variant_new("(os)", priv->path, "DisplayYesNo"),
401 G_DBUS_CALL_FLAGS_NONE, -1,
404 BT_ERR("Agent registration failed");
406 BT_ERR("Agent registration failed: errCode[%x], message[%s]",
407 error->code, error->message);
408 g_clear_error(&error);
410 g_object_unref(agent_manager);
411 priv->agent_manager = NULL;
414 g_variant_unref(reply);
417 /* Set the defalut agent */
418 BT_DBG("agent_manager[%p] priv->path[%s]", agent_manager, priv->path);
419 reply = g_dbus_proxy_call_sync(agent_manager, "RequestDefaultAgent",
420 g_variant_new("(o)", priv->path),
421 G_DBUS_CALL_FLAGS_NONE, -1,
424 ERR("Request Default Agent failed");
426 ERR("Request Default Agent failed: errCode[%x], message[%s]",
427 error->code, error->message);
428 g_clear_error(&error);
430 g_object_unref(agent_manager);
431 priv->agent_manager = NULL;
434 g_variant_unref(reply);
436 priv->agent_manager = agent_manager;
441 static gboolean __gap_agent_unregister(GapAgentPrivate *agent)
443 GapAgentPrivate *priv = agent;
444 GDBusProxy *agent_manager;
445 GError *error = NULL;
448 retv_if(priv == NULL, FALSE);
449 retv_if(priv->path == NULL, FALSE);
450 retv_if(connection == NULL, FALSE);
452 if (priv->agent_manager == NULL) {
453 agent_manager = g_dbus_proxy_new_sync(connection,
454 G_DBUS_PROXY_FLAGS_NONE, NULL,
455 BT_BLUEZ_NAME, BT_BLUEZ_PATH,
456 BT_AGENT_MANAGER_INTERFACE, NULL, &error);
457 if (!agent_manager) {
459 ERR("Unable to create proxy: %s", error->message);
460 g_clear_error(&error);
465 agent_manager = priv->agent_manager;
468 reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
469 g_variant_new("o", priv->path),
470 G_DBUS_CALL_FLAGS_NONE, -1,
472 g_object_unref(agent_manager);
473 priv->agent_manager = NULL;
476 ERR("Agent unregistration failed");
478 ERR("Agent unregistration failed: errCode[%x], message[%s]",
479 error->code, error->message);
480 g_clear_error(&error);
484 g_variant_unref(reply);
489 static const gchar gap_agent_bluez_introspection_xml[] =
491 " <interface name='org.bluez.Agent1'>"
492 " <method name='GetDiscoverableTimeout'>"
493 " <arg type='u' name='timeout' direction='out'/>"
495 " <method name='Cancel'>"
497 " <method name='RequestPasskey'>"
498 " <arg type='o' name='device' direction='in'/>"
499 " <arg type='u' name='passkey' direction='out'/>"
501 " <method name='Release'>"
503 " <method name='RequestConfirmation'>"
504 " <arg type='o' name='device' direction='in'/>"
505 " <arg type='u' name='passkey' direction='in'/>"
507 " <method name='RequestAuthorization'>"
508 " <arg type='o' name='device' direction='in'/>"
510 " <method name='ReplyPasskey'>"
511 " <arg type='u' name='accept' direction='in'/>"
512 " <arg type='s' name='passkey' direction='in'/>"
514 " <method name='DisplayPasskey'>"
515 " <arg type='o' name='device' direction='in'/>"
516 " <arg type='u' name='passkey' direction='in'/>"
517 " <arg type='q' name='entered' direction='in'/>"
519 " <method name='ReplyConfirmation'>"
520 " <arg type='u' name='accept' direction='in'/>"
522 " <method name='ReplyPinCode'>"
523 " <arg type='u' name='accept' direction='in'/>"
524 " <arg type='s' name='pincode' direction='in'/>"
526 " <method name='ReplyAuthorize'>"
527 " <arg type='u' name='accept' direction='in'/>"
529 " <method name='RequestPinCode'>"
530 " <arg type='o' name='device' direction='in'/>"
531 " <arg type='s' name='pincode' direction='out'/>"
533 " <method name='ConfirmModeChange'>"
534 " <arg type='s' name='mode' direction='in'/>"
536 " <method name='AuthorizeService'>"
537 " <arg type='o' name='device' direction='in'/>"
538 " <arg type='s' name='uuid' direction='in'/>"
543 static GDBusNodeInfo *__bt_service_create_method_node_info
544 (const gchar *introspection_data)
547 GDBusNodeInfo *node_info = NULL;
549 if (introspection_data == NULL)
552 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
555 ERR("Unable to create node: %s", err->message);
561 static void __bt_gap_agent_method(GDBusConnection *connection,
563 const gchar *object_path,
564 const gchar *interface_name,
565 const gchar *method_name,
566 GVariant *parameters,
567 GDBusMethodInvocation *invocation,
572 BT_DBG("Method[%s] Object Path[%s] Interface Name[%s]",
573 method_name, object_path, interface_name);
577 if (g_strcmp0(method_name, "RequestPinCode") == 0) {
578 GapAgentPrivate *agent = user_data;
579 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
583 GDBusConnection *conn;
588 g_variant_get(parameters, "(&o)", &path);
589 BT_INFO("Request pin code, Device Path :%s", path);
592 if (g_strcmp0(sender, agent->busname) != 0)
596 if (!agent->cb.passkey_func)
599 conn = _bt_get_system_gconn();
603 device = g_dbus_proxy_new_sync(conn,
604 G_DBUS_PROXY_FLAGS_NONE, NULL,
606 BT_PROPERTIES_INTERFACE, NULL, &err);
609 BT_ERR("Fail to make device proxy");
611 g_dbus_method_invocation_return_error(invocation,
612 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
613 "No proxy for device");
616 ERR("Unable to create proxy: %s", err->message);
623 agent->exec_type = GAP_AGENT_EXEC_PAIRING;
624 agent->reply_context = invocation;
626 addr = strstr(path, "dev_");
630 g_strlcpy(agent->pairing_addr, addr, sizeof(agent->pairing_addr));
632 while ((pos = strchr(agent->pairing_addr, '_')) != NULL) {
637 agent->cb.pincode_func(agent, device);
639 g_object_unref(device);
642 } else if (g_strcmp0(method_name, "RequestPasskey") == 0) {
643 GapAgentPrivate *priv = user_data;
644 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
648 GDBusConnection *conn;
653 g_variant_get(parameters, "(&o)", &path);
654 BT_INFO("Request passkey : sender %s priv->busname %s Device Path :%s",
655 sender, priv->busname, path);
658 if (g_strcmp0(sender, agent->busname) != 0)
662 if (!priv->cb.passkey_func)
665 conn = _bt_get_system_gconn();
669 device = g_dbus_proxy_new_sync(conn,
670 G_DBUS_PROXY_FLAGS_NONE, NULL,
672 BT_PROPERTIES_INTERFACE, NULL, &err);
675 BT_ERR("Fail to make device proxy");
677 g_dbus_method_invocation_return_error(invocation,
678 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
679 "No proxy for device");
682 ERR("Unable to create proxy: %s", err->message);
689 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
690 priv->reply_context = invocation;
692 addr = strstr(path, "dev_");
696 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
698 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
703 priv->cb.passkey_func(priv, device);
705 g_object_unref(device);
708 } else if (g_strcmp0(method_name, "DisplayPasskey") == 0) {
709 GapAgentPrivate *priv = user_data;
710 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
715 GDBusConnection *conn;
720 g_variant_get(parameters, "(&ouq)", &path, &passkey, &entered);
721 BT_INFO("Request passkey display :sender %s priv->busname %s"
722 " Device Path :%s, Passkey: %d, Entered: %d",
723 sender, priv->busname, path, passkey, entered);
725 /* Do not show popup for Key event while typing*/
730 if (g_strcmp0(sender, agent->busname) != 0)
734 if (!priv->cb.display_func)
737 conn = _bt_get_system_gconn();
741 device = g_dbus_proxy_new_sync(conn,
742 G_DBUS_PROXY_FLAGS_NONE, NULL,
744 BT_PROPERTIES_INTERFACE, NULL, &err);
747 BT_ERR("Fail to make device proxy");
749 g_dbus_method_invocation_return_error(invocation,
750 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
751 "No proxy for device");
754 ERR("Unable to create proxy: %s", err->message);
761 g_dbus_method_invocation_return_value(invocation, NULL);
763 priv->cb.display_func(priv, device, passkey);
765 g_object_unref(device);
768 } else if (g_strcmp0(method_name, "RequestConfirmation") == 0) {
769 GapAgentPrivate *priv = user_data;
770 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
775 GDBusConnection *conn;
780 g_variant_get(parameters, "(&ou)", &path, &passkey);
781 BT_INFO("Request passkey confirmation, Device Path :%s, Passkey: %d",
784 BT_DBG("Sender: [%s] priv->busname: [%s]", sender, priv->busname);
786 if (g_strcmp0(sender, agent->busname) != 0)
790 BT_DBG("priv->cb.confirm_func [%p]", priv->cb.confirm_func);
791 if (!priv->cb.confirm_func)
794 conn = _bt_get_system_gconn();
798 device = g_dbus_proxy_new_sync(conn,
799 G_DBUS_PROXY_FLAGS_NONE, NULL,
801 BT_PROPERTIES_INTERFACE, NULL, &err);
804 BT_ERR("Fail to make device proxy");
806 g_dbus_method_invocation_return_error(invocation,
807 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
808 "No proxy for device");
811 ERR("Unable to create proxy: %s", err->message);
818 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
819 priv->reply_context = invocation;
821 addr = strstr(path, "dev_");
825 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
827 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
832 priv->cb.confirm_func(priv, device, passkey);
834 g_object_unref(device);
837 } else if (g_strcmp0(method_name, "AuthorizeService") == 0) {
838 GapAgentPrivate *priv = user_data;
839 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
841 GDBusConnection *conn;
849 g_variant_get(parameters, "(&o&s)", &path, &uuid);
850 BT_DBG("Request authorization :sender %s priv->busname %s "
851 "Device Path :%s UUID: %s",
852 sender, priv->busname, path, uuid);
855 if (g_strcmp0(sender, agent->busname) != 0)
859 if (!priv->cb.authorize_func)
862 conn = _bt_get_system_gconn();
866 device = g_dbus_proxy_new_sync(conn,
867 G_DBUS_PROXY_FLAGS_NONE, NULL,
869 BT_PROPERTIES_INTERFACE, NULL, &err);
872 BT_ERR("Fail to make device proxy");
874 g_dbus_method_invocation_return_error(invocation,
875 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
876 "No proxy for device");
879 ERR("Unable to create proxy: %s", err->message);
886 priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
887 priv->reply_context = invocation;
889 addr = strstr(path, "dev_");
893 g_strlcpy(priv->authorize_addr, addr,
894 sizeof(priv->authorize_addr));
896 while ((pos = strchr(priv->authorize_addr, '_')) != NULL) {
901 priv->cb.authorize_func(priv, device, uuid);
903 g_object_unref(device);
906 } else if (g_strcmp0(method_name, "RequestAuthorization") == 0) {
907 g_dbus_method_invocation_return_value(invocation, NULL);
908 } else if (g_strcmp0(method_name, "ConfirmModeChange") == 0) {
909 g_dbus_method_invocation_return_value(invocation, NULL);
910 } else if (g_strcmp0(method_name, "Cancel") == 0) {
911 GapAgentPrivate *priv = user_data;
912 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
917 BT_DBG("Cancelled : agent %p sender %s", sender);
920 if (g_strcmp0(sender, agent->busname) != 0)
924 if (priv->cb.authorization_cancel_func &&
925 priv->exec_type == GAP_AGENT_EXEC_AUTHORZATION) {
926 priv->cb.authorization_cancel_func(priv,
927 priv->authorize_addr);
928 memset(priv->authorize_addr, 0x00,
929 sizeof(priv->authorize_addr));
930 } else if (priv->cb.pairing_cancel_func &&
931 priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
932 priv->cb.pairing_cancel_func(priv,
934 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
937 if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
938 priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
939 priv->reply_context != NULL) {
941 g_dbus_method_invocation_return_error(priv->reply_context,
942 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
943 "Rejected by remote cancel");
946 /* Canceled flag is set when user cancels pairing request
947 * Since here bluez has cancelled pairing request, we set the flag to false
949 priv->canceled = FALSE;
950 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
951 priv->reply_context = NULL;
954 } else if (g_strcmp0(method_name, "Release") == 0) {
955 GapAgentPrivate *priv = user_data;
956 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
961 BT_DBG("Released : sender %s\n", sender);
964 if (g_strcmp0(sender, agent->busname) != 0)
968 g_dbus_method_invocation_return_value(invocation, NULL);
970 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
971 priv->reply_context = NULL;
973 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
974 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
977 } else if (g_strcmp0(method_name, "GetDiscoverableTimeout") == 0) {
982 _bt_get_timeout_value(&timeout);
984 g_dbus_method_invocation_return_value(invocation,
985 g_variant_new("(i)", timeout));
990 } else if (g_strcmp0(method_name, "ReplyPinCode") == 0) {
991 GapAgentPrivate *priv = user_data;
992 const char *pin_code;
995 g_variant_get(parameters, "(u&s)", &accept, &pin_code);
996 BT_DBG("Accept: %d PinCode: %s", accept, pin_code);
997 gap_agent_reply_pin_code(priv, accept, pin_code, invocation);
998 } else if (g_strcmp0(method_name, "ReplyPasskey") == 0) {
999 GapAgentPrivate *priv = user_data;
1000 const char *passkey;
1003 g_variant_get(parameters, "(u&s)", &accept, &passkey);
1004 BT_DBG("Accept: %d PinCode: %s", accept, passkey);
1005 gap_agent_reply_passkey(priv, accept, passkey, invocation);
1006 } else if (g_strcmp0(method_name, "ReplyConfirmation") == 0) {
1007 GapAgentPrivate *priv = user_data;
1010 g_variant_get(parameters, "(u)", &accept);
1011 BT_DBG("Accept: %d", accept);
1012 gap_agent_reply_confirmation(priv, accept, invocation);
1013 } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
1014 GapAgentPrivate *priv = user_data;
1017 g_variant_get(parameters, "(u)", &accept);
1018 BT_DBG("Accept: %d", accept);
1019 gap_agent_reply_authorize(priv, accept, invocation);
1023 static const GDBusInterfaceVTable method_table = {
1024 __bt_gap_agent_method,
1029 void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
1031 GDBusProxy *adapter)
1033 GapAgentPrivate *priv = agent;
1035 GDBusNodeInfo *node_info;
1036 GError *error = NULL;
1039 priv->path = g_strdup(path);
1042 node_info = __bt_service_create_method_node_info(
1043 gap_agent_bluez_introspection_xml);
1044 if (node_info == NULL)
1047 BT_DBG("path is [%s]", path);
1049 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1052 ERR("Unable to connect to gdbus: %s", error->message);
1053 g_clear_error(&error);
1058 if (gap_agent_id == -1) {
1059 gap_agent_id = g_dbus_connection_register_object(connection, path,
1060 node_info->interfaces[0],
1061 &method_table, priv,
1065 g_dbus_node_info_unref(node_info);
1067 if (gap_agent_id == 0) {
1068 BT_ERR("Failed to register for Path: %s", path);
1070 BT_ERR("Failed to register: %s", error->message);
1071 g_clear_error(&error);
1076 memcpy(&priv->cb, func_cb, sizeof(GAP_AGENT_FUNC_CB));
1078 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
1079 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
1080 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
1081 priv->reply_context = NULL;
1083 BT_DBG("path: %s", path);
1085 proxy = g_dbus_proxy_new_sync(connection,
1086 G_DBUS_PROXY_FLAGS_NONE, NULL,
1087 BT_BLUEZ_NAME, path,
1088 BT_AGENT_INTERFACE, NULL, &error);
1091 ERR("Unable to create proxy");
1093 ERR("Error: %s", error->message);
1094 g_clear_error(&error);
1096 priv->busname = NULL;
1098 priv->busname = g_strdup(g_dbus_proxy_get_name(proxy));
1099 g_object_unref(proxy);
1100 BT_DBG("Busname: %s", priv->busname);
1105 void _gap_agent_reset_dbus(GapAgentPrivate *agent)
1107 GapAgentPrivate *priv = agent;
1109 /* Fix : NULL_RETURNS */
1113 __gap_agent_unregister(agent);
1115 if (gap_agent_id > 0) {
1116 g_dbus_connection_unregister_object(connection,
1121 if (priv->osp_servers) {
1122 __gap_agent_remove_osp_servers(priv->osp_servers);
1123 g_slist_free(priv->osp_servers);
1124 priv->osp_servers = NULL;
1127 g_object_ref(priv->adapter);
1128 priv->adapter = NULL;
1133 g_free(priv->busname);
1134 priv->busname = NULL;
1137 gboolean _gap_agent_exist_osp_server(GapAgentPrivate *agent, int type, char *uuid)
1139 GapAgentPrivate *priv = agent;
1141 /* Fix : NULL_RETURNS */
1142 retv_if(priv == NULL, FALSE);
1144 if (__gap_agent_find_server(priv->osp_servers,
1145 type, uuid) != NULL) {
1152 bt_agent_osp_server_t *_gap_agent_get_osp_server(GapAgentPrivate *agent, int type,
1155 GapAgentPrivate *priv = agent;
1156 bt_agent_osp_server_t *osp_serv = NULL;
1160 osp_serv = __gap_agent_find_server(priv->osp_servers,
1169 gchar* _gap_agent_get_path(GapAgentPrivate *agent)
1171 GapAgentPrivate *priv = agent;
1173 /* Fix : NULL_RETURNS */
1180 gboolean _gap_agent_is_canceled(GapAgentPrivate *agent)
1182 GapAgentPrivate *priv = agent;
1184 /* Fix : NULL_RETURNS */
1185 retv_if(priv == NULL, FALSE);
1187 return priv->canceled;
1190 void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value)
1192 GapAgentPrivate *priv = agent;
1194 /* Fix : NULL_RETURNS */
1198 priv->canceled = value;