Handle ACL Disconnect Reason 27/198827/1
authorAnupam Roy <anupam.r@samsung.com>
Wed, 30 Jan 2019 06:24:58 +0000 (11:54 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Wed, 30 Jan 2019 06:36:56 +0000 (12:06 +0530)
Following events are Bluez HAL specific
 - Disconnect due to Remote Host
 - Disconnect due to Local Host

Change-Id: I8199847a3cad9040ec1b91ce13f89c773748e8b2
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-api/bt-event-handler.c
bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.c
bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.h
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/common/oal-common.c
bt-oal/hardware/bluetooth.h
bt-oal/include/oal-manager.h
bt-oal/oal-device-mgr.c
bt-service-adaptation/services/device/bt-service-core-device.c

index 6a3ce72..08c09f5 100644 (file)
@@ -942,7 +942,7 @@ void __bt_device_event_filter(GDBusConnection *connection,
 
                conn_info.addr_type = addr_type;
                conn_info.disc_reason = result;
-               BT_DBG("Sending Event to Framework");
+               BT_DBG("Sending Event to Framework, disconnect reason [0x%x]", result);
                _bt_common_event_cb(BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
                                result, &conn_info,
                                event_info->cb, event_info->user_data);
index 2fac142..7230e49 100644 (file)
@@ -1160,6 +1160,21 @@ char * _bt_hal_convert_disc_reason_to_string(int reason)
        }
 }
 
