Fix Bluetooth connection authorization 23/148823/2
authorAtul Rai <a.rai@samsung.com>
Mon, 11 Sep 2017 03:42:18 +0000 (09:12 +0530)
committerAtul Rai <a.rai@samsung.com>
Wed, 13 Sep 2017 06:10:06 +0000 (11:40 +0530)
This patch does following:
1/ Remove _bt_send_event() call (send event to bt-api) from BT HAL
2/ Send Audio/Iotivity/SAP/HID etc profile connection authorization
event to bt-service. Accept/Reject logic will be decided in bt-service.

Change-Id: Id56156cdbe456322720ed623b26723f58b4e198a
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/bluez_hal/hardware/bluetooth.h
bt-oal/bluez_hal/inc/bt-hal-utils.h
bt-oal/bluez_hal/src/bt-hal-agent.c
bt-oal/bluez_hal/src/bt-hal-utils.c
bt-oal/include/oal-manager.h
bt-service-adaptation/services/device/bt-service-core-device.c

index 34c2d37..2b05eda 100644 (file)
@@ -390,7 +390,10 @@ typedef enum {
     BT_MAP_SERVICE_ID,              /* Message Access Profile */
     BT_MN_SERVICE_ID,               /* Message Notification Service */
     BT_HDP_SERVICE_ID,              /* Health Device Profile */
-    BT_PCE_SERVICE_ID               /* PhoneBook Access Client*/
+    BT_PCE_SERVICE_ID,              /* PhoneBook Access Client*/
+#ifdef TIZEN_BT_HAL
+    BT_IOTIVITY_SERVICE_ID,         /* Custom IOTIVITY UUID */
+#endif
 } bt_service_id_t;
 
 #define BT_MAX_NUM_UUIDS 32
