Disallow HFP multi connection 88/235388/1
authorSangki Park <sangki79.park@samsung.com>
Thu, 21 May 2020 07:11:29 +0000 (16:11 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 4 Jun 2020 07:07:25 +0000 (16:07 +0900)
Change-Id: I56e07cd917601a4ea486026389fd1f99827edf84
Signed-off-by: Sangki Park <sangki79.park@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-service-adaptation/services/audio/bt-service-audio.c
bt-service-adaptation/services/audio/hf/bt-service-hf-client.c
bt-service-adaptation/services/device/bt-service-core-device.c
bt-service-adaptation/services/include/bt-service-audio-common.h

index 0d8d4e1..420d0ad 100644 (file)
@@ -1096,6 +1096,10 @@ void _bt_remove_headset_from_list(int type, const char *address)
                        if (connected_device->type & BT_AUDIO_A2DP_SOURCE)
                                connected_device->type &= ~(BT_AUDIO_A2DP_SOURCE);
                        break;
+               case BT_AUDIO_AG:
+                       if (connected_device->type & BT_AUDIO_AG)
+                               connected_device->type &= ~(BT_AUDIO_AG);
+                       break;
                default:
                        break;
                }
@@ -1314,3 +1318,45 @@ int _bt_hf_disconnect(bluetooth_device_address_t *device_address)
 
        return result;
 }
+
+void _bt_audio_handle_incoming_authorization(char *address, int service_id)
+{
+       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
+       gboolean connected = FALSE;
+       bluetooth_device_address_t device_address;
+       oal_status_t res = OAL_STATUS_SUCCESS;
+
+       _bt_convert_addr_string_to_type(device_address.addr, address);
+
+       switch (service_id) {
+       case HSP_SERVICE_ID:
+       case HFP_SERVICE_ID:
+               connected = _bt_is_headset_type_connected(BT_AUDIO_HSP, connected_address);
+               BT_DBG("Connected [0x%x]", connected);
+               break;
+       case HSP_HS_SERVICE_ID:
+       case HFP_HS_SERVICE_ID:
+               connected = _bt_is_headset_type_connected(BT_AUDIO_AG, connected_address);
+               BT_DBG("Connected [0x%x]", connected);
+               break;
+       default:
+               BT_ERR("Invalid HFP device ID.. [%d]", service_id);
+               return;
+       }
+
+       if (connected) {
+               BT_INFO("[%d] device is already connected..check which device..", service_id);
+               if (g_strcmp0(connected_address, address) != 0) {
+                       BT_INFO("Different device is connected[%s] reject current [%s] device authorization request",
+                                       connected_address, address);
+                       res = device_reply_auth_request((bt_address_t*)&device_address, service_id, FALSE, FALSE);
+                       if (res != OAL_STATUS_SUCCESS)
+                               BT_ERR("authorize_response: %d", res);
+                       return;
+               }
+       }
+
+       res = device_reply_auth_request((bt_address_t*)&device_address, service_id, TRUE, FALSE);
+       if (res != OAL_STATUS_SUCCESS)
+               BT_ERR("authorize_response: %d", res);
+}
index 33f85f3..fd91e2d 100644 (file)
 #include "oal-hf-client.h"
 #include "bt-service-common.h"
 
+#include <bt-service-audio-common.h>
 #include <bt-service-hf-client.h>
 #include <bt-service-event.h>
 