+int _bt_hal_convert_disc_reason_to_status(int reason)
+{
+       switch (reason) {
+       case 1:
+               return BT_STATUS_CONN_TOUT; //"Link loss"
+       case 2:
+               return BT_STATUS_CONN_TERM_LOCAL_HOST; //"Connection terminated by local host";
+       case 3:
+               return BT_STATUS_CONN_TERM_RMT_HOST; //"Connection terminated by local host";
+       case 0:
+       default:
+               return BT_STATUS_FAIL;
+       }
+}
+
 void _bt_hal_logging_connection(gboolean connect, int addr_type)
 {
        static int le_conn = 0;
index f738f3b..7b9e945 100644 (file)
@@ -479,6 +479,10 @@ extern "C" {
 
        GVariant *_bt_hal_get_managed_objects(void);
 
+       char * _bt_hal_convert_disc_reason_to_string(int reason);
+
+       int _bt_hal_convert_disc_reason_to_status(int reason);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 0f69377..719681c 100644 (file)
@@ -95,7 +95,7 @@ static void __bt_hal_device_property_changed_event(GVariant *msg, const char *pa
 static void __bt_hal_dbus_device_found_properties(const char *device_path);
 static void __bt_hal_device_properties_lookup(GVariant *result, char *address);
 static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *member, const char *path);
-static void __bt_hal_send_device_acl_connection_state_event(gboolean connected, const char *address);
+static void __bt_hal_send_device_acl_connection_state_event(int status, gboolean connected, const char *address);
 static void __bt_hal_handle_input_event(GVariant *msg, const char *path);
 static void __bt_hal_send_av_connection_state_event(gboolean connected, const char *address);
 static void __bt_hal_send_a2dp_sink_connection_state_event(gboolean connected, const char *address);
@@ -1802,12 +1802,12 @@ static void __bt_hal_device_properties_lookup(GVariant *result, char *address)
        DBG("-");
 }
 
-static void __bt_hal_send_device_acl_connection_state_event(gboolean connected, const char *address)
+static void __bt_hal_send_device_acl_connection_state_event(int status, gboolean connected, const char *address)
 {
        DBG("+");
        struct hal_ev_acl_state_changed ev;
 
-       ev.status = BT_STATUS_SUCCESS;
+       ev.status = status;
        ev.state = (connected == TRUE) ?
                HAL_ACL_STATE_CONNECTED :
                HAL_ACL_STATE_DISCONNECTED;
@@ -1821,12 +1821,12 @@ static void __bt_hal_send_device_acl_connection_state_event(gboolean connected,
        DBG("-");
 }
 
-static void __bt_hal_send_device_le_connection_state_event(gboolean connected, const char *address)
+static void __bt_hal_send_device_le_connection_state_event(int status, gboolean connected, const char *address)
 {
        DBG("+");
        struct hal_ev_le_conn_state_changed ev;
 
-       ev.status = BT_STATUS_SUCCESS;
+       ev.status = status;
        ev.state = (connected == TRUE) ?
                HAL_LE_STATE_CONNECTED :
                HAL_LE_STATE_DISCONNECTED;
@@ -1934,9 +1934,9 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                DBG("Member: [%s]", member);
                ERR_C("Connected [%s] [%s]", !addr_type ? "BREDR" : "LE", address);
                if (!addr_type)
-                       __bt_hal_send_device_acl_connection_state_event(TRUE, address);
+                       __bt_hal_send_device_acl_connection_state_event(BT_STATUS_SUCCESS, TRUE, address);
                else
-                       __bt_hal_send_device_le_connection_state_event(TRUE, address);
+                       __bt_hal_send_device_le_connection_state_event(BT_STATUS_SUCCESS, TRUE, address);
                g_free(address);
        } else if (strcasecmp(member, "Disconnected") == 0) {
                unsigned char disc_reason = 0;
@@ -1949,13 +1949,14 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                _bt_hal_convert_device_path_to_address(path, address);
 
                DBG("Member: [%s]", member);
+
                ERR_C("DisConnected [%s] [%s]", !addr_type ? "BREDR" : "LE", address);
-               DBG("Disconnect Reason: %d", disc_reason);
+               DBG("Disconnected Reason [%d : %s]", disc_reason, _bt_hal_convert_disc_reason_to_string(disc_reason));
                DBG("Name: %s", name);
                if (!addr_type)
-                       __bt_hal_send_device_acl_connection_state_event(FALSE, address);
+                       __bt_hal_send_device_acl_connection_state_event(_bt_hal_convert_disc_reason_to_status(disc_reason), FALSE, address);
                else
-                       __bt_hal_send_device_le_connection_state_event(FALSE, address);
+                       __bt_hal_send_device_le_connection_state_event(_bt_hal_convert_disc_reason_to_status(disc_reason), FALSE, address);
                g_free(address);
        } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
                int state = 0;
index edf77ca..816a857 100755 (executable)
@@ -186,6 +186,17 @@ oal_status_t convert_to_oal_status(bt_status_t status)
        case BT_STATUS_UNSUPPORTED:
                ret = OAL_STATUS_NOT_SUPPORT;
                break;
+       case BT_STATUS_CONN_TOUT:
+               ret = OAL_STATUS_LINK_LOSS;
+               break;
+#ifdef TIZEN_BT_HAL
+       case BT_STATUS_CONN_TERM_LOCAL_HOST:
+               ret = OAL_STATUS_CONN_TERM_LOCAL_HOST;
+               break;
+       case BT_STATUS_CONN_TERM_RMT_HOST:
+               ret = OAL_STATUS_CONN_TERM_RMT_HOST;
+               break;
+#endif
        case BT_STATUS_UNHANDLED:
        case BT_STATUS_FAIL:
        case BT_STATUS_NOMEM:
index 6b9138f..e77a4d4 100644 (file)
@@ -89,8 +89,14 @@ typedef enum {
        BT_STATUS_UNHANDLED,
        BT_STATUS_AUTH_FAILURE,
        BT_STATUS_RMT_DEV_DOWN,
-       BT_STATUS_AUTH_REJECTED
-
+#ifndef TIZEN_BT_HAL
+       BT_STATUS_CONN_TOUT   /* disconnection due to supervision timeout */
+#else
+       BT_STATUS_CONN_TOUT,   /* disconnection due to supervision timeout */
+       BT_STATUS_AUTH_REJECTED,
+       BT_STATUS_CONN_TERM_LOCAL_HOST,
+       BT_STATUS_CONN_TERM_RMT_HOST
+#endif
 } bt_status_t;
 
 /** Bluetooth PinKey Code */
index 2dfc693..427fdc1 100755 (executable)
@@ -68,7 +68,14 @@ typedef enum {
        OAL_STATUS_PENDING,
        OAL_STATUS_CONN_TIMEOUT,
        /* HID */
-       OAL_STATUS_HID_FAILED_MOUSE
+       OAL_STATUS_HID_FAILED_MOUSE,
+#ifndef TIZEN_BT_HAL
+       OAL_STATUS_LINK_LOSS
+#else
+       OAL_STATUS_LINK_LOSS,
+       OAL_STATUS_CONN_TERM_LOCAL_HOST,
+       OAL_STATUS_CONN_TERM_RMT_HOST
+#endif
 } oal_status_t;
 
 
index 33ee984..1ddacc9 100755 (executable)
@@ -692,6 +692,9 @@ void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
 
        memcpy(conn_status->address.addr, bd_addr->address, 6);
 
+#ifdef TIZEN_BT_HAL
+       conn_status->status = convert_to_oal_status(status);
+#else
        if (BT_STATUS_SUCCESS != status) {
                /* At present only timeout will cause non-success status, later we can add more */
                conn_status->status = OAL_STATUS_CONN_TIMEOUT;
@@ -700,6 +703,10 @@ void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
                conn_status->status = OAL_STATUS_SUCCESS;
 
        memcpy(conn_status->address.addr, bd_addr->address, 6);
+#endif
+
+       BT_INFO("ACL STATE :%d, conn_status->status :%d, BT_ACL_STATE: %d", status, conn_status->status, state);
+
        switch (state) {
        case BT_ACL_STATE_CONNECTED:
                event = OAL_EVENT_DEVICE_ACL_CONNECTED;
@@ -729,11 +736,7 @@ void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
 
        BT_DBG("LE conn status:%d, state: %d", status, state);
        memcpy(conn_status->address.addr, bd_addr->address, 6);
-       if (BT_STATUS_SUCCESS != status)
-               /* At present only timeout will cause non-success status, later we can add more */
-               conn_status->status = OAL_STATUS_CONN_TIMEOUT;
-       else
-               conn_status->status = OAL_STATUS_SUCCESS;
+       conn_status->status = convert_to_oal_status(status);
 
        switch (state) {
        case BT_LE_CONN_STATE_CONNECTED:
index e055615..abd1bb8 100644 (file)
@@ -166,7 +166,7 @@ static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr);
 static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr);
 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event);
 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond);
-static void __bt_device_conn_state_changed_callback(event_dev_conn_status_t *acl_event,
+static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
                gboolean connected, unsigned char type);
 static void __bt_free_pairing_info(bt_pairing_data_t **p_info);
 
@@ -971,23 +971,23 @@ static void __bt_device_event_handler(int event_type, gpointer event_data)
        case OAL_EVENT_DEVICE_ACL_CONNECTED: {
                BT_INFO("ACL Connected event Received");
                event_dev_conn_status_t* param = event_data;
-               __bt_device_conn_state_changed_callback(param, TRUE, 0);
+               __bt_device_acl_state_changed_callback(param, TRUE, 0);
                break;
        }
        case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
                BT_INFO("ACL Disconnected event Received");
-               __bt_device_conn_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
+               __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
                break;
        }
        case OAL_EVENT_DEVICE_LE_CONNECTED: {
                BT_INFO("LE Connected event Received");
                event_dev_conn_status_t* param = event_data;
-               __bt_device_conn_state_changed_callback(param, TRUE, 1);
+               __bt_device_acl_state_changed_callback(param, TRUE, 1);
                break;
        }
        case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
                BT_INFO("LE Disconnected event Received");
