Implement local LE features adapter property 15/186215/1
authorAnupam Roy <anupam.r@samsung.com>
Wed, 8 Aug 2018 06:13:29 +0000 (11:43 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Wed, 8 Aug 2018 06:13:29 +0000 (11:43 +0530)
This patch handles Adapter's local LE features property
which will indicate whether adapter supports LE 2M PHY
and LE CODED PHY. This property is emitted by bluetoothd
as adapter's property changed event and handled in
bluetooth HAL layer. LE features are further propagated to
bt-service via new OAL event OAL_EVENT_BLE_LOCAL_FEATURES.
LE features will be finally saved in bt-service daemon.
Application can read these values directly from bt-service.

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

index d3fdb56..e51c87e 100644 (file)
@@ -33,6 +33,7 @@
 #include "bt-hal-log.h"
 #include "bt-hal-msg.h"
 #include "bt-hal-utils.h"
+#include "bt-hal-adapter-le.h"
 
 #include <bt-hal-adapter-dbus-handler.h>
 #include <bt-hal-dbus-common-utils.h>
@@ -475,34 +476,6 @@ int _bt_hal_dbus_stop_discovery(void)
        return BT_STATUS_SUCCESS;
 }
 
-static void ___bt_fill_le_supported_features(const char *item,
-               const char *value, uint8_t *le_features)
-{
-       DBG("+");
-
-       if (g_strcmp0(item, "adv_inst_max") == 0)
-               le_features[1] = atoi(value);
-       else if (g_strcmp0(item, "rpa_offloading") == 0)
-               le_features[2] = atoi(value);
-       else if (g_strcmp0(item, "max_filter") == 0)
-               le_features[4] = atoi(value);
-       else
-               DBG("No registered item");
-
-       /*
-        * TODO: Need to check these usages for Bluez Case. In Bluedroid case,
-        * these are used, so just setting all to 0
-        */
-       le_features[3] = 0; /* Adapter MAX IRK List Size */
-       /* lo byte */
-       le_features[5] = 0; /* Adapter Scan result storage size */
-       /* hi byte */
-       le_features[6] = 0;
-       le_features[7] = 0; /* Adapter Activity energy info supported */
-
-       DBG("-");
-}
-
 static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
 {
        GVariant *result = user_data;
@@ -656,23 +629,25 @@ static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
                        char *name = NULL;
                        char *val = NULL;
                        GVariantIter *iter = NULL;
-                       uint8_t le_features[8];
+                       bt_local_le_features_t le_features;
                        gboolean le_features_present = FALSE;
 
+                       memset(&le_features, 0x00, sizeof(le_features));
+
                        g_variant_get(value, "as", &iter);
                        if (iter) {
                                while (g_variant_iter_loop(iter, "s", &name)) {
                                        DBG("name = %s", name);
                                        g_variant_iter_loop(iter, "s", &val);
                                        DBG("Value = %s", val);
-                                       ___bt_fill_le_supported_features(name, val, le_features);
+                                       _bt_hal_update_le_feature_support(name, val, &le_features);
                                        le_features_present = TRUE;
                                }
                                g_variant_iter_free(iter);
 
                                if (le_features_present) {
                                        size += __bt_insert_hal_properties(buf + size,
-                                                       HAL_PROP_ADAPTER_LOCAL_LE_FEAT, sizeof(le_features), le_features);
+                                                       HAL_PROP_ADAPTER_LOCAL_LE_FEAT, sizeof(le_features), &le_features);
                                        ev->num_props++;
                                } else {
                                        DBG("le supported features values are NOT provided by Stack");
index 6bce6f2..95ac2ff 100644 (file)
@@ -52,6 +52,8 @@ typedef struct {
        int adv_inst_max;
        int rpa_offloading;
        int max_filter;
+       int le_2m_phy;
+       int le_coded_phy;
 } bt_adapter_le_feature_info_t;
 
 typedef struct {
@@ -197,7 +199,9 @@ void _bt_hal_le_deinit(void)
 {
        __bt_hal_free_le_adv_slot();
 }
-gboolean _bt_hal_update_le_feature_support(const char *item, const char *value)
+
+gboolean _bt_hal_update_le_feature_support(const char *item, const char *value,
+                       bt_local_le_features_t *le_features)
 {
        if (item == NULL || value == NULL)
                return FALSE;
@@ -219,12 +223,45 @@ gboolean _bt_hal_update_le_feature_support(const char *item, const char *value)
                        INFO("Advertising instance max : %d", le_feature_info.adv_inst_max);
                        le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
                }
+               /* Fill LE feature bytes */
+               le_features->max_adv_instance = atoi(value);
+
        } else if (g_strcmp0(item, "rpa_offloading") == 0) {
                le_feature_info.rpa_offloading = atoi(value);
                INFO("RPA offloading : %d", le_feature_info.rpa_offloading);
+
+               /* Fill LE feature bytes */
+               le_features->rpa_offload_supported = atoi(value);
+
        } else if (g_strcmp0(item, "max_filter") == 0) {
                le_feature_info.max_filter = atoi(value);
                INFO("BLE Scan max filter : %d", le_feature_info.max_filter);
+
+               /* Fill LE feature bytes */
+               le_features->max_adv_filter_supported = atoi(value);
+
+       } else if (g_strcmp0(item, "2m_phy") == 0) {
+               if (g_strcmp0(value, "true") == 0) {
+                       le_feature_info.le_2m_phy = TRUE;
+                       /* Fill LE feature bytes */
+                       le_features->le_2m_phy_supported = 0x1;
+               } else {
+                       le_feature_info.le_2m_phy = FALSE;
+                       /* Fill LE feature bytes */
+                       le_features->le_2m_phy_supported = 0x0;
+               }
+               INFO("2M PHY Supported [%s]",  le_feature_info.le_2m_phy ? "TRUE" : "FALSE");
+       } else if (g_strcmp0(item, "coded_phy") == 0) {
+               if (g_strcmp0(value, "true") == 0) {
+                       le_feature_info.le_coded_phy = TRUE;
+                       /* Fill LE feature bytes */
+                       le_features->le_coded_phy_supported = 0x1;
+               } else {
+                       le_feature_info.le_coded_phy = FALSE;
+                       /* Fill LE feature bytes */
+                       le_features->le_coded_phy_supported = 0x0;
+               }
+               INFO("CODED PHY Supported [%s]",  le_feature_info.le_coded_phy ? "TRUE" : "FALSE");
        } else {
                DBG("No registered item");
                return FALSE;
index 5676b6e..1c802ad 100644 (file)
@@ -43,7 +43,8 @@ void _bt_hal_register_gatt_le_dbus_handler_cb(handle_stack_msg cb);
 
 void _bt_hal_unregister_gatt_le_dbus_handler_cb();
 
-gboolean _bt_hal_update_le_feature_support(const char *item, const char *value);
+gboolean _bt_hal_update_le_feature_support(const char *item, const char *value,
+                        bt_local_le_features_t *le_features);
 
 int _bt_hal_get_available_adv_slot_id(bt_uuid_t *uuid);
 
index 62dd3f2..8161fdc 100644 (file)
@@ -434,18 +434,31 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                        char *val = NULL;
                        GVariantIter *iter = NULL;
                        g_variant_get(value, "as", &iter);
+                       bt_local_le_features_t le_features;
+                        gboolean le_features_present = FALSE;
 
                        if (iter == NULL)
                                continue;
 
+                       memset(&le_features, 0x00, sizeof(le_features));
+
                        while (g_variant_iter_next(iter, "&s", &name) &&
-                               g_variant_iter_next(iter, "&s", &val)) {
+                                       g_variant_iter_next(iter, "&s", &val)) {
                                DBG("name = %s, Value = %s", name, val);
-                               if (FALSE == _bt_hal_update_le_feature_support(name, val))
+                               if (FALSE == _bt_hal_update_le_feature_support(name, val, &le_features))
                                        ERR("Failed to update LE feature (name = %s, value = %s)", name, val);
+                               else
+                                       le_features_present = TRUE;
                        }
 
                        g_variant_iter_free(iter);
+                       if (le_features_present) {
+                               size += __bt_insert_hal_properties(buf + size,
+                                               HAL_PROP_ADAPTER_LOCAL_LE_FEAT, sizeof(le_features), &le_features);
+                               ev->num_props++;
+                       } else {
+                               DBG("le supported features values are NOT provided by Stack");
+                       }
                } else if (!g_strcmp0(key, "IpspInitStateChanged")) {
                        g_variant_get(value, "b" , &ipsp_initialized);
                        DBG("##IPSP Initialized = %d", ipsp_initialized);
index 9891830..10ef16e 100644 (file)
@@ -674,8 +674,7 @@ static void local_le_feat2string(char *str, const bt_local_le_features_t *f, int
        str += ret;
        buf_len -= ret;
 
-       scan_num = (f->scan_result_storage_size_hibyte << 8) +
-               f->scan_result_storage_size_lobyte;
+       scan_num = f->scan_result_storage_size;
 
        ret = snprintf(str, buf_len, "Num of offloaded scan results: %u,\n", scan_num);
        if (0 > ret) {
@@ -694,6 +693,24 @@ static void local_le_feat2string(char *str, const bt_local_le_features_t *f, int
        str += ret;
        buf_len -= ret;
 
+       ret = snprintf(str, buf_len, "LE 2M PHY Support: %s\n",
+                       f->le_2m_phy_supported ? "TRUE" : "FALSE");
+       if (0 > ret) {
+               ERR("snprintf failed with %d", ret);
+               return;
+       }
+       str += ret;
+       buf_len -= ret;
+
+       ret = snprintf(str, buf_len, "LE CODED PHY Support: %s\n",
+                       f->le_coded_phy_supported ? "TRUE" : "FALSE");
+       if (0 > ret) {
+               ERR("snprintf failed with %d", ret);
+               return;
+       }
+       str += ret;
+       buf_len -= ret;
+
        ret = snprintf(str, buf_len, "}");
        if (0 > ret) {
                ERR("snprintf failed with %d", ret);
index 4cec7a5..65a7e8e 100755 (executable)
@@ -429,14 +429,19 @@ void local_le_feat_2_string(char *str, const bt_local_le_features_t *f)
        str += sprintf(str, "Num of offloaded scan filters: %u,\n",
                        f->max_adv_filter_supported);
 
-       scan_num = (f->scan_result_storage_size_hibyte << 8) +
-               f->scan_result_storage_size_lobyte;
+       scan_num = f->scan_result_storage_size;
 
        str += sprintf(str, "Num of offloaded scan results: %u,\n", scan_num);
 
        str += sprintf(str, "Activity & energy report support: %s\n",
                        f->activity_energy_info_supported ? "TRUE" : "FALSE");
 
+       str += sprintf(str, "LE 2M PHY support: %s\n",
+                       f->le_2m_phy_supported ? "TRUE" : "FALSE");
+
+       str += sprintf(str, "LE Coded PHY support: %s\n",
+                       f->le_coded_phy_supported ? "TRUE" : "FALSE");
+
        sprintf(str, "}");
 }
 
index 2971117..6b9138f 100644 (file)
@@ -145,6 +145,27 @@ typedef struct {
        int manufacturer;
 } bt_remote_version_t;
 
+
+typedef struct {
+       uint16_t version_supported;
+       uint8_t local_privacy_enabled;
+       uint8_t max_adv_instance;
+       uint8_t rpa_offload_supported;
+       uint8_t max_irk_list_size;
+       uint8_t max_adv_filter_supported;
+       uint8_t activity_energy_info_supported;
+       uint16_t scan_result_storage_size;
+       uint16_t total_trackable_advertisers;
+       bool extended_scan_support;
+       bool debug_logging_supported;
+       bool le_2m_phy_supported;
+       bool le_coded_phy_supported;
+       bool le_extended_advertising_supported;
+       bool le_periodic_advertising_supported;
+       uint16_t le_maximum_advertising_data_length;
+} bt_local_le_features_t;
+
+/*
 typedef struct {
        uint8_t local_privacy_enabled;
        uint8_t max_adv_instance;
@@ -154,7 +175,7 @@ typedef struct {
        uint8_t scan_result_storage_size_lobyte;
        uint8_t scan_result_storage_size_hibyte;
        uint8_t activity_energy_info_supported;
-} bt_local_le_features_t;
+} bt_local_le_features_t;*/
 
 /* Bluetooth Adapter and Remote Device property types */
 typedef enum {
index 97fde1c..472b9ad 100644 (file)
@@ -137,6 +137,7 @@ extern "C" {
        EVENT(OAL_EVENT_BLE_DISCOVERY_STARTED)                          /* NULL */\
        EVENT(OAL_EVENT_BLE_DISCOVERY_STOPPED)                          /* NULL */\
        EVENT(OAL_EVENT_BLE_REMOTE_DEVICE_FOUND)                /* event_ble_scan_result_info */\
+       EVENT(OAL_EVENT_BLE_LOCAL_FEATURES)                     /* adapter le features */\
        EVENT(OAL_EVENT_GATTS_SERVICE_ADDED)                /* gatts Service Added */\
        EVENT(OAL_EVENT_GATTS_INCLUDED_SERVICE_ADDED)       /* gatts Included Service Added */\
        EVENT(OAL_EVENT_GATTS_SERVICE_STARTED)              /* gatts Service Started */\
@@ -212,6 +213,15 @@ typedef struct {
 } event_adapter_services_t;
 
 typedef struct {
+       /* TODO Add more features */
+       uint8_t  max_adv_instance;
+       uint8_t rpa_offloading;
+       uint8_t max_adv_filter;
+       uint8_t le_2m_phy_support;
+       uint8_t le_coded_phy_support;
+} event_adapter_le_features_t;
+
+typedef struct {
        remote_device_t device_info;
        uint8_t adv_data[62];
        int adv_len;
index f12a508..679906f 100644 (file)
@@ -555,13 +555,11 @@ oal_status_t adapter_get_service_uuids(void)
        CHECK_OAL_INITIALIZED();
 
        API_TRACE();
-
        ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
                return convert_to_oal_status(ret);
        }
-
        return OAL_STATUS_SUCCESS;
 }
 
@@ -716,6 +714,8 @@ static void cb_adapter_properties(bt_status_t status,
 
        BT_DBG("status: %d, count: %d", status, num_properties);
 
+       print_bt_properties(num_properties, properties);
+
        if (status != BT_STATUS_SUCCESS) {
                if (num_properties == 1) {
                        BT_ERR("Adapter Prop failed: status: [%s], count: %d, prop: %d",
@@ -848,6 +848,25 @@ static void cb_adapter_properties(bt_status_t status,
                                        event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
                        break;
                }
+               case BT_PROPERTY_LOCAL_LE_FEATURES: {
+                       event_adapter_le_features_t *le_features;
+
+                       le_features = g_malloc(sizeof(event_adapter_le_features_t));
+
+                       le_features->max_adv_instance = ((bt_local_le_features_t *)(properties[i].val))->max_adv_instance;
+                       le_features->rpa_offloading = ((bt_local_le_features_t *)(properties[i].val))->rpa_offload_supported;
+                       le_features->max_adv_filter = ((bt_local_le_features_t *)(properties[i].val))->max_adv_filter_supported;
+                       le_features->le_2m_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
+                       le_features->le_coded_phy_support = ((bt_local_le_features_t *)(properties[i].val))->le_2m_phy_supported;
+
+                       BT_INFO("LE 2M PHY Support (%d)", le_features->le_2m_phy_support);
+                       BT_INFO("LE CODED PHY Support (%d)", le_features->le_coded_phy_support);
+
+                       send_event(OAL_EVENT_BLE_LOCAL_FEATURES,
+                                       le_features,
+                                       sizeof(event_adapter_le_features_t));
+                       break;
+               }
                default:
                         BT_WARN("Unhandled property: %d", properties[i].type);
                         break;
index 676153b..353a8ec 100644 (file)
@@ -52,6 +52,17 @@ static const char BASE_UUID_CONVERTED[BT_UUID_128] = {
 };
 
 typedef struct {
+        int adv_inst_max;
+        int rpa_offloading;
+        int max_filter;
+       int le_2m_phy;
+       int le_coded_phy;
+} bt_adapter_le_feature_info_t;
+
+/* Set Default values */
+static bt_adapter_le_feature_info_t le_feature_info = {1, 0, 0, 0, 0};
+
+typedef struct {
        int adv_handle;
        char *sender;
        int data_len;
@@ -698,6 +709,17 @@ static void __bt_le_event_handler(int event_type, gpointer event_data)
                g_gatt_client_id = gattc_event->client_if;
                break;
        }
+       case OAL_EVENT_BLE_LOCAL_FEATURES: {
+               event_adapter_le_features_t *le_features = event_data;
+
+               le_feature_info.le_2m_phy = le_features->le_2m_phy_support;
+               le_feature_info.le_coded_phy = le_features->le_coded_phy_support;
+
+               BT_INFO("Adapter LE 2M PHY Support [%s]", le_feature_info.le_2m_phy ? "TRUE" : "FALSE");
+               BT_INFO("Adapter LE CODED PHY Support [%s]", le_feature_info.le_coded_phy ? "TRUE" : "FALSE");
+
+               break;
+       }
        default:
                break;
        }
index bdb14fe..74c3782 100644 (file)
@@ -360,6 +360,7 @@ static gboolean __bt_handle_oal_events(gpointer data)
        case OAL_EVENT_BLE_DISCOVERY_STARTED:
        case OAL_EVENT_BLE_DISCOVERY_STOPPED:
        case OAL_EVENT_BLE_REMOTE_DEVICE_FOUND:
+       case OAL_EVENT_BLE_LOCAL_FEATURES:
                if (adapter_le_cb)
                        adapter_le_cb(event_type, event_data);
                break;