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"
41 #include "bt-hal-adapter-dbus-handler.h"
42 #include "bt-hal-dbus-common-utils.h"
44 static GDBusConnection *connection = NULL;
47 GAP_AGENT_ERROR_REJECT,
48 GAP_AGENT_ERROR_CANCEL,
49 GAP_AGENT_ERROR_TIMEOUT,
52 #define AGENT_ALREADY_EXIST 0x24
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);
80 static gint gap_agent_id = -1;
83 static void __bt_hal_free_osp_server(gpointer data)
85 bt_hal_agent_osp_server_t *server = data;
92 /* TODO: Free additional elements if present */
98 static void __bt_hal_gap_agent_remove_osp_servers(GSList *osp_servers)
103 ERR("osp_servers is NULL");
108 g_slist_free_full(osp_servers, __bt_hal_free_osp_server);
114 gboolean _gap_agent_register(GapAgentPrivate *agent)
116 GapAgentPrivate *priv = agent;
117 GDBusProxy *agent_manager;
118 GError *error = NULL;
126 if (priv->agent_manager == NULL) {
127 agent_manager = g_dbus_proxy_new_sync(connection,
128 G_DBUS_PROXY_FLAGS_NONE, NULL,
129 BT_HAL_BLUEZ_NAME, BT_HAL_BLUEZ_PATH,
130 BT_HAL_AGENT_MANAGER_INTERFACE, NULL, &error);
131 if (!agent_manager) {
133 ERR("Unable to create proxy: %s", error->message);
134 g_clear_error(&error);
139 agent_manager = priv->agent_manager;
142 reply = g_dbus_proxy_call_sync(agent_manager, "RegisterAgent",
143 #ifdef TIZEN_BT_IO_CAPA_NO_INPUT_OUTPUT
144 g_variant_new("(os)", priv->path, "NoInputNoOutput"),
146 g_variant_new("(os)", priv->path, "DisplayYesNo"),
148 G_DBUS_CALL_FLAGS_NONE, -1,
151 ERR("Agent registration failed");
153 ERR("Agent registration failed: errCode[%x], message[%s]",
154 error->code, error->message);
156 if (error->code == AGENT_ALREADY_EXIST) {
157 DBG("Agent is already registered");
158 g_clear_error(&error);
160 g_clear_error(&error);
161 g_object_unref(agent_manager);
162 priv->agent_manager = NULL;
167 g_variant_unref(reply);
170 /* Set the defalut agent */
171 DBG("agent_manager[%p] priv->path[%s]", agent_manager, priv->path);
172 reply = g_dbus_proxy_call_sync(agent_manager, "RequestDefaultAgent",
173 g_variant_new("(o)", priv->path),
174 G_DBUS_CALL_FLAGS_NONE, -1,
177 ERR("Request Default Agent failed");
179 ERR("Request Default Agent failed: errCode[%x], message[%s]",
180 error->code, error->message);
181 g_clear_error(&error);
183 g_object_unref(agent_manager);
184 priv->agent_manager = NULL;
187 g_variant_unref(reply);
189 priv->agent_manager = agent_manager;
194 static const gchar gap_agent_bluez_introspection_xml[] =
196 " <interface name='org.bluez.Agent1'>"
197 " <method name='RequestPinCode'>"
198 " <arg type='o' name='device' direction='in'/>"
199 " <arg type='s' name='pincode' direction='out'/>"
201 " <method name='RequestPasskey'>"
202 " <arg type='o' name='device' direction='in'/>"
203 " <arg type='u' name='passkey' direction='out'/>"
205 " <method name='DisplayPasskey'>"
206 " <arg type='o' name='device' direction='in'/>"
207 " <arg type='u' name='passkey' direction='in'/>"
208 " <arg type='q' name='entered' direction='in'/>"
210 " <method name='RequestConfirmation'>"
211 " <arg type='o' name='device' direction='in'/>"
212 " <arg type='u' name='passkey' direction='in'/>"
214 " <method name='RequestAuthorization'>"
215 " <arg type='o' name='device' direction='in'/>"
217 " <method name='AuthorizeService'>"
218 " <arg type='o' name='device' direction='in'/>"
219 " <arg type='s' name='uuid' direction='in'/>"
221 " <method name='Cancel'>"
223 " <method name='Release'>"
225 " <method name='ReplyPinCode'>"
226 " <arg type='u' name='accept' direction='in'/>"
227 " <arg type='s' name='pincode' direction='in'/>"
229 " <method name='ReplyPasskey'>"
230 " <arg type='u' name='accept' direction='in'/>"
231 " <arg type='s' name='passkey' direction='in'/>"
233 " <method name='ReplyConfirmation'>"
234 " <arg type='u' name='accept' direction='in'/>"
236 " <method name='ReplyAuthorize'>"
237 " <arg type='u' name='accept' direction='in'/>"
239 " <method name='ConfirmModeChange'>"
240 " <arg type='s' name='mode' direction='in'/>"
242 " <method name='GetDiscoverableTimeout'>"
243 " <arg type='u' name='timeout' direction='out'/>"
249 static const GDBusInterfaceVTable method_table = {
250 __bt_gap_agent_method,
255 void _gap_agent_setup_dbus(GapAgentPrivate *agent, GAP_AGENT_FUNC_CB *func_cb,
259 GapAgentPrivate *priv = agent;
261 GDBusNodeInfo *node_info;
262 GError *error = NULL;
265 priv->path = g_strdup(path);
267 node_info = __bt_service_create_method_node_info(
268 gap_agent_bluez_introspection_xml);
269 if (node_info == NULL)
272 DBG("path is [%s]", path);
274 connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
277 ERR("Unable to connect to gdbus: %s", error->message);
278 g_clear_error(&error);
283 if (gap_agent_id == -1) {
284 gap_agent_id = g_dbus_connection_register_object(connection, path,
285 node_info->interfaces[0],
290 g_dbus_node_info_unref(node_info);
292 if (gap_agent_id == 0) {
293 ERR("Failed to register for Path: %s", path);
295 ERR("Failed to register: %s", error->message);
296 g_clear_error(&error);
301 memcpy(&priv->cb, func_cb, sizeof(GAP_AGENT_FUNC_CB));
303 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
304 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
305 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
306 priv->reply_context = NULL;
308 DBG("path: %s", path);
310 proxy = g_dbus_proxy_new_sync(connection,
311 G_DBUS_PROXY_FLAGS_NONE, NULL,
312 BT_HAL_BLUEZ_NAME, path,
313 BT_HAL_AGENT_INTERFACE, NULL, &error);
316 ERR("Unable to create proxy");
318 ERR("Error: %s", error->message);
319 g_clear_error(&error);
321 priv->busname = NULL;
323 priv->busname = g_strdup(g_dbus_proxy_get_name(proxy));
324 g_object_unref(proxy);
325 DBG("Busname: %s", priv->busname);
330 void _gap_agent_reset_dbus(GapAgentPrivate *agent)
332 GapAgentPrivate *priv = agent;
334 /* Fix : NULL_RETURNS */
338 __gap_agent_unregister(agent);
340 if (gap_agent_id > 0) {
343 g_dbus_connection_unregister_object(connection,
349 if (priv->osp_servers)
350 __bt_hal_gap_agent_remove_osp_servers(priv->osp_servers);
353 g_object_ref(priv->adapter);
354 priv->adapter = NULL;
359 g_free(priv->busname);
360 priv->busname = NULL;
363 gchar* _gap_agent_get_path(GapAgentPrivate *agent)
365 GapAgentPrivate *priv = agent;
367 /* Fix : NULL_RETURNS */
374 gboolean _gap_agent_is_canceled(GapAgentPrivate *agent)
376 GapAgentPrivate *priv = agent;
378 /* Fix : NULL_RETURNS */
382 return priv->canceled;
385 void _gap_agent_set_canceled(GapAgentPrivate *agent, gboolean value)
387 GapAgentPrivate *priv = agent;
389 /* Fix : NULL_RETURNS */
393 priv->canceled = value;
396 static gboolean __gap_agent_unregister(GapAgentPrivate *agent)
398 GapAgentPrivate *priv = agent;
399 GDBusProxy *agent_manager;
400 GError *error = NULL;
403 if (priv == NULL || priv->path == NULL || connection == NULL)
406 if (priv->agent_manager == NULL) {
407 agent_manager = g_dbus_proxy_new_sync(connection,
408 G_DBUS_PROXY_FLAGS_NONE, NULL,
409 BT_HAL_BLUEZ_NAME, BT_HAL_BLUEZ_PATH,
410 BT_HAL_AGENT_MANAGER_INTERFACE, NULL, &error);
411 if (!agent_manager) {
413 ERR("Unable to create proxy: %s", error->message);
414 g_clear_error(&error);
419 agent_manager = priv->agent_manager;
422 reply = g_dbus_proxy_call_sync(agent_manager, "UnregisterAgent",
423 g_variant_new("o", priv->path),
424 G_DBUS_CALL_FLAGS_NONE, -1,
426 g_object_unref(agent_manager);
427 priv->agent_manager = NULL;
430 ERR("Agent unregistration failed");
432 ERR("Agent unregistration failed: errCode[%x], message[%s]",
433 error->code, error->message);
434 g_clear_error(&error);
438 g_variant_unref(reply);
443 static GDBusNodeInfo *__bt_service_create_method_node_info
444 (const gchar *introspection_data)
447 GDBusNodeInfo *node_info = NULL;
449 if (introspection_data == NULL)
452 node_info = g_dbus_node_info_new_for_xml(introspection_data, &err);
455 ERR("Unable to create node: %s", err->message);
461 static void __bt_gap_agent_method(GDBusConnection *connection,
463 const gchar *object_path,
464 const gchar *interface_name,
465 const gchar *method_name,
466 GVariant *parameters,
467 GDBusMethodInvocation *invocation,
473 DBG("Method[%s] Object Path[%s] Interface Name[%s]",
474 method_name, object_path, interface_name);
477 if (g_strcmp0(method_name, "RequestPinCode") == 0) {
478 GapAgentPrivate *agent = user_data;
482 GDBusConnection *conn;
487 g_variant_get(parameters, "(&o)", &path);
488 DBG("Request pin code, Device Path :%s", path);
491 if (g_strcmp0(sender, agent->busname) != 0)
495 if (!agent->cb.passkey_func)
497 conn = _bt_hal_get_system_gconn();
500 device = g_dbus_proxy_new_sync(conn,
501 G_DBUS_PROXY_FLAGS_NONE, NULL,
502 BT_HAL_BLUEZ_NAME, path,
503 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
505 ERR("Fail to make device proxy");
506 g_dbus_method_invocation_return_error(invocation,
507 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
508 "No proxy for device");
510 ERR("Unable to create proxy: %s", err->message);
516 agent->exec_type = GAP_AGENT_EXEC_PAIRING;
517 agent->reply_context = invocation;
519 addr = strstr(path, "dev_");
523 g_strlcpy(agent->pairing_addr, addr, sizeof(agent->pairing_addr));
525 while ((pos = strchr(agent->pairing_addr, '_')) != NULL)
528 agent->cb.pincode_func(agent, device);
529 g_object_unref(device);
531 } else if (g_strcmp0(method_name, "RequestPasskey") == 0) {
532 GapAgentPrivate *priv = user_data;
536 GDBusConnection *conn;
541 g_variant_get(parameters, "(&o)", &path);
542 DBG("Request passkey : sender %s priv->busname %s Device Path :%s",
543 sender, priv->busname, path);
545 if (g_strcmp0(sender, agent->busname) != 0)
548 if (!priv->cb.passkey_func)
550 conn = _bt_hal_get_system_gconn();
554 device = g_dbus_proxy_new_sync(conn,
555 G_DBUS_PROXY_FLAGS_NONE, NULL,
556 BT_HAL_BLUEZ_NAME, path,
557 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
560 ERR("Fail to make device proxy");
562 g_dbus_method_invocation_return_error(invocation,
563 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
564 "No proxy for device");
566 ERR("Unable to create proxy: %s", err->message);
571 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
572 priv->reply_context = invocation;
574 addr = strstr(path, "dev_");
578 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
580 while ((pos = strchr(priv->pairing_addr, '_')) != NULL)
583 priv->cb.passkey_func(priv, device);
584 g_object_unref(device);
586 } else if (g_strcmp0(method_name, "DisplayPasskey") == 0) {
587 GapAgentPrivate *priv = user_data;
592 GDBusConnection *conn;
596 g_variant_get(parameters, "(&ouq)", &path, &passkey, &entered);
597 DBG("Request passkey display :sender %s priv->busname %s"
598 " Device Path :%s, Passkey: %d, Entered: %d",
599 sender, priv->busname, path, passkey, entered);
600 /* Do not show popup for Key event while typing*/
604 if (g_strcmp0(sender, agent->busname) != 0)
607 if (!priv->cb.display_func)
610 conn = _bt_hal_get_system_gconn();
613 device = g_dbus_proxy_new_sync(conn,
614 G_DBUS_PROXY_FLAGS_NONE, NULL,
615 BT_HAL_BLUEZ_NAME, path,
616 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
618 ERR("Fail to make device proxy");
620 g_dbus_method_invocation_return_error(invocation,
621 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
622 "No proxy for device");
624 ERR("Unable to create proxy: %s", err->message);
629 g_dbus_method_invocation_return_value(invocation, NULL);
630 priv->cb.display_func(priv, device, passkey);
631 g_object_unref(device);
633 } else if (g_strcmp0(method_name, "RequestConfirmation") == 0) {
634 GapAgentPrivate *priv = user_data;
639 GDBusConnection *conn;
644 g_variant_get(parameters, "(&ou)", &path, &passkey);
645 DBG("Request passkey confirmation, Device Path :%s, Passkey: %d",
648 DBG("Sender: [%s] priv->busname: [%s]", sender, priv->busname);
650 if (g_strcmp0(sender, agent->busname) != 0)
653 DBG("priv->cb.confirm_func [%p]", priv->cb.confirm_func);
654 if (!priv->cb.confirm_func)
656 conn = _bt_hal_get_system_gconn();
659 device = g_dbus_proxy_new_sync(conn,
660 G_DBUS_PROXY_FLAGS_NONE, NULL,
661 BT_HAL_BLUEZ_NAME, path,
662 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
664 ERR("Fail to make device proxy");
665 g_dbus_method_invocation_return_error(invocation,
666 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
667 "No proxy for device");
669 ERR("Unable to create proxy: %s", err->message);
674 priv->exec_type = GAP_AGENT_EXEC_PAIRING;
675 priv->reply_context = invocation;
676 addr = strstr(path, "dev_");
680 g_strlcpy(priv->pairing_addr, addr, sizeof(priv->pairing_addr));
682 while ((pos = strchr(priv->pairing_addr, '_')) != NULL)
686 DBG("Pairing address [%s]", priv->pairing_addr);
687 priv->cb.confirm_func(priv, device, passkey);
688 g_object_unref(device);
690 } else if (g_strcmp0(method_name, "AuthorizeService") == 0) {
691 GapAgentPrivate *priv = user_data;
693 GDBusConnection *conn;
701 g_variant_get(parameters, "(&o&s)", &path, &uuid);
702 DBG("Request authorization :sender %s priv->busname %s "
703 "Device Path :%s UUID: %s",
704 sender, priv->busname, path, uuid);
707 if (g_strcmp0(sender, agent->busname) != 0)
711 if (!priv->cb.authorize_func)
714 conn = _bt_hal_get_system_gconn();
718 device = g_dbus_proxy_new_sync(conn,
719 G_DBUS_PROXY_FLAGS_NONE, NULL,
720 BT_HAL_BLUEZ_NAME, path,
721 BT_HAL_PROPERTIES_INTERFACE, NULL, &err);
724 ERR("Fail to make device proxy");
726 g_dbus_method_invocation_return_error(invocation,
727 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
728 "No proxy for device");
731 ERR("Unable to create proxy: %s", err->message);
738 priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
739 priv->reply_context = invocation;
741 addr = strstr(path, "dev_");
745 g_strlcpy(priv->authorize_addr, addr,
746 sizeof(priv->authorize_addr));
748 while ((pos = strchr(priv->authorize_addr, '_')) != NULL)
752 priv->cb.authorize_func(priv, device, uuid);
754 g_object_unref(device);
756 } else if (g_strcmp0(method_name, "RequestAuthorization") == 0) {
757 g_dbus_method_invocation_return_value(invocation, NULL);
758 } else if (g_strcmp0(method_name, "ConfirmModeChange") == 0) {
759 g_dbus_method_invocation_return_value(invocation, NULL);
760 } else if (g_strcmp0(method_name, "Cancel") == 0) {
761 GapAgentPrivate *priv = user_data;
765 DBG("Cancelled : agent %p sender %p", priv, sender);
767 if (g_strcmp0(sender, agent->busname) != 0)
770 if (priv->cb.authorization_cancel_func &&
771 priv->exec_type == GAP_AGENT_EXEC_AUTHORZATION) {
772 DBG("Call GAP agent cancel Authorization method.");
773 priv->cb.authorization_cancel_func(priv,
774 priv->authorize_addr);
775 memset(priv->authorize_addr, 0x00,
776 sizeof(priv->authorize_addr));
777 } else if (priv->cb.pairing_cancel_func &&
778 priv->exec_type == GAP_AGENT_EXEC_PAIRING) {
779 DBG("Call GAP agent cancel Pairing method.");
780 priv->cb.pairing_cancel_func(priv,
782 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
784 if (priv->exec_type != GAP_AGENT_EXEC_CONFIRM_MODE &&
785 priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
786 priv->reply_context != NULL) {
788 g_dbus_method_invocation_return_error(priv->reply_context,
789 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
790 "Rejected by remote cancel");
793 /* Canceled flag is set when user cancels pairing request
794 * Since here bluez has cancelled pairing request, we set the flag to false
796 priv->canceled = FALSE;
797 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
798 priv->reply_context = NULL;
800 } else if (g_strcmp0(method_name, "Release") == 0) {
801 GapAgentPrivate *priv = user_data;
806 DBG("Released : sender %s\n", sender);
809 if (g_strcmp0(sender, agent->busname) != 0)
813 g_dbus_method_invocation_return_value(invocation, NULL);
816 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
817 priv->reply_context = NULL;
819 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
820 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
823 } else if (g_strcmp0(method_name, "GetDiscoverableTimeout") == 0) {
825 } else if (g_strcmp0(method_name, "ReplyPinCode") == 0) {
826 GapAgentPrivate *priv = user_data;
827 const char *pin_code;
830 g_variant_get(parameters, "(u&s)", &accept, &pin_code);
831 DBG("Accept: %d PinCode: %s", accept, pin_code);
832 gap_agent_reply_pin_code(priv, accept, pin_code, invocation);
833 } else if (g_strcmp0(method_name, "ReplyPasskey") == 0) {
834 GapAgentPrivate *priv = user_data;
838 g_variant_get(parameters, "(u&s)", &accept, &passkey);
839 DBG("Accept: %d PinCode: %s", accept, passkey);
840 gap_agent_reply_passkey(priv, accept, passkey, invocation);
841 } else if (g_strcmp0(method_name, "ReplyConfirmation") == 0) {
842 GapAgentPrivate *priv = user_data;
845 g_variant_get(parameters, "(u)", &accept);
846 DBG("Accept: %d", accept);
847 gap_agent_reply_confirmation(priv, accept, invocation);
848 } else if (g_strcmp0(method_name, "ReplyAuthorize") == 0) {
849 GapAgentPrivate *priv = user_data;
852 g_variant_get(parameters, "(u)", &accept);
853 DBG("Accept: %d", accept);
854 gap_agent_reply_authorize(priv, accept, invocation);
859 gboolean gap_agent_reply_confirmation(GapAgentPrivate *agent, const guint accept,
860 GDBusMethodInvocation *context)
865 GapAgentPrivate *priv = agent;
867 /* Fix : NULL_RETURNS */
871 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
872 priv->reply_context != NULL) {
873 if (accept == GAP_AGENT_ACCEPT || accept == GAP_AGENT_ACCEPT_ALWAYS) {
874 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
875 priv->canceled = FALSE;
878 case GAP_AGENT_CANCEL:
879 g_dbus_method_invocation_return_error(priv->reply_context,
880 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
882 priv->canceled = TRUE;
884 case GAP_AGENT_TIMEOUT:
885 case GAP_AGENT_REJECT:
887 g_dbus_method_invocation_return_error(priv->reply_context,
888 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
889 "Confirmation request rejected");
890 priv->canceled = FALSE;
896 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
897 priv->reply_context = NULL;
898 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
904 gboolean gap_agent_reply_pin_code(GapAgentPrivate *agent, const guint accept,
905 const char *pin_code,
906 GDBusMethodInvocation *context)
909 GapAgentPrivate *priv = agent;
911 /* Fix : NULL_RETURNS */
915 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
916 priv->reply_context != NULL) {
917 if (accept == GAP_AGENT_ACCEPT) {
918 g_dbus_method_invocation_return_value(priv->reply_context,
919 g_variant_new("(s)", pin_code));
920 priv->canceled = FALSE;
923 case GAP_AGENT_CANCEL:
924 g_dbus_method_invocation_return_error(priv->reply_context,
925 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
927 priv->canceled = TRUE;
929 case GAP_AGENT_TIMEOUT:
930 case GAP_AGENT_REJECT:
932 g_dbus_method_invocation_return_error(priv->reply_context,
933 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
934 "Pairing request rejected");
935 priv->canceled = FALSE;
940 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
941 priv->reply_context = NULL;
942 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
948 gboolean gap_agent_reply_passkey(GapAgentPrivate *agent, const guint accept,
950 GDBusMethodInvocation *context)
953 GapAgentPrivate *priv = agent;
955 /* Fix : NULL_RETURNS */
959 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
960 priv->reply_context != NULL) {
961 if (accept == GAP_AGENT_ACCEPT) {
962 guint pass_key = atoi(passkey);
963 g_dbus_method_invocation_return_value(priv->reply_context,
964 g_variant_new("(u)", pass_key));
965 priv->canceled = FALSE;
968 case GAP_AGENT_CANCEL:
969 g_dbus_method_invocation_return_error(priv->reply_context,
970 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
972 priv->canceled = TRUE;
974 case GAP_AGENT_TIMEOUT:
975 case GAP_AGENT_REJECT:
977 g_dbus_method_invocation_return_error(priv->reply_context,
978 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
979 "Passkey request rejected");
980 priv->canceled = FALSE;
986 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
987 priv->reply_context = NULL;
988 memset(priv->pairing_addr, 0x00, sizeof(priv->pairing_addr));
994 gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
995 GDBusMethodInvocation *context)
998 GapAgentPrivate *priv = agent;
1001 /* Fix : NULL_RETURNS */
1005 if (priv->exec_type != GAP_AGENT_EXEC_NO_OPERATION &&
1006 priv->reply_context != NULL) {
1007 if (accept == GAP_AGENT_ACCEPT) {
1008 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
1009 } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
1010 /* TODO: Enable below logic after set authorization API implementation */
1011 g_dbus_method_invocation_return_value(priv->reply_context, NULL);
1014 case GAP_AGENT_CANCEL:
1015 g_dbus_method_invocation_return_error(priv->reply_context,
1016 GAP_AGENT_ERROR, GAP_AGENT_ERROR_CANCEL,
1019 case GAP_AGENT_TIMEOUT:
1020 case GAP_AGENT_REJECT:
1022 g_dbus_method_invocation_return_error(priv->reply_context,
1023 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
1024 "Authorization request rejected");
1030 g_dbus_method_invocation_return_value(context, NULL);
1034 g_dbus_method_invocation_return_error(context,
1035 GAP_AGENT_ERROR, GAP_AGENT_ERROR_REJECT,
1040 priv->exec_type = GAP_AGENT_EXEC_NO_OPERATION;
1041 priv->reply_context = NULL;
1042 memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
1049 bt_hal_agent_osp_server_t *_bt_hal_gap_agent_find_osp_server_by_type(GSList *servers, unsigned int type)
1052 bt_hal_agent_osp_server_t *server;
1054 for (l = servers; l != NULL; l = g_slist_next(l)) {
1060 if (type == server->type)
1067 gboolean _bt_hal_gap_agent_register_osp_server(GapAgentPrivate *agent, unsigned int type)
1069 bt_hal_agent_osp_server_t *server;
1073 GapAgentPrivate *priv = agent;
1077 if (type >= BT_OSP_SERVER_MAX)
1080 server = g_malloc0(sizeof(bt_hal_agent_osp_server_t));
1081 server->type = type;
1082 priv->osp_servers = g_slist_append(priv->osp_servers, server);
1088 gboolean _bt_hal_gap_agent_unregister_osp_server(GapAgentPrivate *agent, unsigned int type)
1090 bt_hal_agent_osp_server_t *server;
1092 GapAgentPrivate *priv = agent;
1098 if (type >= BT_OSP_SERVER_MAX)
1101 server = _bt_hal_gap_agent_find_osp_server_by_type(priv->osp_servers, type);
1105 priv->osp_servers = g_slist_remove(priv->osp_servers, server);
1106 __bt_hal_free_osp_server(server);