index 28b0b4c..793bd2e 100644 (file)
@@ -47,6 +47,7 @@ static const char BASE_UUID_CONVERTED[BT_HAL_UUID_128] = {
 #define BT_HAL_HFP_AUDIO_GATEWAY_UUID "0000111f-0000-1000-8000-00805f9b34fb"
 #define BT_HAL_HSP_AUDIO_GATEWAY_UUID "00001112-0000-1000-8000-00805f9b34fb"
 #define BT_HAL_HFP_HF_UUID "0000111e-0000-1000-8000-00805f9b34fb"
+#define BT_HAL_HSP_HS_UUID "00001108-0000-1000-8000-00805f9b34fb"
 #define BT_HAL_A2DP_PROFILE_UUID "0000110d-0000-1000-8000-00805f9b34fb" /* This is A2DP Profile UUID */
 #define BT_HAL_A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb"  /* This is A2DP Profile Role(SRC) UUID */
 #define BT_HAL_A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb"   /* This is A2DP Profile Role(SNK) UUID */
@@ -63,6 +64,12 @@ static const char BASE_UUID_CONVERTED[BT_HAL_UUID_128] = {
 #define BT_HAL_HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
 #define BT_HAL_SAP_UUID_OLD "a49eb41e-cb06-495c-9f4f-bb80a90cdf00"
 #define BT_HAL_SAP_UUID_NEW "a49eb41e-cb06-495c-9f4f-aa80a90cdf4a"
+
+#ifdef TIZEN_BT_HAL
+#define BT_HAL_HID_DEVICE_UUID "00001124-0000-1000-8000-00805f9b43bf"
+#define BT_HAL_IOTIVITY_UUID "12341234-1c25-481f-9dfb-59193d238280"
+#endif
+
 // List of Protocols
 #define BASE                                    0x0000          //Base
 #define SDP                                     0x0001          //Bluetooth Core Specification
index 2b03ccc..e4d6aeb 100644 (file)
@@ -391,51 +391,40 @@ static gboolean __bt_hal_pincode_request(GapAgentPrivate *agent, GDBusProxy *dev
 
        if (!name)
                name = address;
-#ifdef TIZEN_SYSPOPUP_SUPPORTED
 
-       __bt_hal_get_auth_info(reply, (char *)auth_info);
-       if (__bt_hal_device_is_hid_keyboard(device_class)) {
-               DBG("Device is HID Keyboard");
-               char str_passkey[BT_HAL_PASSKEY_MAX_LENGTH + 1] = { 0 };
-               if (__bt_hal_device_generate_passkey(str_passkey,
-                                       BT_HAL_PASSKEY_MAX_LENGTH) != 0) {
-                       gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT,
-                                       "", NULL);
-                       goto done;
-               }
-               gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT,
-                               str_passkey, NULL);
+       if (headed_plugin_info->plugin_headed_enabled) {
+               __bt_hal_get_auth_info(reply, (char *)auth_info);
+               if (__bt_hal_device_is_hid_keyboard(device_class)) {
+                       char str_passkey[BT_HAL_PASSKEY_MAX_LENGTH + 1] = { 0 };
+
+                       DBG("Device is HID Keyboard");
+                       if (__bt_hal_device_generate_passkey(str_passkey,
+                                               BT_HAL_PASSKEY_MAX_LENGTH) != 0) {
+                               gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT,
+                                               "", NULL);
+                               goto done;
+                       }
 
-               DBG("Launch BT Syspopup");
+                       gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT,
+                                       str_passkey, NULL);
 
-               if (headed_plugin_info->plugin_headed_enabled) {
-                       headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_HAL_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
+                       DBG("Launch BT Syspopup");
+                       headed_plugin_info->headed_plugin->bt_launch_system_popup(
+                                       BT_HAL_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
                                        name, auth_info, str_passkey, NULL, _gap_agent_get_path(agent));
-               } else {
-#if TODO_40
-                       GVariant *param = NULL;
-                       param = g_variant_new("(isss)", ret, address, name, str_passkey);
-                       _bt_send_event(BT_ADAPTER_EVENT, BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY, param);
-#endif
-               }
-       } else if (!__bt_hal_device_is_auto_response(device_class, address, name)) {
-               DBG("Device is not of AUto response class, Show PIN Entry");
-               if (headed_plugin_info->plugin_headed_enabled) {
-                       DBG("Show Pin entry");
-                       headed_plugin_info->headed_plugin->bt_launch_system_popup(BT_HAL_AGENT_EVENT_PIN_REQUEST, name, auth_info,
+               } else if (!__bt_hal_device_is_auto_response(device_class, address, name)) {
+                       DBG("Device is not of Auto response class, Show PIN Entry");
+                       headed_plugin_info->headed_plugin->bt_launch_system_popup(
+                                       BT_HAL_AGENT_EVENT_PIN_REQUEST, name, auth_info,
                                        NULL, NULL, _gap_agent_get_path(agent));
                } else {
-                       INFO("Plugin Headed not Enabled");
+                       DBG("Device is of Type Auto response, send event to HAL");
                        __bt_hal_send_pin_request_event(address, name, device_class);
                }
        } else {
-               DBG("Device is of Type Auto response, send event to HAL");
+               INFO("Plugin Headed not Enabled");
                __bt_hal_send_pin_request_event(address, name, device_class);
        }
-#else
-       DBG("PIN CODE request, device class [%u]", device_class);
-       __bt_hal_send_pin_request_event(address, name, device_class);
-#endif
 
 done:
        g_variant_unref(reply);
@@ -737,6 +726,24 @@ 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_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) ||
+#ifdef TIZEN_BT_HAL
+                       !strcasecmp(uuid, BT_HAL_IOTIVITY_UUID) ||
+#endif
+                       !strcasecmp(uuid, BT_HAL_AVRCP_TARGET_UUID)) {
+               DBG("Authorization for UUID: %s, send event", uuid);
+               __bt_hal_send_authorize_request_event(address, uuid);
+               goto done;
+       }
+
 #ifdef TIZEN_BT_HAL
        if (!strcasecmp(uuid, BT_HAL_OPP_UUID) &&
                (NULL != _bt_hal_gap_agent_find_osp_server_by_type(
@@ -810,7 +817,6 @@ static gboolean __bt_hal_pairing_cancel_request(GapAgentPrivate *agent, const ch
         return TRUE;
 }
 
-#ifdef TIZEN_SYSPOPUP_SUPPORTED
 static gboolean __bt_hal_device_is_hid_keyboard(unsigned int dev_class)
 {
        switch ((dev_class & 0x1f00) >> 8) {
@@ -1050,7 +1056,6 @@ static gboolean __bt_hal_device_is_auto_response(uint32_t dev_class,
 
        return TRUE;
 }
-#endif
 
 static GVariant *__bt_hal_service_getall(GDBusProxy *device, const char *interface)
 {
index b1eefc6..4df453d 100644 (file)
@@ -749,6 +749,16 @@ bt_service_id_t _bt_convert_uuid_string_to_service_id(const char *uuid)
                service_id = BT_SAP_SERVICE_ID;
        else if (!strcasecmp(uuid, BT_HAL_SAP_UUID_NEW))
                service_id = BT_SAP_SERVICE_ID;
+       else if (!strcasecmp(uuid, BT_HAL_HSP_HS_UUID))
+               service_id = BT_HSP_HS_SERVICE_ID;
+       else if (!strcasecmp(uuid, BT_HAL_HFP_HF_UUID))
+               service_id = BT_HFP_HS_SERVICE_ID;
+#ifdef TIZEN_BT_HAL
+       else if (!strcasecmp(uuid, BT_HAL_HID_DEVICE_UUID))
+               service_id = BT_HID_SERVICE_ID;
+       else if (!strcasecmp(uuid, BT_HAL_IOTIVITY_UUID))
+               service_id = BT_IOTIVITY_SERVICE_ID;
+#endif
        else
                ERR("Unknwon Service uuid, return BT_RES_SERVICE_ID");
 
@@ -763,7 +773,7 @@ char *_bt_convert_service_id_to_uuid_string(bt_service_id_t service_id)
 
        switch (service_id) {
        case BT_HFP_SERVICE_ID:
-               return g_strdup(BT_HAL_HFP_HF_UUID);
+               return g_strdup(BT_HAL_HFP_AUDIO_GATEWAY_UUID);
        case BT_HSP_SERVICE_ID:
                return g_strdup(BT_HAL_HSP_AUDIO_GATEWAY_UUID);
        case BT_A2DP_SERVICE_ID:
@@ -802,10 +812,16 @@ char *_bt_convert_service_id_to_uuid_string(bt_service_id_t service_id)
        case BT_PANU_SERVICE_ID:
        case BT_VDP_SERVICE_ID:
        case BT_HSP_HS_SERVICE_ID:
+               return g_strdup(BT_HAL_HSP_HS_UUID);
        case BT_HFP_HS_SERVICE_ID:
+               return g_strdup(BT_HAL_HFP_HF_UUID);
        case BT_MN_SERVICE_ID:
        case BT_HDP_SERVICE_ID:
        case BT_PCE_SERVICE_ID:
+#ifdef TIZEN_BT_HAL
+       case BT_IOTIVITY_SERVICE_ID:
+               return g_strdup(BT_HAL_IOTIVITY_UUID);
+#endif
        default:
                ERR("Unknwon Service id: %d, return NULL");
        }
index 91b8644..bbe75f0 100755 (executable)
@@ -76,12 +76,19 @@ typedef enum {
 /* NOTE: If anything changes in bt_service_id_t enum definition of Bluedroid header, change here too */
 typedef enum {
        A2DP_SRC_SERVICE_ID = 3,
-       HFP_HF_SERVICE_ID = 6,
+       HSP_SERVICE_ID = 5,
+       HFP_SERVICE_ID = 6,
        OPP_SERVICE_ID = 7,
        AVRCP_CT_SERVICE_ID = 9,
+       SAP_SERVICE_ID = 17,
        A2DP_SERVICE_ID = 18,
        AVRCP_SERVICE_ID = 19,
-       HID_SERVICE_ID = 20
+       HID_SERVICE_ID = 20,
+       HSP_HS_SERVICE_ID = 23,
+       HFP_HS_SERVICE_ID = 24,
+#ifdef TIZEN_BT_HAL
+       IOTIVITY_SERVICE_ID = 29,
+#endif
 } oal_service_t;
 
 /** Bluetooth 128-bit UUID */
index 16ecba4..171d579 100644 (file)
@@ -644,30 +644,30 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 
         BT_INFO("service_d: %d", service_d);
 
-        switch(service_d) {
-        case HID_SERVICE_ID:
-                BT_INFO("Incoming HID Profile conn Req from device addr [%s]", address);
-                break;
-        case A2DP_SERVICE_ID:
-                BT_INFO("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
-                _bt_a2dp_src_handle_incoming_authorization(address, service_d);
-                return;
-        case A2DP_SRC_SERVICE_ID:
+       switch(service_d) {
+       case HID_SERVICE_ID:
+               BT_INFO("Incoming HID Profile conn Req from device addr [%s]", address);
+               break;
+       case A2DP_SERVICE_ID:
+               BT_INFO("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
+               _bt_a2dp_src_handle_incoming_authorization(address, service_d);
+               return;
+       case A2DP_SRC_SERVICE_ID:
                BT_INFO("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
                _bt_a2dp_sink_handle_incoming_authorization(address, service_d);
-                break;
-        case AVRCP_SERVICE_ID:
-                BT_INFO("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
-                break;
-        case AVRCP_CT_SERVICE_ID:
-                BT_INFO("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
-                break;
+               break;
+       case AVRCP_SERVICE_ID:
+               BT_INFO("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
+               break;
+       case AVRCP_CT_SERVICE_ID:
+               BT_INFO("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
+               break;
 #ifdef TIZEN_FEATURE_BT_OBEX
        case OPP_SERVICE_ID: {
                GVariant *param = NULL;
                char *name = g_strdup(address); /* TODO: Retrieve and send correct name in OBEX conn auth req event */
 
-                BT_INFO("Incoming OPP conn Req from device addr [%s]", address);
+               BT_INFO("Incoming OPP conn Req from device addr [%s]", address);
                _bt_obex_server_set_pending_conn_auth_device_addr(address);
                param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
                _bt_send_event(BT_OPP_SERVER_EVENT,
@@ -676,14 +676,34 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
                return;
        }
 #endif
-        default:
-                /* For now, reject authorization for any service apart from above switch cases */
-                BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
-                res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, FALSE, FALSE);
-                if (res != OAL_STATUS_SUCCESS)
-                        BT_ERR("authorize_response: %d", res);
-                return;
-        }
+       case HSP_SERVICE_ID:
+               BT_INFO("Incoming HSP_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+       case HFP_SERVICE_ID:
+               BT_INFO("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+       case SAP_SERVICE_ID:
+               BT_INFO("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+       case HSP_HS_SERVICE_ID:
+               BT_INFO("Incoming HSP_HS_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+       case HFP_HS_SERVICE_ID:
+               BT_INFO("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+#ifdef TIZEN_BT_HAL
+       case IOTIVITY_SERVICE_ID:
+               BT_INFO("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
+               break;
+#endif
+       default:
+               /* For now, reject authorization for any service apart from above switch cases */
+               BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
+               res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, FALSE, FALSE);
+               if (res != OAL_STATUS_SUCCESS)
+                       BT_ERR("authorize_response: %d", res);
+               return;
+       }
 
         /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
         BT_INFO("Auto Accept authorization");
@@ -1830,7 +1850,7 @@ gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int
                svc_id = A2DP_SRC_SERVICE_ID; /* Remote is A2DP Source*/
                break;
        case BT_PROFILE_CONN_HSP:
-               svc_id = HFP_HF_SERVICE_ID; /* Remote is HFP HF Unit */
+               svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
                break;
        default:
                BT_DBG("Unknown svc_type: %d", svc_type);