4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Anupam Roy <anupam.r@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include <vconf-keys.h>
28 #include <bt-hal-gap-agent.h>
29 #include <bt-hal-agent.h>
30 #include <bt-hal-internal.h>
33 #include "bt-hal-log.h"
34 #include "bt-hal-msg.h"
35 #include "bt-hal-utils.h"
37 #include <dbus/dbus-glib.h>
38 #include <dbus/dbus.h>
43 #include "bt-hal-adapter-dbus-handler.h"
44 #include "bt-hal-dbus-common-utils.h"
46 static GDBusConnection *connection = NULL;
49 GAP_AGENT_ERROR_REJECT,
50 GAP_AGENT_ERROR_CANCEL,
51 GAP_AGENT_ERROR_TIMEOUT,
54 #define GAP_AGENT_ERROR (gap_agent_error_quark())
56 static GQuark gap_agent_error_quark(void)
58 static GQuark quark = 0;
60 quark = g_quark_from_static_string("agent");
66 /* Forward declaration */
67 static gboolean __gap_agent_unregister(GapAgentPrivate *agent);
68 static GDBusNodeInfo *__bt_service_create_method_node_info
69 (const gchar *introspection_data);
70 static void __bt_gap_agent_method(GDBusConnection *connection,
72 const gchar *object_path,
73 const gchar *interface_name,
74 const gchar *method_name,
76 GDBusMethodInvocation *invocation,
78 void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value);
82 static gint gap_agent_id = -1;
84 gboolean _gap_agent_register(GapAgentPrivate *agent)
86 GapAgentPrivate *priv = agent;
87 GDBusProxy *agent_manager;
96 if (priv->agent_manager == NULL) {
97 agent_manager = g_dbus_proxy_new_sync(connection,
98 G_DBUS_PROXY_FLAGS_NONE, NULL,
99 BT_HAL_BLUEZ_NAME, BT_HAL_BLUEZ_PATH,
100 BT_HAL_AGENT_MANAGER_INTERFACE, NULL, &error);
101 if (!agent_manager) {
103 ERR("Unable to create proxy: %s", error->message);
104 g_clear_error(&error);
109 agent_manager = priv->agent_manager;
112 reply = g_dbus_proxy_call_sync(agent_manager, "RegisterAgent",
113 #ifdef TIZEN_BT_IO_CAPA_NO_INPUT_OUTPUT
114 g_variant_new("(os)", priv->path, "NoInputNoOutput"),
116 g_variant_new("(os)", priv->path, "DisplayYesNo"),
118 G_DBUS_CALL_FLAGS_NONE, -1,
121 ERR("Agent registration failed");
123 ERR("Agent registration failed: errCode[%x], message[%s]",
124 error->code, error->message);
125 g_clear_error(&error);
127 g_object_unref(agent_manager);
128 priv->agent_manager = NULL;
131 g_variant_unref(reply);
134 /* Set the defalut agent */
135 DBG("agent_manager[%p] priv->path[%s]", agent_manager, priv->path);
136 reply = g_dbus_proxy_call_sync(agent_manager, "RequestDefaultAgent",
137 g_variant_new("(o)", priv->path),
138 G_DBUS_CALL_FLAGS_NONE, -1,
141 ERR("Request Default Agent failed");
143 ERR("Request Default Agent failed: errCode[%x], message[%s]",
144 error->code, error->message);
145 g_clear_error(&error);
147 g_object_unref(agent_manager);
148 priv->agent_manager = NULL;
151 g_variant_unref(reply);
153 priv->agent_manager = agent_manager;
158 static const gchar gap_agent_bluez_introspection_xml[] =
160 " <interface name='org.bluez.Agent1'>"
161 " <method name='RequestPinCode'>"
162 " <arg type='o' name='device' direction='in'/>"
163 " <arg type='s' name='pincode' direction='out'/>"
165 " <method name='RequestPasskey'>"
166 " <arg type='o' name='device' direction='in'/>"
167 " <arg type='u' name='passkey' direction='out'/>"
169 " <method name='DisplayPasskey'>"
170 " <arg type='o' name='device' direction='in'/>"
171 " <arg type='u' name='passkey' direction='in'/>"
172 " <arg type='q' name='entered' direction='in'/>"
174 " <method name='RequestConfirmation'>"
175 " <arg type='o' name='device' direction='in'/>"
176 " <arg type='u' name='passkey' direction='in'/>"
178 " <method name='RequestAuthorization'>"
179 " <arg type='o' name='device' direction='in'/>"
181 " <method name='AuthorizeService'>"
182 " <arg type='o' name='device' direction='in'/>"
183 " <arg type='s' name='uuid' direction='in'/>"
185 " <method name='Cancel'>"
187 " <method name='Release'>"
189 " <method name='ReplyPinCode'>"
190 " <arg type='u' name='accept' direction='in'/>"
191 " <arg type='s' name='pincode' direction='in'/>"
193 " <method name='ReplyPasskey'>"
194 " <arg type='u' name='accept' direction='in'/>"
195 " <arg type='s' name='passkey' direction='in'/>"
197 " <method name='ReplyConfirmation'>"
198 " <arg type='u' name='accept' direction='in'/>"
200 " <method name='ReplyAuthorize'>"
201 " <arg type='u' name='accept' direction='in'/>"
203 " <method name='ConfirmModeChange'>"
204 " <arg type='s' name='mode' direction='in'/>"
206 " <method name='GetDiscoverableTimeout'>"
207 " <arg type='u' name='timeout' direction='out'/>"
213 static const GDBusInterfaceVTable method_table = {
214 __bt_gap_agent_method,
219 void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
223 GapAgentPrivate *priv = agent;
225 GDBusNodeInfo *node_info;
226 GError *error = NULL;
229 priv->path = g_strdup(path);
231 node_info = __bt_service_create_method_node_info(
232 gap_agent_bluez_introspection_xml);
233 if (node_info == NULL)
236 DBG("path is [%s]", path);
238 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
241 ERR("Unable to connect to gdbus: %s", error->message);
242 g_clear_error(&error);
247 if (gap_agent_id == -1) {
248 gap_agent_id = g_dbus_connection_register_object(connection, path,
249 node_info->interfaces[0],
254 g_dbus_node_info_unref(node_info);
256 if (gap_agent_id == 0) {
257 ERR("Failed to register for Path: %s", path);
259 ERR("Failed to register: %s", error->message);
260 g_clear_error(&error);
265 memcpy(&priv->cb, func_cb, sizeof(GAP_AGENT_FUNC_CB));
267 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
268 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
269 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
270 priv->reply_context = NULL;
272 DBG("path: %s", path);
274 proxy = g_dbus_proxy_new_sync(connection,
275 G_DBUS_PROXY_FLAGS_NONE, NULL,
276 BT_HAL_BLUEZ_NAME, path,
277 BT_HAL_AGENT_INTERFACE, NULL, &error);
280 ERR("Unable to create proxy");
282 ERR("Error: %s", error->message);
283 g_clear_error(&error);
285 priv->busname = NULL;
287 priv->busname = g_strdup(g_dbus_proxy_get_name(proxy));
288 g_object_unref(proxy);
289 DBG("Busname: %s", priv->busname);
294 void _gap_agent_reset_dbus(GapAgentPrivate *agent)
296 GapAgentPrivate *priv = agent;
298 /* Fix : NULL_RETURNS */
302 __gap_agent_unregister(agent);
304 if (gap_agent_id > 0) {
307 g_dbus_connection_unregister_object(connection,
313 if (priv->osp_servers) {
314 __gap_agent_remove_osp_servers(priv->osp_servers);
315 g_slist_free(priv->osp_servers);
316 priv->osp_servers = NULL;
319 g_object_ref(priv->adapter);
320 priv->adapter = NULL;
325 g_free(priv->busname);
326 priv->busname = NULL;
329 gchar* _gap_agent_get_path(GapAgentPrivate *agent)
331 GapAgentPrivate *priv = agent;
333 /* Fix : NULL_RETURNS */
340 gboolean _gap_agent_is_canceled(GapAgentPrivate *agent)
342 GapAgentPrivate *priv = agent;
344 /* Fix : NULL_RETURNS */
348 return priv->canceled;
351 void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value)
353 GapAgentPrivate *priv = agent;
355 /* Fix : NULL_RETURNS */
359 priv->canceled = value;
362 static gboolean __gap_agent_unregister(GapAgentPrivate *agent)
364 GapAgentPrivate *priv = agent;
365 GDBusProxy *agent_manager;
366 GError *error = NULL;
369 if (priv == NULL || priv->path == NULL|| connection == NULL )
372 if (priv->agent_manager == NULL) {
373 agent_manager = g_dbus_proxy_new_sync(connection,
374 G_DBUS_PROXY_FLAGS_NONE, NULL,
375 BT_HAL_BLUEZ_NAME, BT_HAL_BLUEZ_PATH,
376 BT_HAL_AGENT_MANAGER_INTERFACE, NULL, &error);
377 if (!agent_manager) {
379 ERR("Unable to create proxy: %s", error->message);
380 g_clear_error(&error);
385 agent_manager = priv->agent_manager;
388 reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
389 g_variant_new("o", priv->path),
390 G_DBUS_CALL_FLAGS_NONE, -1,
392 g_object_unref(agent_manager);
393 priv->agent_manager = NULL;
396 ERR("Agent unregistration failed");
398 ERR("Agent unregistration failed: errCode[%x], message[%s]",
399 error->code, error->message);
400 g_clear_error(&error);
404 g_variant_unref(reply);
409 static GDBusNodeInfo *__bt_service_create_method_node_info
410 (const gchar *introspection_data)
413 GDBusNodeInfo *node_info = NULL;
415 if (introspection_data == NULL)
418 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
421 ERR("Unable to create node: %s", err->message);
427 static void __bt_gap_agent_method(GDBusConnection *connection,
429 const gchar *object_path,
430 const gchar *interface_name,
431 const gchar *method_name,
432 GVariant *parameters,
433 GDBusMethodInvocation *invocation,
439 DBG("Method[%s] Object Path[%s] Interface Name[%s]",
440 method_name, object_path, interface_name);
443 if (g_strcmp0(method_name, "RequestPinCode") == 0) {
444 GapAgentPrivate *agent = user_data;
445 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
449 GDBusConnection *conn;
454 g_variant_get(parameters, "(&o)", &path);
455 DBG("Request pin code, Device Path :%s", path);
458 if (g_strcmp0(sender, agent->busname) != 0)
462 if (!agent->cb.passkey_func)
464 conn = _bt_get_system_gconn();
467 device = g_dbus_proxy_new_sync(conn,
468 G_DBUS_PROXY_FLAGS_NONE, NULL,
469 BT_HAL_BLUEZ_NAME, path,
470 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
472 ERR("Fail to make device proxy");
473 g_dbus_method_invocation_return_error(invocation,
474 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
475 "No proxy for device");
477 ERR("Unable to create proxy: %s", err->message);
483 agent->exec_type = GAP_AGENT_EXEC_PAIRING;
484 agent->reply_context = invocation;
486 addr = strstr(path, "dev_");
490 g_strlcpy(agent->pairing_addr, addr, sizeof(agent->pairing_addr));
492 while ((pos = strchr(agent->pairing_addr, '_')) != NULL) {
496 agent->cb.pincode_func(agent, device);
497 g_object_unref(device);
499 } else if (g_strcmp0(method_name, "RequestPasskey") == 0) {
500 GapAgentPrivate *priv = user_data;
501 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
505 GDBusConnection *conn;
510 g_variant_get(parameters, "(&o)", &path);
511 DBG("Request passkey : sender %s priv->busname %s Device Path :%s",
512 sender, priv->busname, path);
514 if (g_strcmp0(sender, agent->busname) != 0)
517 if (!priv->cb.passkey_func)
519 conn = _bt_get_system_gconn();
523 device = g_dbus_proxy_new_sync(conn,
524 G_DBUS_PROXY_FLAGS_NONE, NULL,
525 BT_HAL_BLUEZ_NAME, path,
526 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
529 ERR("Fail to make device proxy");
531 g_dbus_method_invocation_return_error(invocation,
532 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
533 "No proxy for device");
535 ERR("Unable to create proxy: %s", err->message);
540 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
541 priv->reply_context = invocation;
543 addr = strstr(path, "dev_");
547 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
549 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
553 priv->cb.passkey_func(priv, device);
554 g_object_unref(device);
556 } else if (g_strcmp0(method_name, "DisplayPasskey") == 0) {
557 GapAgentPrivate *priv = user_data;
558 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
563 GDBusConnection *conn;
567 g_variant_get(parameters, "(&ouq)", &path, &passkey, &entered);
568 DBG("Request passkey display :sender %s priv->busname %s"
569 " Device Path :%s, Passkey: %d, Entered: %d",
570 sender, priv->busname, path, passkey, entered);
571 /* Do not show popup for Key event while typing*/
575 if (g_strcmp0(sender, agent->busname) != 0)
578 if (!priv->cb.display_func)
581 conn = _bt_get_system_gconn();
584 device = g_dbus_proxy_new_sync(conn,
585 G_DBUS_PROXY_FLAGS_NONE, NULL,
586 BT_HAL_BLUEZ_NAME, path,
587 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
589 ERR("Fail to make device proxy");
591 g_dbus_method_invocation_return_error(invocation,
592 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
593 "No proxy for device");
595 ERR("Unable to create proxy: %s", err->message);
600 g_dbus_method_invocation_return_value(invocation, NULL);
601 priv->cb.display_func(priv, device, passkey);
602 g_object_unref(device);
604 } else if (g_strcmp0(method_name, "RequestConfirmation") == 0) {
605 GapAgentPrivate *priv = user_data;
606 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
611 GDBusConnection *conn;
616 g_variant_get(parameters, "(&ou)", &path, &passkey);
617 DBG("Request passkey confirmation, Device Path :%s, Passkey: %d",
620 DBG("Sender: [%s] priv->busname: [%s]", sender, priv->busname);
622 if (g_strcmp0(sender, agent->busname) != 0)
625 DBG("priv->cb.confirm_func [%p]", priv->cb.confirm_func);
626 if (!priv->cb.confirm_func)
628 conn = _bt_get_system_gconn();
631 device = g_dbus_proxy_new_sync(conn,
632 G_DBUS_PROXY_FLAGS_NONE, NULL,
633 BT_HAL_BLUEZ_NAME, path,
634 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
636 ERR("Fail to make device proxy");
637 g_dbus_method_invocation_return_error(invocation,
638 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
639 "No proxy for device");
641 ERR("Unable to create proxy: %s", err->message);
646 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
647 priv->reply_context = invocation;
648 addr = strstr(path, "dev_");
652 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
654 while ((pos = strchr(priv->pairing_addr, '_')) != NULL) {
659 DBG("Pairing address [%s]", priv->pairing_addr);
660 priv->cb.confirm_func(priv, device, passkey);
661 g_object_unref(device);
663 } else if (g_strcmp0(method_name, "AuthorizeService") == 0) {
664 GapAgentPrivate *priv = user_data;
665 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
667 GDBusConnection *conn;
675 g_variant_get(parameters, "(&o&s)", &path, &uuid);
676 DBG("Request authorization :sender %s priv->busname %s "
677 "Device Path :%s UUID: %s",
678 sender, priv->busname, path, uuid);
681 if (g_strcmp0(sender, agent->busname) != 0)
685 if (!priv->cb.authorize_func)
688 conn = _bt_get_system_gconn();
692 device = g_dbus_proxy_new_sync(conn,
693 G_DBUS_PROXY_FLAGS_NONE, NULL,
694 BT_HAL_BLUEZ_NAME, path,
695 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
698 ERR("Fail to make device proxy");
700 g_dbus_method_invocation_return_error(invocation,
701 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
702 "No proxy for device");
705 ERR("Unable to create proxy: %s", err->message);
712 priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
713 priv->reply_context = invocation;
715 addr = strstr(path, "dev_");
719 g_strlcpy(priv->authorize_addr, addr,
720 sizeof(priv->authorize_addr));
722 while ((pos = strchr(priv->authorize_addr, '_')) != NULL) {
727 priv->cb.authorize_func(priv, device, uuid);
729 g_object_unref(device);
731 } else if (g_strcmp0(method_name, "RequestAuthorization") == 0) {
732 g_dbus_method_invocation_return_value(invocation, NULL);
733 } else if (g_strcmp0(method_name, "ConfirmModeChange") == 0) {
734 g_dbus_method_invocation_return_value(invocation, NULL);
735 } else if (g_strcmp0(method_name, "Cancel") == 0) {
736 GapAgentPrivate *priv = user_data;
737 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
741 DBG("Cancelled : agent %p sender %s", sender);
743 if (g_strcmp0(sender, agent->busname) != 0)
746 if (priv->cb.authorization_cancel_func &&
747 priv->exec_type == GAP_AGENT_EXEC_AUTHORZATION) {
748 priv->cb.authorization_cancel_func(priv,
749 priv->authorize_addr);
750 memset(priv->authorize_addr, 0x00,
751 sizeof(priv->authorize_addr));
752 } else if (priv->cb.pairing_cancel_func &&
753 priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
754 priv->cb.pairing_cancel_func(priv,
756 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
758 if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
759 priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
760 priv->reply_context != NULL) {
762 g_dbus_method_invocation_return_error(priv->reply_context,
763 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
764 "Rejected by remote cancel");
767 /* Canceled flag is set when user cancels pairing request
768 * Since here bluez has cancelled pairing request, we set the flag to false
770 priv->canceled = FALSE;
771 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
772 priv->reply_context = NULL;
774 } else if (g_strcmp0(method_name, "Release") == 0) {
775 GapAgentPrivate *priv = user_data;
776 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
781 DBG("Released : sender %s\n", sender);
784 if (g_strcmp0(sender, agent->busname) != 0)
788 g_dbus_method_invocation_return_value(invocation, NULL);
791 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
792 priv->reply_context = NULL;
794 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
795 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
798 } else if (g_strcmp0(method_name, "GetDiscoverableTimeout") == 0) {
800 } else if (g_strcmp0(method_name, "ReplyPinCode") == 0) {
801 GapAgentPrivate *priv = user_data;
802 const char *pin_code;
805 g_variant_get(parameters, "(u&s)", &accept, &pin_code);
806 DBG("Accept: %d PinCode: %s", accept, pin_code);
807 gap_agent_reply_pin_code(priv, accept, pin_code, invocation);
808 } else if (g_strcmp0(method_name, "ReplyPasskey") == 0) {
809 GapAgentPrivate *priv = user_data;
813 g_variant_get(parameters, "(u&s)", &accept, &passkey);
814 DBG("Accept: %d PinCode: %s", accept, passkey);
815 gap_agent_reply_passkey(priv, accept, passkey, invocation);
816 } else if (g_strcmp0(method_name, "ReplyConfirmation") == 0) {
817 GapAgentPrivate *priv = user_data;
820 g_variant_get(parameters, "(u)", &accept);
821 DBG("Accept: %d", accept);
822 gap_agent_reply_confirmation(priv, accept, invocation);
823 } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
824 GapAgentPrivate *priv = user_data;
827 g_variant_get(parameters, "(u)", &accept);
828 DBG("Accept: %d", accept);
829 gap_agent_reply_authorize(priv, accept, invocation);
834 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
835 GDBusMethodInvocation *context)
840 GapAgentPrivate *priv = agent;
842 /* Fix : NULL_RETURNS */
846 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
847 priv->reply_context != NULL) {
848 if (accept == GAP_AGENT_ACCEPT) {
849 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
850 priv->canceled = FALSE;
853 case GAP_AGENT_CANCEL:
854 g_dbus_method_invocation_return_error(priv->reply_context,
855 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
857 priv->canceled = TRUE;
859 case GAP_AGENT_TIMEOUT:
860 case GAP_AGENT_REJECT:
862 g_dbus_method_invocation_return_error(priv->reply_context,
863 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
864 "Confirmation request rejected");
865 priv->canceled = FALSE;
871 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
872 priv->reply_context = NULL;
873 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
879 gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
880 const char *pin_code,
881 GDBusMethodInvocation *context)
884 GapAgentPrivate *priv = agent;
886 /* Fix : NULL_RETURNS */
890 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
891 priv->reply_context != NULL) {
892 if (accept == GAP_AGENT_ACCEPT) {
893 g_dbus_method_invocation_return_value(priv->reply_context,
894 g_variant_new("(s)", pin_code));
895 priv->canceled = FALSE;
898 case GAP_AGENT_CANCEL:
899 g_dbus_method_invocation_return_error(priv->reply_context,
900 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
902 priv->canceled = TRUE;
904 case GAP_AGENT_TIMEOUT:
905 case GAP_AGENT_REJECT:
907 g_dbus_method_invocation_return_error(priv->reply_context,
908 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
909 "Pairing request rejected");
910 priv->canceled = FALSE;
915 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
916 priv->reply_context = NULL;
917 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
923 gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
925 GDBusMethodInvocation *context)
928 GapAgentPrivate *priv = agent;
930 /* Fix : NULL_RETURNS */
934 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
935 priv->reply_context != NULL) {
936 if (accept == GAP_AGENT_ACCEPT) {
937 guint pass_key = atoi(passkey);
938 g_dbus_method_invocation_return_value(priv->reply_context,
939 g_variant_new("(u)", pass_key));
940 priv->canceled = FALSE;
943 case GAP_AGENT_CANCEL:
944 g_dbus_method_invocation_return_error(priv->reply_context,
945 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
947 priv->canceled = TRUE;
949 case GAP_AGENT_TIMEOUT:
950 case GAP_AGENT_REJECT:
952 g_dbus_method_invocation_return_error(priv->reply_context,
953 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
954 "Passkey request rejected");
955 priv->canceled = FALSE;
961 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
962 priv->reply_context = NULL;
963 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
969 gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
970 GDBusMethodInvocation *context)
973 GapAgentPrivate *priv = agent;
976 /* Fix : NULL_RETURNS */
980 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
981 priv->reply_context != NULL) {
982 if (accept == GAP_AGENT_ACCEPT) {
983 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
984 } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
985 /* TODO: Enable below logic after set authorization API implementation */
986 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
989 case GAP_AGENT_CANCEL:
990 g_dbus_method_invocation_return_error(priv->reply_context,
991 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
994 case GAP_AGENT_TIMEOUT:
995 case GAP_AGENT_REJECT:
997 g_dbus_method_invocation_return_error(priv->reply_context,
998 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
999 "Authorization request rejected");
1005 g_dbus_method_invocation_return_value(context, NULL);
1009 g_dbus_method_invocation_return_error(context,
1010 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
1015 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
1016 priv->reply_context = NULL;
1017 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));