Apply auth check logic for hid device 00/218000/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Mon, 18 Nov 2019 10:47:35 +0000 (19:47 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Mon, 18 Nov 2019 10:47:35 +0000 (19:47 +0900)
Change-Id: I64d54609f50a6528f7af65b2f22379bbba753efa
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-oal/bluez_hal/src/bt-hal-agent.c
bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.c
bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.h

index 70d14e4..d84c596 100644 (file)
@@ -101,6 +101,7 @@ static void __bt_hal_agent_release_memory(void);
 static inline void stack_trim(void);
 
 static gboolean __bt_hal_device_is_hid_keyboard(unsigned int dev_class);
+static gboolean __bt_hal_is_hid_device_connectable(void);
 static int __bt_hal_device_generate_passkey(char *passkey, int size);
 static gboolean __bt_hal_device_is_auto_response(uint32_t dev_class,
                const gchar *address, const gchar *name);
@@ -779,12 +780,22 @@ static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *d
                INFO("Device is not Trusted, so prompt user to accept or reject authorization \n");
        }
 
+       if (!strcasecmp(uuid, BT_HAL_HID_UUID)) {
+               gboolean is_connectable = __bt_hal_is_hid_device_connectable();
+               DBG("Automatically %s authorization for HID",
+                       is_connectable ? "accept" : "reject");
+               if (is_connectable == TRUE)
+                       gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT, NULL);
+               else
+                       gap_agent_reply_authorize(agent, GAP_AGENT_REJECT, NULL);
+               goto done;
+       }
+
        if (!strcasecmp(uuid, BT_HAL_HFP_AUDIO_GATEWAY_UUID) ||
                        !strcasecmp(uuid, BT_HAL_HSP_AUDIO_GATEWAY_UUID) ||
                        !strcasecmp(uuid, BT_HAL_HFP_HF_UUID) ||
                        !strcasecmp(uuid, BT_HAL_HSP_HS_UUID) ||
                        !strcasecmp(uuid, BT_HAL_A2DP_PROFILE_UUID) ||
-                       !strcasecmp(uuid, BT_HAL_HID_UUID) ||
                        !strcasecmp(uuid, BT_HAL_HID_DEVICE_UUID) ||
                        !strcasecmp(uuid, BT_HAL_SAP_UUID_OLD) ||
                        !strcasecmp(uuid, BT_HAL_SAP_UUID_NEW) ||
@@ -901,6 +912,38 @@ static gboolean __bt_hal_device_is_hid_keyboard(unsigned int dev_class)
        return FALSE;
 }
 
