[Adapt: HAL] Implement Device 'Trust' state changed event 56/86056/1
authorAnupam Roy <anupam.r@samsung.com>
Mon, 1 Aug 2016 11:08:50 +0000 (16:38 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 1 Aug 2016 11:08:50 +0000 (16:38 +0530)
Change-Id: I9c311dcea99bdc756c3e8762ec0c63b2414ad5f0
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/hardware/bluetooth.h
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

index eef11e4..02d0388 100755 (executable)
@@ -119,6 +119,12 @@ typedef enum {
     BT_ACL_STATE_DISCONNECTED
 } bt_acl_state_t;
 
+/** Remote Device Trusted state */
+typedef enum {
+    BT_DEVICE_TRUSTED,
+    BT_DEVICE_NOT_TRUSTED
+} bt_device_trust_state_t;
+
 /** Bluetooth 128-bit UUID */
 typedef struct {
    uint8_t uu[16];
@@ -484,6 +490,10 @@ typedef void (*authorize_request_callback) (bt_bdaddr_t *remote_bd_addr, bt_serv
 /** TODO: Add callbacks for Link Up/Down and other generic
   *  notifications/callbacks */
 
+/** Remote Device Trust state changed callback */
+typedef void (*device_trust_state_changed_callback)(bt_bdaddr_t *remote_bd_addr,
+                                            bt_device_trust_state_t trust);
+
 /** Bluetooth DM callback structure. */
 typedef struct {
     /** set to sizeof(bt_callbacks_t) */
@@ -502,6 +512,7 @@ typedef struct {
     le_test_mode_callback le_test_mode_cb;
     energy_info_callback energy_info_cb;
     authorize_request_callback authorize_request_cb;
+    device_trust_state_changed_callback device_trust_state_changed_cb;
 } bt_callbacks_t;
 
 typedef void (*alarm_cb)(void *data);
index 5c3bf26..7c9254d 100644 (file)
@@ -172,6 +172,15 @@ struct hal_ev_acl_state_changed {
         uint8_t state;
 } __attribute__((packed));
 
+#define HAL_DEVICE_TRUSTED         0x00
+#define HAL_DEVICE_UNTRUSTED       0x01
+
+#define HAL_EV_DEVICE_TRUST_CHANGED    0x8B
+struct hal_ev_device_trust_state_changed {
+        uint8_t bdaddr[6];
+        uint8_t trust;
+} __attribute__((packed));
+
 #define BT_TRANSPORT_UNKNOWN            0x00
 #define BT_TRANSPORT_BR_EDR             0x01
 #define BT_TRANSPORT_LE                 0x02
index c533f19..22b8498 100644 (file)
@@ -60,6 +60,8 @@ static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t l
 static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len);
 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len);
 
+static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len);
+
 static bool interface_ready(void)
 {
        return bt_hal_cbacks != NULL;
@@ -706,6 +708,32 @@ static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
        DBG("-");
 }
 
+static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
+{
+        struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
+        bt_bdaddr_t bd_addr;
+        DBG("+");
+
+        memcpy(bd_addr.address, ev->bdaddr, 6);
+        /* BD address*/
+        DBG("[0x%x]", bd_addr.address[0]);
+        DBG("[0x%x]", bd_addr.address[1]);
+        DBG("[0x%x]", bd_addr.address[2]);
+        DBG("[0x%x]", bd_addr.address[3]);
+        DBG("[0x%x]", bd_addr.address[4]);
+        DBG("[0x%x]", bd_addr.address[5]);
+
+        DBG("Device Trusted?  [0x%x]", ev->trust);
+
+        if (!bt_hal_cbacks->device_trust_state_changed_cb) {
+                ERR("HAL User device_trust_state_changed_cb is not set!!");
+                return;
+        }
+
+        bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
+        DBG("-");
+}
+
 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
 {
        DBG("+");
@@ -750,6 +778,10 @@ static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
                        DBG("Event: HAL_EV_AUTHORIZE_REQUEST");
                        __bt_hal_handle_authorize_request_event(buf, len);
                        break;
+               case HAL_EV_DEVICE_TRUST_CHANGED:
+                       DBG("Event: HAL_EV_DEVICE_TRUST_CHANGED");
+                       __bt_hal_handle_device_trust_state_changed_event(buf, len);
+                       break;
                default:
                        DBG("Event Currently not handled!!");
                        break;
index 3c451be..f3e893b 100644 (file)
@@ -78,6 +78,8 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
 static void __bt_hal_send_device_acl_connection_state_event(gboolean connected, const char *address);
 static void __bt_hal_handle_input_event(GVariant *msg, const char *path);
 
+static void __bt_hal_send_device_trust_state_event(gboolean is_trusted, const char *address);
+
 static gboolean __bt_hal_discovery_finished_cb(gpointer user_data)
 {
        event_id = 0;
@@ -962,37 +964,47 @@ int _bt_hal_initialize_event_receiver(handle_stack_msg cb)
 
 static void __bt_hal_device_property_changed_event(GVariant *msg, const char *path)
 {
-       GVariantIter value_iter;
-       GVariant *value = NULL;
-       char *key = NULL;
-       g_variant_iter_init (&value_iter, msg);
-       DBG("+");
+       GVariantIter value_iter;
+       GVariant *value = NULL;
+       char *key = NULL;
+       g_variant_iter_init (&value_iter, msg);
+       DBG("+");
 
-       while (g_variant_iter_loop(&value_iter, "{sv}", &key, &value)) {
-               if(!g_strcmp0(key, "Connected")) {
-                       guint connected = 0;
-                       g_variant_get(value, "i", &connected);
-                       DBG("Device property changed : Connected [%d]", connected);
-               } else if (!g_strcmp0(key, "RSSI")) {
-                       DBG("Device property changed : RSSI");
-                       __bt_hal_dbus_device_found_properties(path);
-               } else if (!g_strcmp0(key, "GattConnected")) {
-                       DBG("Device property changed : GattConnected");
-               } else if (!g_strcmp0(key, "Paired")) {
-                       DBG("Device property changed : Paired");
-               } else if (!g_strcmp0(key, "LegacyPaired")) {
-                       DBG("Device property changed : LegacyPaired");
-               } else if (!g_strcmp0(key, "Trusted")) {
-                       DBG("Device property changed : Trusted");
-               } else if (!g_strcmp0(key, "IpspConnected")) {
-                       DBG("Device property changed : IpspConnected");
-               } else if (!g_strcmp0(key, "IpspInitStateChanged")) {
-                       DBG("Device property changed : IpspInitStateChanged");
-               } else {
-                       ERR("Unhandled Property:[%s]", key);
-               }
-       }
-       DBG("-");
+       while (g_variant_iter_loop(&value_iter, "{sv}", &key, &value)) {
+               if(!g_strcmp0(key, "Connected")) {
+                       guint connected = 0;
+                       g_variant_get(value, "i", &connected);
+                       DBG("Device property changed : Connected [%d]", connected);
+               } else if (!g_strcmp0(key, "RSSI")) {
+                       DBG("Device property changed : RSSI");
+                       __bt_hal_dbus_device_found_properties(path);
+               } else if (!g_strcmp0(key, "GattConnected")) {
+                       DBG("Device property changed : GattConnected");
+               } else if (!g_strcmp0(key, "Paired")) {
+                       DBG("Device property changed : Paired");
+               } else if (!g_strcmp0(key, "LegacyPaired")) {
+                       DBG("Device property changed : LegacyPaired");
+               } else if (!g_strcmp0(key, "Trusted")) {
+                       DBG("Device property changed : Trusted");
+                       gboolean trusted = FALSE;
+                       gchar *address = NULL;
+                       g_variant_get(value, "b", &trusted);
+                       address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
+
+                       _bt_convert_device_path_to_address(path, address);
+                       DBG("Device [%s] trusted: [%d]", address, trusted);
+
+                       __bt_hal_send_device_trust_state_event(trusted, address);
+                       g_free(address);
+               } else if (!g_strcmp0(key, "IpspConnected")) {
+                       DBG("Device property changed : IpspConnected");
+               } else if (!g_strcmp0(key, "IpspInitStateChanged")) {
+                       DBG("Device property changed : IpspInitStateChanged");
+               } else {
+                       ERR("Unhandled Property:[%s]", key);
+               }
+       }
+       DBG("-");
 }
 
 static void __bt_hal_dbus_device_found_properties(const char *device_path)
@@ -1257,6 +1269,25 @@ static void __bt_hal_send_device_acl_connection_state_event(gboolean connected,
        DBG("-");
 }
 
+static void __bt_hal_send_device_trust_state_event(gboolean is_trusted,
+                               const char *address)
+{
+       struct hal_ev_device_trust_state_changed ev;
+       DBG("+");
+
+       ev.trust = (is_trusted == TRUE) ?
+               HAL_DEVICE_TRUSTED :
+               HAL_DEVICE_UNTRUSTED;
+
+       _bt_convert_addr_string_to_type(ev.bdaddr, address);
+
+       if (!event_cb)
+               ERR("Bluetooth HAL event handler not registered");
+       else
+               event_cb(HAL_EV_DEVICE_TRUST_CHANGED, &ev, sizeof(ev));
+       DBG("-");
+}
+
 static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *member,
                        const char *path)
 {