-
-
-
 static void __bt_reply_hf_client_disconnection_pending_request(bt_address_t *address)
 {
-       BT_DBG("+");
        char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
        bluetooth_device_address_t device_address;
        GArray *out_param;
@@ -49,7 +46,7 @@ static void __bt_reply_hf_client_disconnection_pending_request(bt_address_t *add
        memcpy(device_address.addr, address->addr, BLUETOOTH_ADDRESS_LENGTH);
        _bt_convert_addr_type_to_string(addr, address->addr);
 
-       BT_INFO("HF Client Disconnection remote device [%s]", addr);
+       BT_DBG("HF Client Disconnection remote device [%s]", addr);
 
        /* Find Async request information*/
        req_info = _bt_get_request_info_data(BT_HF_DISCONNECT, addr);
@@ -60,13 +57,13 @@ static void __bt_reply_hf_client_disconnection_pending_request(bt_address_t *add
                   __bt_hf_client_connect_cb) which will internally trigger HF DISCONNECTED event */
                req_info = _bt_get_request_info_data(BT_HF_CONNECT, addr);
                if (NULL == req_info) {
-                       BT_INFO("HF Connect request not found..");
+                       BT_DBG("HF Connect request not found..");
                        return;
                } else {
-                       BT_INFO("HF Connect request found..reply this request");
+                       BT_DBG("HF Connect request found..reply this request");
                }
        } else {
-               BT_INFO("HF DisConnect request found..reply this request");
+               BT_DBG("HF DisConnect request found..reply this request");
        }
 
        /* In any of the above cases, reply DBUS context */
@@ -75,13 +72,10 @@ static void __bt_reply_hf_client_disconnection_pending_request(bt_address_t *add
        _bt_service_method_return(req_info->context, out_param, result);
        g_array_free(out_param, TRUE);
        _bt_free_info_from_invocation_list(req_info);
-
-       BT_DBG("-");
 }
 
 static void __bt_reply_hf_client_connection_pending_request(bt_address_t *address)
 {
-       BT_DBG("+");
        char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
        bluetooth_device_address_t device_address;
        GArray *out_param;
@@ -93,16 +87,16 @@ static void __bt_reply_hf_client_connection_pending_request(bt_address_t *addres
        memcpy(device_address.addr, address->addr, BLUETOOTH_ADDRESS_LENGTH);
        _bt_convert_addr_type_to_string(addr, address->addr);
 
-       BT_INFO("HF Client Connection remote device [%s]", addr);
+       BT_DBG("HF Client Connection remote device [%s]", addr);
 
        /* Find Async request information*/
        req_info = _bt_get_request_info_data(BT_HF_CONNECT, addr);
        if (NULL == req_info) {
-               BT_INFO("HF Connect request not found or possibly already replied..");
+               BT_DBG("HF Connect request not found or possibly already replied..");
                return;
 
        } else {
-               BT_INFO("HF Connect request found..");
+               BT_DBG("HF Connect request found..");
        }
 
        /* In any of the above cases, reply DBUS context */
@@ -112,15 +106,14 @@ static void __bt_reply_hf_client_connection_pending_request(bt_address_t *addres
        g_array_free(out_param, TRUE);
        _bt_free_info_from_invocation_list(req_info);
 
-       BT_DBG("-");
 }
 
 
 /* This event handler process events for HF Client role */
 void _bt_hf_client_event_handler(int oal_event, gpointer event_data)
 {
-       BT_INFO("+");
        bt_address_t *bt_addr = event_data;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
 
        switch (oal_event) {
        case OAL_EVENT_HF_CLIENT_DISCONNECTED:
@@ -128,11 +121,17 @@ void _bt_hf_client_event_handler(int oal_event, gpointer event_data)
                BT_INFO("HF client Profile disconnected, reply pending DBUS request and check waiting device");
                __bt_reply_hf_client_disconnection_pending_request(bt_addr);
                BT_PERMANENT_LOG("Disconnected HF");
+
+               _bt_convert_addr_type_to_string(address, bt_addr->addr);
+               _bt_remove_headset_from_list(BT_AUDIO_AG, address);
                break;
        case OAL_EVENT_HF_CLIENT_CONNECTED:
                BT_INFO("HF Client Profile connected, Event & DBUS context will be handled at finalizing SCO connect..");
                __bt_reply_hf_client_connection_pending_request(bt_addr);
                BT_PERMANENT_LOG("Connected HF");
+
+               _bt_convert_addr_type_to_string(address, bt_addr->addr);
+               _bt_add_headset_to_list(BT_AUDIO_AG, BT_STATE_CONNECTED, address);
                break;
        case OAL_EVENT_HF_CLIENT_CONNECTING:
                BT_INFO("HF Client Profile connection successful, wait for Audio connect..");
@@ -151,8 +150,6 @@ int _bt_connect_remote_ag(bluetooth_device_address_t *device_address)
        int result = BLUETOOTH_ERROR_NONE;
        gboolean is_connected = FALSE;
 
-       BT_INFO("+");
-
        is_connected = device_get_svc_conn_state((bt_address_t*)device_address, HFP_SERVICE_ID);
        if (is_connected == TRUE) {
                BT_ERR("HF Client is already connected");
@@ -171,7 +168,6 @@ int _bt_disconnect_remote_ag(bluetooth_device_address_t *device_address)
 {
        oal_status_t status = OAL_STATUS_SUCCESS;
        int result = BLUETOOTH_ERROR_NONE;
-       BT_INFO("+");
 
        status = hf_client_disconnect((bt_address_t *)device_address);
        if (status != OAL_STATUS_SUCCESS) {
index d3cf2e8..370de79 100644 (file)
@@ -602,25 +602,25 @@ static void __bt_device_services_callback(event_dev_services_t* uuid_list)
 
 static void __bt_device_authorization_request_callback(event_dev_authorize_req_t* auth_event)
 {
-       oal_service_t service_d = auth_event->service_id;
+       oal_service_t service_id = auth_event->service_id;
        gchar address[BT_ADDRESS_STR_LEN];
        int res;
 
        _bt_convert_addr_type_to_string(address, auth_event->address.addr);
 
-       BT_DBG("service_d: %d", service_d);
+       BT_DBG("service_d: %d", service_id);
 
-       switch (service_d) {
+       switch (service_id) {
        case HID_SERVICE_ID:
                BT_DBG("Incoming HID Profile conn Req from device addr [%s]", address);
                break;
        case A2DP_SERVICE_ID:
                BT_DBG("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
-               _bt_a2dp_src_handle_incoming_authorization(address, service_d);
+               _bt_a2dp_src_handle_incoming_authorization(address, service_id);
                return;
        case A2DP_SRC_SERVICE_ID:
                BT_DBG("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
-               _bt_a2dp_sink_handle_incoming_authorization(address, service_d);
+               _bt_a2dp_sink_handle_incoming_authorization(address, service_id);
                break;
        case AVRCP_SERVICE_ID:
                BT_DBG("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
@@ -650,20 +650,18 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
        }
 #endif
        case HSP_SERVICE_ID:
-               BT_DBG("Incoming HSP_SERVICE_ID conn Req from device addr [%s]", address);
-               break;
        case HFP_SERVICE_ID:
                BT_DBG("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
-               break;
+               _bt_audio_handle_incoming_authorization(address, service_id);
+               return;
        case SAP_SERVICE_ID:
                BT_DBG("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
                break;
        case HSP_HS_SERVICE_ID:
-               BT_DBG("Incoming HSP_HS_SERVICE_ID conn Req from device addr [%s]", address);
-               break;
        case HFP_HS_SERVICE_ID:
                BT_DBG("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
-               break;
+               _bt_audio_handle_incoming_authorization(address, service_id);
+               return;
 #ifdef TIZEN_BT_HAL
        case IOTIVITY_SERVICE_ID:
                BT_DBG("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
@@ -671,8 +669,8 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 #endif
        default:
                /* For now, reject authorization for any service apart from above switch cases */
-               BT_DBG("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);
+               BT_DBG("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_id, address);
+               res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, FALSE, FALSE);
                if (res != OAL_STATUS_SUCCESS)
                        BT_ERR("authorize_response: %d", res);
                return;
@@ -680,7 +678,7 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 
        /* Auto accept authorization request for HID, A2DP and AVRCP profiles */
        BT_INFO("Auto Accept authorization");
-       res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, TRUE, FALSE);
+       res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_id, TRUE, FALSE);
        if (res != OAL_STATUS_SUCCESS)
                BT_ERR("authorize_response: %d", res);
 }
index a6c866d..e57084c 100644 (file)
@@ -39,12 +39,12 @@ typedef enum {
 typedef enum {
        BT_AUDIO_HSP = 0x01,    /* HSP Connection */
        BT_AUDIO_A2DP = 0x02,           /* A2DP Source Connection, remote device is A2DP Sink */
-       BT_AUDIO_ALL = 0x03,            /* HSP and A2DP Source Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP) */
+       BT_AUDIO_ALL = (0x01 | 0x02),           /* HSP and A2DP Source Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP) */
        BT_AVRCP_TARGET = 0x04, /* AVRCP Target Connection to remote AVRCP controller */
        BT_AVRCP = 0x08,        /* AVRCP ctrl Connection to remote AVRCP target */
        BT_AUDIO_A2DP_SOURCE = 0x10,    /* A2DP Sink Connection, remote device is A2DP Source */
-       BT_AUDIO_HFP_SOURCE = 0x11,     /* HSP and A2DP Sink Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP_SOURCE)*/
-       BT_AUDIO_AG = 0x12    /* BT_HF_CONNECT local device HF Client and remote device AG */
+       BT_AUDIO_AG = 0x20, /* BT_HF_CONNECT local device HF Client and remote device AG */
+       BT_AUDIO_HFP_SOURCE = (0x10 | 0x20) /* HSP and A2DP Sink Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP_SOURCE)*/
 } bt_audio_type_t;
 
 typedef enum {
@@ -130,6 +130,8 @@ int _bt_audio_select_role(bluetooth_audio_role_t role);
 
 void _bt_audio_set_current_role(bluetooth_audio_role_t role);
 
+void _bt_audio_handle_incoming_authorization(char *address, int service_id);
+
 #ifdef TIZEN_FEATURE_BT_AVC_TARGET
 typedef enum {
        BT_AVC_OFF = 0x00,