Merge "Adapt the set advertising filter policy in BT-HAL framework." into tizen
authorPyun DoHyun <dh79.pyun@samsung.com>
Wed, 18 Dec 2019 22:51:15 +0000 (22:51 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Wed, 18 Dec 2019 22:51:15 +0000 (22:51 +0000)
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-gatt-server.c
bt-oal/hardware/bt_gatt_server.h
bt-oal/include/oal-adapter-mgr.h
bt-oal/include/oal-gatt.h
bt-oal/oal-adapter-mgr.c
bt-oal/oal-gatt.c
bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c

index 5f561d9..ddfe6c3 100644 (file)
@@ -101,11 +101,15 @@ typedef struct {
 
 handle_stack_msg gatt_le_event_cb;
 
+/* Advertising filter_policy */
+static int adv_filter_policy;
+
 /* Forward declarations */
 static gboolean __bt_hal_is_factory_test_mode(void);
 static void __bt_hal_free_le_adv_slot(void);
 static gboolean __bt_hal_adv_event_cb(gpointer param);
 
+
 #ifdef TIZEN_BT_HAL
 /* Enable LE Adapter */
 int _bt_hal_le_enable(void)
@@ -119,6 +123,11 @@ int _bt_hal_le_disable(void)
        return _bt_hal_dbus_disable_le();
 }
 
+void _bt_hal_set_filter_policy_param(int filter_policy)
+{
+       adv_filter_policy = filter_policy;
+}
+
 int _bt_hal_set_le_static_random_address(uint8_t enable)
 {
        DBG("+");
@@ -679,6 +688,10 @@ int _bt_hal_set_advertising_params(int server_if, int min_interval,
                        adv_type == BT_HAL_ADV_NON_CONNECTABLE)
                return BT_STATUS_UNSUPPORTED;
 
+       if (adv_filter_policy < 0 || adv_filter_policy > 3) {
+               ERR("Invalid filter policy, Setting the filter policy to default");
+               adv_filter_policy = BT_HAL_ADV_FILTER_POLICY_DEFAULT;
+       }
 
        min = min_interval / BT_HAL_ADV_INTERVAL_SPLIT;
        max = max_interval / BT_HAL_ADV_INTERVAL_SPLIT;
@@ -687,7 +700,7 @@ int _bt_hal_set_advertising_params(int server_if, int min_interval,
 
        ret = g_dbus_proxy_call_sync(proxy, "SetAdvertisingParameters",
                        g_variant_new("(uuuuii)", min, max,
-                       BT_HAL_ADV_FILTER_POLICY_DEFAULT, adv_type,
+                       adv_filter_policy, adv_type,
                        tx_power, slot_id), G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL, &error);
        if (error) {
index 75da4c5..e9965e0 100644 (file)
@@ -38,6 +38,8 @@ int _bt_hal_le_enable(void);
 
 int _bt_hal_le_disable(void);
 
+void _bt_hal_set_filter_policy_param(int filter_policy);
+
 int _bt_hal_set_le_static_random_address(uint8_t enable);
 #endif
 
index d1eabe8..90550f0 100644 (file)
@@ -3573,6 +3573,14 @@ static bt_status_t gatt_server_multi_adv_update(int server_if, int min_interval,
                        chnl_map, tx_power, timeout_s);
 }
 
+static bt_status_t gatt_server_set_filter_policy(int filter_policy)
+{
+       CHECK_BTGATT_INIT();
+       DBG("+");
+       /* Send the Filter policy parameter to LE Module */
+        _bt_hal_set_filter_policy_param(filter_policy);
+       return BT_STATUS_SUCCESS;
+}
 
 static bt_status_t gatt_server_multi_adv_set_inst_data(btgatt_adv_param_setup_t adv_param_setup)
 {
@@ -3709,6 +3717,7 @@ const btgatt_server_interface_t btgatt_server_interface = {
        .set_adv_data = gatt_server_set_adv_data,
        .multi_adv_enable = gatt_server_multi_adv_enable,
        .multi_adv_update = gatt_server_multi_adv_update,
+       .set_filter_policy = gatt_server_set_filter_policy,
        .multi_adv_set_inst_data = gatt_server_multi_adv_set_inst_data,
        .multi_adv_disable = gatt_server_multi_adv_disable,
        .get_att_mtu = gatt_server_get_mtu_size,
index 2118615..d1fd236 100644 (file)
@@ -268,6 +268,9 @@ typedef struct {
        bt_status_t (*multi_adv_update)(int server_if, int min_interval, int max_interval, int adv_type,
                        int chnl_map, int tx_power, int timeout_s);
 
+       /* Set the filter_policy value in the HAL Layer */
+       bt_status_t (*set_filter_policy)(int filter_policy);
+
        /* Setup the data for the specified instance */
        bt_status_t (*multi_adv_set_inst_data)(btgatt_adv_param_setup_t adv_param_setup);
 
index 71ebadf..8e709f9 100644 (file)
@@ -415,6 +415,17 @@ oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv
                int adv_type, int chnl_map, int tx_power, int timeout_s);
 
 /**
+ * @brief Set Advertising filter policy for a advertiser
+ *
+ * @param filter_policy Type of policy to be used for a particular advertiser.
+ *
+ * @return OAL_STATUS_SUCCESS on success.
+ *
+ * @pre Adapter must be enabled with adapter_enable()
+ */
+oal_status_t adapter_ble_set_filter_policy(int filter_policy);
+
+/**
  * @brief Enable Multi Advertising on specific Instance ID
  *
  * @param instance_id Multi advertising slot ID initialized by stack
index 4067865..18ba689 100644 (file)
@@ -254,6 +254,11 @@ oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
                int tx_power, int timeout_s);
 
 /**
+ * @brief sets the filter policy for a particular advertiser in HAL layer.
+ */
+oal_status_t gatts_set_filter_policy(int filter_policy);
+
+/**
  * @brief Sets the the Multiple Advertising Data
  *
  * @remarks  The Multiple advertising data will be set.
index 886d3f9..544e639 100644 (file)
@@ -679,6 +679,25 @@ oal_status_t adapter_set_discoverable_timeout(int timeout)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t adapter_ble_set_filter_policy(int filter_policy)
+{
+       int ret = OAL_STATUS_SUCCESS;
+
+       CHECK_OAL_INITIALIZED();
+       API_TRACE();
+
+       BT_DBG("Filter policy applied is [%d]", filter_policy);
+
+       ret = gatts_set_filter_policy(filter_policy);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("gatts_set_filter_policy: [%d]", ret);
+               return ret;
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t adapter_ble_multi_adv_update(int Ins_id, int min_intv, int max_intv,
                        int adv_type, int chnl_map, int tx_power, int timeout_s)
 {
index c5b8956..16b3acc 100644 (file)
@@ -527,6 +527,23 @@ oal_status_t gatts_multi_adv_disable(int instance_id)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t gatts_set_filter_policy(int filter_policy)
+{
+       int ret = OAL_STATUS_SUCCESS;
+
+       CHECK_OAL_GATT_ENABLED();
+
+       /* send the filter_policy value to the HAL Layer */
+       ret = gatt_api->server->set_filter_policy(filter_policy);
+
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("set_filter_policy failed: %d",ret);
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t gatts_multi_adv_update(int instance_id,
                int min_intv, int max_intv,
                int adv_type, int chnl_map,
index 12e13ac..203834d 100644 (file)
@@ -1384,6 +1384,13 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
        }
 
        if (enable) {
+               /* Set the Advertising filter policy Parameter in HAL */
+               result = adapter_ble_set_filter_policy(params->filter_policy);
+
+               if (result != OAL_STATUS_SUCCESS){
+                       BT_ERR("OAL API adapter_ble_set_filter_policy Fail %d", result);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
                /* Set Advertising parameters to Stack */
                result = adapter_ble_multi_adv_update(server_instance, params->interval_min, params->interval_max,
                                params->type, BT_ADV_DEFAULT_CHANNEL_MAP, params->tx_power_level, BT_ADV_DEFAULT_TIMEOUT);