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 DBG("Call GAP agent cancel Authorization method.");
749 priv->cb.authorization_cancel_func(priv,
750 priv->authorize_addr);
751 memset(priv->authorize_addr, 0x00,
752 sizeof(priv->authorize_addr));
753 } else if (priv->cb.pairing_cancel_func &&
754 priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
755 priv->cb.pairing_cancel_func(priv,
757 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
759 if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
760 priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
761 priv->reply_context != NULL) {
763 g_dbus_method_invocation_return_error(priv->reply_context,
764 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
765 "Rejected by remote cancel");
768 /* Canceled flag is set when user cancels pairing request
769 * Since here bluez has cancelled pairing request, we set the flag to false
771 priv->canceled = FALSE;
772 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
773 priv->reply_context = NULL;
775 } else if (g_strcmp0(method_name, "Release") == 0) {
776 GapAgentPrivate *priv = user_data;
777 char *sender = (char *)g_dbus_method_invocation_get_sender(invocation);
782 DBG("Released : sender %s\n", sender);
785 if (g_strcmp0(sender, agent->busname) != 0)
789 g_dbus_method_invocation_return_value(invocation, NULL);
792 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
793 priv->reply_context = NULL;
795 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
796 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
799 } else if (g_strcmp0(method_name, "GetDiscoverableTimeout") == 0) {
801 } else if (g_strcmp0(method_name, "ReplyPinCode") == 0) {
802 GapAgentPrivate *priv = user_data;
803 const char *pin_code;
806 g_variant_get(parameters, "(u&s)", &accept, &pin_code);
807 DBG("Accept: %d PinCode: %s", accept, pin_code);
808 gap_agent_reply_pin_code(priv, accept, pin_code, invocation);
809 } else if (g_strcmp0(method_name, "ReplyPasskey") == 0) {
810 GapAgentPrivate *priv = user_data;
814 g_variant_get(parameters, "(u&s)", &accept, &passkey);
815 DBG("Accept: %d PinCode: %s", accept, passkey);
816 gap_agent_reply_passkey(priv, accept, passkey, invocation);
817 } else if (g_strcmp0(method_name, "ReplyConfirmation") == 0) {
818 GapAgentPrivate *priv = user_data;
821 g_variant_get(parameters, "(u)", &accept);
822 DBG("Accept: %d", accept);
823 gap_agent_reply_confirmation(priv, accept, invocation);
824 } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
825 GapAgentPrivate *priv = user_data;
828 g_variant_get(parameters, "(u)", &accept);
829 DBG("Accept: %d", accept);
830 gap_agent_reply_authorize(priv, accept, invocation);
835 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
836 GDBusMethodInvocation *context)
841 GapAgentPrivate *priv = agent;
843 /* Fix : NULL_RETURNS */
847 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
848 priv->reply_context != NULL) {
849 if (accept == GAP_AGENT_ACCEPT) {
850 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
851 priv->canceled = FALSE;
854 case GAP_AGENT_CANCEL:
855 g_dbus_method_invocation_return_error(priv->reply_context,
856 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
858 priv->canceled = TRUE;
860 case GAP_AGENT_TIMEOUT:
861 case GAP_AGENT_REJECT:
863 g_dbus_method_invocation_return_error(priv->reply_context,
864 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
865 "Confirmation request rejected");
866 priv->canceled = FALSE;
872 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
873 priv->reply_context = NULL;
874 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
880 gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
881 const char *pin_code,
882 GDBusMethodInvocation *context)
885 GapAgentPrivate *priv = agent;
887 /* Fix : NULL_RETURNS */
891 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
892 priv->reply_context != NULL) {
893 if (accept == GAP_AGENT_ACCEPT) {
894 g_dbus_method_invocation_return_value(priv->reply_context,
895 g_variant_new("(s)", pin_code));
896 priv->canceled = FALSE;
899 case GAP_AGENT_CANCEL:
900 g_dbus_method_invocation_return_error(priv->reply_context,
901 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
903 priv->canceled = TRUE;
905 case GAP_AGENT_TIMEOUT:
906 case GAP_AGENT_REJECT:
908 g_dbus_method_invocation_return_error(priv->reply_context,
909 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
910 "Pairing request rejected");
911 priv->canceled = FALSE;
916 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
917 priv->reply_context = NULL;
918 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
924 gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
926 GDBusMethodInvocation *context)
929 GapAgentPrivate *priv = agent;
931 /* Fix : NULL_RETURNS */
935 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
936 priv->reply_context != NULL) {
937 if (accept == GAP_AGENT_ACCEPT) {
938 guint pass_key = atoi(passkey);
939 g_dbus_method_invocation_return_value(priv->reply_context,
940 g_variant_new("(u)", pass_key));
941 priv->canceled = FALSE;
944 case GAP_AGENT_CANCEL:
945 g_dbus_method_invocation_return_error(priv->reply_context,
946 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
948 priv->canceled = TRUE;
950 case GAP_AGENT_TIMEOUT:
951 case GAP_AGENT_REJECT:
953 g_dbus_method_invocation_return_error(priv->reply_context,
954 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
955 "Passkey request rejected");
956 priv->canceled = FALSE;
962 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
963 priv->reply_context = NULL;
964 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
970 gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
971 GDBusMethodInvocation *context)
974 GapAgentPrivate *priv = agent;
977 /* Fix : NULL_RETURNS */
981 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
982 priv->reply_context != NULL) {
983 if (accept == GAP_AGENT_ACCEPT) {
984 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
985 } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
986 /* TODO: Enable below logic after set authorization API implementation */
987 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
990 case GAP_AGENT_CANCEL:
991 g_dbus_method_invocation_return_error(priv->reply_context,
992 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
995 case GAP_AGENT_TIMEOUT:
996 case GAP_AGENT_REJECT:
998 g_dbus_method_invocation_return_error(priv->reply_context,
999 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
1000 "Authorization request rejected");
1006 g_dbus_method_invocation_return_value(context, NULL);
1010 g_dbus_method_invocation_return_error(context,
1011 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
1016 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
1017 priv->reply_context = NULL;
1018 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));