[HAL/OAL] Add LE device conn state changed support 71/157471/1
authorAtul Rai <a.rai@samsung.com>
Tue, 24 Oct 2017 12:49:45 +0000 (18:19 +0530)
committerAtul Rai <a.rai@samsung.com>
Tue, 24 Oct 2017 14:21:28 +0000 (19:51 +0530)
Change-Id: I5146f5dad0de4b8c41ad4794b31b6c2d5dca9bda
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/hardware/bluetooth.h
bt-oal/include/oal-event.h
bt-oal/oal-adapter-mgr.c
bt-oal/oal-device-mgr.c

index a1b9eb6..74818f3 100644 (file)
@@ -587,6 +587,15 @@ struct hal_ev_gatt_server_notifcation_change {
 struct hal_ev_le_state_changed {
         uint8_t state;
 } __attribute__((packed));
+#endif /* TIZEN_BT_HAL */
+
+#define HAL_LE_STATE_CONNECTED         0x00
+#define HAL_LE_STATE_DISCONNECTED      0x01
 
-#endif
+#define HAL_EV_LE_CONN_STATE_CHANGED        0xB8
+struct hal_ev_le_conn_state_changed {
+        uint8_t status;
+        uint8_t bdaddr[6];
+        uint8_t state;
+} __attribute__((packed));
 #endif //_BT_HAL_MSG_H_
index 66900cd..ff99c06 100644 (file)
@@ -700,6 +700,31 @@ static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t l
         DBG("-");
 }
 