-               __bt_device_conn_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
+               __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
                break;
        }
        case OAL_EVENT_DEVICE_PIN_REQUEST: {
@@ -1350,7 +1350,38 @@ static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
        BT_DBG("-");
 }
 
-static void __bt_device_conn_state_changed_callback(event_dev_conn_status_t *acl_event,
+static int __bt_oal_status_to_bt_error(int oal_status)
+{
+        int ret = 0;
+
+       switch (oal_status) {
+       case OAL_STATUS_SUCCESS:
+               ret = BLUETOOTH_ERROR_NONE;
+               break;
+       case OAL_STATUS_CONN_TIMEOUT:
+       case OAL_STATUS_LINK_LOSS:
+               BT_INFO("Connection Timeout");
+               ret = BLUETOOTH_ERROR_CONNECTION_TIMEOUT;
+               break;
+#ifdef TIZEN_BT_HAL
+       case OAL_STATUS_CONN_TERM_LOCAL_HOST:
+               ret = BLUETOOTH_ERROR_LOCAL_HOST_TERM;
+               break;
+       case OAL_STATUS_CONN_TERM_RMT_HOST:
+               ret = BLUETOOTH_ERROR_REMOTE_USER_TERM;
+               break;
+#endif
+       case OAL_STATUS_INTERNAL_ERROR:
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               break;
+       default:
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               break;
+       }
+       return ret;
+}
+
+static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
                gboolean connected, unsigned char type)
 {
        gchar address[BT_ADDRESS_STR_LEN];
@@ -1363,6 +1394,9 @@ static void __bt_device_conn_state_changed_callback(event_dev_conn_status_t *acl
 
        _bt_logging_connection(connected, type);
 
+       result = __bt_oal_status_to_bt_error(acl_event->status);
+       BT_INFO("Result [0x%x]", result);
+
        if (connected) {
                param = g_variant_new("(isy)", result, address, type);
                _bt_send_event(BT_DEVICE_EVENT,