+static gboolean __bt_hal_is_hid_device_connectable(void)
+{
+       GDBusProxy *proxy = NULL;
+       GVariant *reply = NULL;
+       GError *err = NULL;
+       gboolean connectable = FALSE;
+
+       proxy = _bt_hal_get_hid_agent_proxy();
+       if(proxy == NULL)
+               return FALSE;
+
+       reply = g_dbus_proxy_call_sync(proxy, "IsHidConnectable", NULL,
+                               G_DBUS_CALL_FLAGS_NONE, 2000, NULL, &err);
+       if (reply == NULL) {
+               ERR("Error returned in method call");
+               if (err != NULL) {
+                       ERR("Error message = %s", err->message);
+                       g_error_free(err);
+               }
+               connectable = FALSE;
+       } else {
+               g_variant_get(reply, "(b)", &connectable);
+               g_variant_unref(reply);
+       }
+       g_object_unref(proxy);
+
+       INFO("HID Device is %s",
+                       connectable ? "Connectable" : "Non-connectable");
+
+       return connectable;
+}
+
 static int __bt_hal_device_generate_passkey(char *passkey, int size)
 {
        int i;
index 8528369..aba8e3c 100644 (file)
@@ -72,8 +72,6 @@ struct avrcp_proxy {
 
 struct avrcp_proxy proxy_array[BT_AUDIO_SOURCE_MAX];
 
-static GDBusConnection *system_gconn = NULL;
-
 static guint bus_id;
 GDBusNodeInfo *new_conn_node;
 static const gchar rfcomm_agent_xml[] =
@@ -90,31 +88,44 @@ static const gchar rfcomm_agent_xml[] =
 "  </interface>"
 "</node>";
 
-GDBusConnection *_bt_hal_gdbus_init_system_gconn(void)
+static GDBusConnection *__bt_hal_init_session_conn(void)
+{
+       if (session_conn == NULL)
+               session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
+
+       return session_conn;
+}
+
+GDBusConnection *_bt_hal_get_session_gconn(void)
+{
+       return (session_conn) ? session_conn : __bt_hal_init_session_conn();
+}
+
+static GDBusConnection *__bt_hal_init_system_gconn(void)
 {
        GError *error = NULL;
 
-       if (system_gconn != NULL)
-               return system_gconn;
+       if (system_conn != NULL)
+               return system_conn;
 
-       system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
-       if (!system_gconn) {
+       if (!system_conn) {
                ERR("Unable to connect to dbus: %s", error->message);
                g_clear_error(&error);
        }
 
-       return system_gconn;
+       return system_conn;
 }
 
-GDBusConnection *_bt_hal_gdbus_get_system_gconn(void)
+GDBusConnection *_bt_hal_get_system_gconn(void)
 {
        GDBusConnection *local_system_gconn = NULL;
        GError *error = NULL;
 
-       if (system_gconn == NULL) {
-               system_gconn = _bt_hal_gdbus_init_system_gconn();
-       } else if (g_dbus_connection_is_closed(system_gconn)) {
+       if (system_conn == NULL) {
+               system_conn = __bt_hal_init_system_gconn();
+       } else if (g_dbus_connection_is_closed(system_conn)) {
 
                local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
@@ -123,10 +134,10 @@ GDBusConnection *_bt_hal_gdbus_get_system_gconn(void)
                        g_clear_error(&error);
                }
 
-               system_gconn = local_system_gconn;
+               system_conn = local_system_gconn;
        }
 
-       return system_gconn;
+       return system_conn;
 }
 
 static GDBusProxy *__bt_hal_init_manager_proxy(void)
@@ -417,14 +428,6 @@ char *_bt_hal_get_transport_device_path(bt_bdaddr_t *bd_addr)
        return transport_path;
 }
 
-static GDBusConnection *__bt_hal_init_system_gconn(void)
-{
-       if (system_conn == NULL)
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-
-       return system_conn;
-}
-
 static GDBusProxy *__bt_hal_init_avrcp_ctrl_proxy(bt_bdaddr_t *bd_addr)
 {
        GDBusProxy *manager_proxy;
@@ -432,7 +435,7 @@ static GDBusProxy *__bt_hal_init_avrcp_ctrl_proxy(bt_bdaddr_t *bd_addr)
        GDBusConnection *gconn = NULL;
        int i;
 
-       gconn = _bt_hal_gdbus_get_system_gconn();
+       gconn = _bt_hal_get_system_gconn();
        if (gconn == NULL)
                return  NULL;
 
@@ -466,24 +469,6 @@ static GDBusProxy *__bt_hal_init_avrcp_ctrl_proxy(bt_bdaddr_t *bd_addr)
        return proxy;
 }
 
-static GDBusConnection *__bt_hal_init_session_conn(void)
-{
-       if (session_conn == NULL)
-               session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
-
-       return session_conn;
-}
-
-GDBusConnection *_bt_hal_get_session_gconn(void)
-{
-       return (session_conn) ? session_conn : __bt_hal_init_session_conn();
-}
-
-GDBusConnection *_bt_hal_get_system_gconn(void)
-{
-       return (system_conn) ? system_conn : __bt_hal_init_system_gconn();
-}
-
 GDBusProxy *_bt_hal_get_manager_proxy(void)
 {
        DBG("+");
@@ -783,6 +768,32 @@ void _bt_hal_deinit_proxys(void)
        }
 }
 
+GDBusProxy *_bt_hal_get_hid_agent_proxy(void)
+{
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *err = NULL;
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL) {
+               ERR("_bt_hal_get_system_gconn failed");
+               return NULL;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                       BT_HAL_HID_SERVICE_NAME, BT_HAL_HID_AGENT_OBJECT_PATH,
+                                       BT_HAL_HID_SERVICE_INTERFACE, NULL, &err);
+       if (proxy == NULL) {
+               if (err != NULL) {
+                       ERR("Unable to create proxy: %s", err->message);
+                       g_clear_error(&err);
+               }
+               return NULL;
+       }
+
+       return proxy;
+}
+
 void _bt_hal_convert_device_path_to_address(const char *device_path,
                char *device_address)
 {
index 7b9e945..edcb24d 100644 (file)
@@ -117,6 +117,10 @@ extern "C" {
 #define BT_HAL_NAME_OWNER_CHANGED "NameOwnerChanged"
 #define BT_HAL_PROPERTIES_CHANGED "PropertiesChanged"
 
+#define BT_HAL_HID_SERVICE_NAME "org.bluez.hid_agent"
+#define BT_HAL_HID_AGENT_OBJECT_PATH "/org/bluez/hid_agent"
+#define BT_HAL_HID_SERVICE_INTERFACE "org.tizen.HidApp"
+
        /**
         * This is Bluetooth error code
         */
@@ -440,8 +444,10 @@ extern "C" {
        gboolean _bt_hal_is_adapter_powered(gboolean *powered);
 
        char *_bt_hal_get_device_object_path(char *address);
-       void _bt_hal_convert_device_path_to_address(const char *device_path, char *device_address);
 
+       GDBusProxy *_bt_hal_get_hid_agent_proxy(void);
+
+       void _bt_hal_convert_device_path_to_address(const char *device_path, char *device_address);
        void _bt_hal_convert_addr_string_to_type(unsigned char *addr, const char *address);
        void _bt_hal_convert_addr_type_to_string(char *address, const unsigned char *addr);
        void _bt_hal_convert_uuid_string_to_type(unsigned char *uuid, const char *device_uuid);