+static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
+{
+        struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
+        bt_bdaddr_t bd_addr;
+        DBG("+");
+
+        memcpy(bd_addr.address, ev->bdaddr, 6);
+        /* BD address */
+        DBG("Address: [%02X:%02X:%02X:%02X:%02X:%02X]", bd_addr.address[0],
+                       bd_addr.address[1], bd_addr.address[2], bd_addr.address[3],
+                       bd_addr.address[4], bd_addr.address[5]);
+        DBG("LE conn Status [0x%x]", ev->status);
+        DBG("LE conn State  [0x%x]", ev->state);
+
+#ifdef TIZEN_BT_HAL
+        if (!bt_hal_cbacks->le_conn_state_changed_cb) {
+                ERR("HAL User le_conn_state_changed_cb is not set!!");
+                return;
+        }
+
+        bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
+#endif
+        DBG("-");
+}
+
 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
 {
        struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
@@ -871,6 +896,10 @@ static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
                        DBG("Event: HAL_ACL_STATE_CONNECTED or Disconnected");
                        __bt_hal_handle_device_acl_state_changed_event(buf, len);
                        break;
+               case HAL_EV_LE_CONN_STATE_CHANGED:
+                       DBG("Event: HAL_LE_CONN_STATE_CONNECTED or Disconnected");
+                       __bt_hal_handle_device_le_conn_state_changed_event(buf, len);
+                       break;
                case HAL_EV_SSP_REQUEST:
                        DBG("Event: HAL_EV_SSP_REQUEST");
                        __bt_hal_handle_ssp_request_event(buf, len);
index ed5031d..51350b8 100644 (file)
@@ -1623,6 +1623,25 @@ 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)
+{
+       DBG("+");
+       struct hal_ev_le_conn_state_changed ev;
+
+       ev.status = BT_STATUS_SUCCESS;
+       ev.state = (connected == TRUE) ?
+               HAL_LE_STATE_CONNECTED :
+               HAL_LE_STATE_DISCONNECTED;
+
+       _bt_hal_convert_addr_string_to_type(ev.bdaddr, address);
+
+       if (!event_cb)
+               ERR("Bluetooth HAL event handler not registered");
+       else
+               event_cb(HAL_EV_LE_CONN_STATE_CHANGED, &ev, sizeof(ev));
+       DBG("-");
+}
+
 static void __bt_hal_send_device_trust_state_event(gboolean is_trusted,
                                const char *address)
 {
@@ -1699,13 +1718,17 @@ 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);
-               __bt_hal_send_device_acl_connection_state_event(TRUE, address);
+               if (!addr_type)
+                       __bt_hal_send_device_acl_connection_state_event(TRUE, address);
+               else
+                       __bt_hal_send_device_le_connection_state_event(TRUE, address);
                g_free(address);
        } else if (strcasecmp(member, "Disconnected") == 0) {
                unsigned char disc_reason = 0;
                unsigned char addr_type = 0;
+               char *name = NULL;
 
-               g_variant_get(msg, "(yy)", &addr_type, &disc_reason);
+               g_variant_get(msg, "(yy&s)", &addr_type, &disc_reason, &name);
 
                address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
                _bt_hal_convert_device_path_to_address(path, address);
@@ -1713,7 +1736,11 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                DBG("Member: [%s]", member);
                ERR_C("DisConnected [%s] [%s]", !addr_type ? "BREDR" : "LE", address);
                DBG("Disconnect Reason: %d", disc_reason);
-               __bt_hal_send_device_acl_connection_state_event(FALSE, address);
+               DBG("Name: %s", name);
+               if (!addr_type)
+                       __bt_hal_send_device_acl_connection_state_event(FALSE, address);
+               else
+                       __bt_hal_send_device_le_connection_state_event(FALSE, address);
                g_free(address);
        } else if (strcasecmp(member, "ProfileStateChanged") == 0) {
                int state = 0;
index 4019ca6..6169606 100644 (file)
@@ -511,6 +511,16 @@ typedef void (*authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_serv
 #ifdef TIZEN_BT_HAL
 /* Service level Authorization request callback */
 typedef void (*sock_authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
+
+/** Bluetooth ACL connection state */
+typedef enum {
+    BT_LE_CONN_STATE_CONNECTED,
+    BT_LE_CONN_STATE_DISCONNECTED
+} bt_le_conn_state_t;
+
+/** Bluetooth ACL connection state changed callback */
+typedef void (*le_conn_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
+               bt_le_conn_state_t state);
 #endif
 
 /** TODO: Add callbacks for Link Up/Down and other generic
@@ -542,6 +552,7 @@ typedef struct {
 #ifdef TIZEN_BT_HAL
     sock_authorize_request_callback socket_authorize_request_cb;
        le_state_changed_callback le_state_changed_cb;
+       le_conn_state_changed_callback le_conn_state_changed_cb;
 #endif
 } bt_callbacks_t;
 
index 3d0d207..1d15961 100644 (file)
@@ -65,6 +65,8 @@ extern "C" {
        EVENT(OAL_EVENT_SOCKET_AUTHORIZE_REQUEST)                       /* event_socket_authorize_req_t */\
        EVENT(OAL_EVENT_DEVICE_ACL_CONNECTED)                           /* bt_address_t */\
        EVENT(OAL_EVENT_DEVICE_ACL_DISCONNECTED)                        /* bt_address_t */\
+       EVENT(OAL_EVENT_DEVICE_LE_CONNECTED)                            /* bt_address_t */\
+       EVENT(OAL_EVENT_DEVICE_LE_DISCONNECTED)                 /* bt_address_t */\
        EVENT(OAL_EVENT_DEVICE_TRUSTED)                 /* Remote Device is Trusted */\
        EVENT(OAL_EVENT_DEVICE_UNTRUSTED)                       /* Remote Device is UnTrusted */\
        EVENT(OAL_EVENT_OAL_INITIALISED_SUCCESS)                /* OAL Initialisation event */  \
index a1ae5c5..041f181 100644 (file)
@@ -73,6 +73,8 @@ extern void cb_device_trust_state_changed(bt_bdaddr_t *remote_bd_addr, bt_device
 #ifdef TIZEN_BT_HAL
 extern void cb_socket_conn_authorize_request(bt_bdaddr_t *remote_bd_addr, bt_uuid_t *uuid);
 static void cb_ble_state_change(bt_state_t status);
+extern void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
+               bt_le_conn_state_t state);
 #endif
 
 static bt_callbacks_t callbacks = {
@@ -95,6 +97,7 @@ static bt_callbacks_t callbacks = {
 #ifdef TIZEN_BT_HAL
        cb_socket_conn_authorize_request,
        cb_ble_state_change,
+       cb_device_le_conn_state_changed,
 #endif
 };
 
index aad4c1f..d8be22d 100755 (executable)
@@ -587,6 +587,41 @@ void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
        send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
 }
 
+#ifdef TIZEN_BT_HAL
+void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
+               bt_le_conn_state_t state)
+{
+       event_dev_conn_status_t * conn_status = g_new0(event_dev_conn_status_t, 1);
+       //bt_address_t * address = g_new0(bt_address_t, 1);
+       oal_event_t event;
+       gsize size = 0;
+
+       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;
+
+       switch(state) {
+       case BT_LE_CONN_STATE_CONNECTED:
+               event = OAL_EVENT_DEVICE_LE_CONNECTED;
+               break;
+       case BT_LE_CONN_STATE_DISCONNECTED:
+               event = OAL_EVENT_DEVICE_LE_DISCONNECTED;
+               break;
+       default:
+               BT_ERR("Unexpected ACL state %d", state);
+               g_free(conn_status);
+               return;
+       }
+
+       size = sizeof(event_dev_conn_status_t);
+       send_event_bda_trace(event, conn_status, size, (bt_address_t*)bd_addr);
+}
+#endif
+
 void cb_device_pin_request(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t device_class)
 {
        remote_device_t * dev_info = g_new0(remote_device_t, 1);