BT 5.0 : Support for Extended Advertisement 15/297615/2
authorAnuj Jain <anuj01.jain@samsung.com>
Mon, 21 Aug 2023 12:26:06 +0000 (17:56 +0530)
committerAnuj Jain <anuj01.jain@samsung.com>
Mon, 21 Aug 2023 13:59:06 +0000 (19:29 +0530)
This patch provides initial support for extended advertisement.

As there is no support for Extended advertisement on bluez layer
therefore this feature is currently disabled.

Change-Id: Ic38a433b6438cc81606f120fe96190a301877389
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
17 files changed:
bt-api/bt-adapter-le.c
bt-httpproxy/bt-httpproxy.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-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-otp/bt-otpserver.c
bt-service/services/adapter/bt-service-core-adapter-le.c
bt-service/services/bt-request-handler.c
bt-service/services/include/bt-service-core-adapter-le.h
include/bluetooth-api.h
include/bt-internal-types.h
test/le-adv/bluetooth-advertising-test.c

index 4bdf2f7..f6798d4 100644 (file)
@@ -356,10 +356,18 @@ BT_EXPORT_API int bluetooth_get_advertising_data(bluetooth_advertising_data_t *a
        return result;
 }
 
-BT_EXPORT_API int bluetooth_set_advertising_data(int handle, const bluetooth_advertising_data_t *value, int length)
+BT_EXPORT_API int bluetooth_set_advertising_data(int handle,
+               const bluetooth_advertising_data_t *value, int length , bool is_legacy)
 {
        int result;
-       gboolean use_reserved_slot = TRUE;
+
+       bluetooth_le_slot_and_adv_type_t rs_at;
+       rs_at.is_legacy = is_legacy;
+       rs_at.use_reserved_slot = TRUE;
+
+       int max_adv_data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX;
+       /* TODO : Change to following once LE EXTENDED feature is supported
+       int max_adv_data_len = is_legacy ? BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX : BLUETOOTH_EXTENDED_ADVERTISING_DATA_LENGTH_MAX; */
 
        BT_CHECK_PARAMETER(value, return);
        BT_CHECK_ENABLED_ANY(return);
@@ -369,11 +377,11 @@ BT_EXPORT_API int bluetooth_set_advertising_data(int handle, const bluetooth_adv
                return BLUETOOTH_ERROR_INVALID_PARAM;
        }
 
-       if (length > BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 3)
+       if (length > max_adv_data_len- 3)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
        if (TIZEN_PROFILE_WEARABLE)
-               use_reserved_slot = __bluetooth_is_privileged_process();
+               rs_at.use_reserved_slot = __bluetooth_is_privileged_process();
 
        BT_INIT_PARAMS();
        BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
@@ -381,7 +389,7 @@ BT_EXPORT_API int bluetooth_set_advertising_data(int handle, const bluetooth_adv
        g_array_append_vals(in_param1, &handle, sizeof(int));
        g_array_append_vals(in_param2, value, sizeof(bluetooth_advertising_data_t));
        g_array_append_vals(in_param3, &length, sizeof(int));
-       g_array_append_vals(in_param4, &use_reserved_slot, sizeof(gboolean));
+       g_array_append_vals(in_param4, &rs_at, sizeof(bluetooth_le_slot_and_adv_type_t));
 
        result = _bt_send_request(BT_BLUEZ_SERVICE, BT_SET_ADVERTISING_DATA,
                in_param1, in_param2, in_param3, in_param4, &out_param);
index d9f57f9..29bc11e 100644 (file)
@@ -1435,7 +1435,7 @@ int _bt_hps_set_advertising_data(void)
 
        BT_DBG("%x %x %x %x", data[0], data[1], data[2], data[3]);
        memcpy(adv.data, data, sizeof(data));
-       ret = bluetooth_set_advertising_data(0, &adv, sizeof(data));
+       ret = bluetooth_set_advertising_data(0, &adv, sizeof(data), TRUE);
        if (ret != BLUETOOTH_ERROR_NONE) {
                BT_ERR("Failed to set ADV data %d", ret);
                return ret;
index 34bf09e..4c27425 100644 (file)
@@ -689,8 +689,11 @@ int _bt_hal_enable_advertising(int server_if, int adv_slot_id, bool enable, bool
 
 int _bt_hal_set_advertising_params(int server_if, int min_interval,
                int max_interval, int adv_type,
-               int chnl_map, int tx_power, int timeout_s)
+               int chnl_map, int tx_power, int timeout_s,
+               bool is_legacy, int primary_phy, int secondary_phy)
 {
+       /*TODO : Handle is_legacy, primary_phy, secondary_phy parameters
+       * once LE_EXTENDED feature is supported */
        GDBusProxy *proxy;
        GVariant *ret;
        GError *error = NULL;
index 9a3a129..a367aa0 100644 (file)
@@ -70,7 +70,7 @@ int _bt_hal_set_advertising_data(btgatt_adv_param_setup_t adv_param_setup);
 
 int _bt_hal_set_advertising_params(int server_if, int min_interval,
                int max_interval, int adv_type,
-               int chnl_map, int tx_power, int timeout_s);
+               int chnl_map, int tx_power, int timeout_s, bool is_legacy, int primary_phy, int secondary_phy);
 
 int _bt_hal_enable_advertising(int server_if, int adv_slot_id, bool enable, bool is_multi_adv);
 
index dfc766a..290c0d8 100644 (file)
@@ -3756,13 +3756,13 @@ static bt_status_t gatt_server_multi_adv_enable(int server_if)
 }
 
 static bt_status_t gatt_server_multi_adv_update(int server_if, int min_interval, int max_interval, int adv_type,
-               int chnl_map, int tx_power, int timeout_s)
+               int chnl_map, int tx_power, int timeout_s, bool is_legacy, int primary_phy, int secondary_phy)
 {
        CHECK_BTGATT_INIT();
 
        /* Send Advertising parameters to LE Module */
        return _bt_hal_set_advertising_params(server_if, min_interval, max_interval, adv_type,
-                       chnl_map, tx_power, timeout_s);
+                       chnl_map, tx_power, timeout_s, is_legacy, primary_phy, secondary_phy);
 }
 
 static bt_status_t gatt_server_set_filter_policy(int filter_policy)
index 2efc554..4b9a82e 100644 (file)
@@ -274,7 +274,7 @@ typedef struct {
 
        /* Update the parameters as per spec, user manual specified values and restart multi ADV */
        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);
+                       int chnl_map, int tx_power, int timeout_s, bool is_legacy, int primary_phy, int secondary_phy);
 
        /* Set the filter_policy value in the HAL Layer */
        bt_status_t (*set_filter_policy)(int filter_policy);
index c3c386a..1d55976 100644 (file)
@@ -441,7 +441,7 @@ oal_status_t adapter_ble_multi_adv_set_inst_data(int instance_id, oal_ble_multi_
  * @see  gatts_multi_adv_set_inst_data()
  */
 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);
+               int adv_type, int chnl_map, int tx_power, int timeout_s, bool is_legacy, int primary_phy, int secondary_phy);
 
 /**
  * @brief Set Advertising filter policy for a advertiser
index 86161ab..4adaf80 100644 (file)
@@ -96,6 +96,9 @@ typedef struct {
        uint8_t  timeout_s;
        char*    tds_data;
        uint16_t tds_data_len;
+       gboolean is_legacy;
+       uint8_t primary_phy;
+       uint8_t secondary_phy;
 } oal_ble_multi_adv_param_setup_t;
 
 typedef struct {
@@ -260,8 +263,8 @@ oal_status_t gatts_multi_adv_disable(int instance_id);
  * @see  gatts_multi_adv_enable()
  */
 oal_status_t gatts_multi_adv_update(int instance_id, int min_intv, int max_intv,
-               int adv_type, int chnl_map,
-               int tx_power, int timeout_s);
+               int adv_type, int chnl_map, int tx_power, int timeout_s,
+               gboolean is_legacy, int primary_phy, int secondary_phy);
 
 /**
  * @brief sets the filter policy for a particular advertiser in HAL layer.
index dda21a9..1abb39d 100644 (file)
@@ -770,14 +770,16 @@ oal_status_t adapter_ble_set_filter_policy(int filter_policy)
 }
 
 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)
+                       int adv_type, int chnl_map, int tx_power, int timeout_s,
+                       bool is_legacy, int primary_phy, int secondary_phy)
 {
        int res;
        CHECK_OAL_INITIALIZED();
        API_TRACE();
 
        res = gatts_multi_adv_update(Ins_id, min_intv, max_intv,
-                       adv_type, chnl_map, tx_power, timeout_s);
+                       adv_type, chnl_map, tx_power, timeout_s,
+                       is_legacy, primary_phy, secondary_phy);
        if (res != OAL_STATUS_SUCCESS) {
                BT_ERR("gatts_multi_adv_update: [%d]", res);
                return res;
index 94e0ab0..039dd7e 100644 (file)
@@ -514,7 +514,8 @@ oal_status_t gatts_set_filter_policy(int filter_policy)
 oal_status_t gatts_multi_adv_update(int instance_id,
                int min_intv, int max_intv,
                int adv_type, int chnl_map,
-               int tx_power, int timeout_s)
+               int tx_power, int timeout_s,
+               gboolean is_legacy,int primary_phy, int secondary_phy)
 {
        int ret = OAL_STATUS_SUCCESS;
        API_TRACE("Multi advertising Update");
@@ -528,9 +529,9 @@ oal_status_t gatts_multi_adv_update(int instance_id,
                return OAL_STATUS_NOT_SUPPORT;
 
        ret = gatt_api->server->multi_adv_update(instance_id,
-                       min_intv, max_intv,
-                       adv_type, chnl_map,
-                       tx_power, timeout_s);
+                       min_intv, max_intv, adv_type, chnl_map,
+                       tx_power, timeout_s, is_legacy, primary_phy,
+                       secondary_phy);
        if (ret != BT_STATUS_SUCCESS) {
                BT_ERR("GATT update multi advertising failed for server Instance: %d With Status: %s",
                                instance_id, status2string(ret));
index 903caee..43be7e0 100644 (file)
@@ -488,7 +488,7 @@ int _bt_otp_set_advertising_data(void)
 
        BT_DBG("%x %x %x %x", data[0], data[1], data[2], data[3]);
        memcpy(adv.data, data, sizeof(data));
-       ret = bluetooth_set_advertising_data(adv_handle, &adv, sizeof(data));
+       ret = bluetooth_set_advertising_data(adv_handle, &adv, sizeof(data), TRUE);
        if (ret != BLUETOOTH_ERROR_NONE) {
                BT_ERR("Failed to set ADV data %d", ret);
                return ret;
index 631777c..5ff7cd0 100644 (file)
@@ -377,6 +377,8 @@ static void __bt_le_handle_server_instance_registered(event_gatts_register_t *da
        bluetooth_scan_resp_data_t scan_rsp;
        int result = BLUETOOTH_ERROR_NONE;
        bt_pending_adv_data_set_t *info = NULL;
+       bluetooth_le_slot_and_adv_type_t rs_at;
+       rs_at.use_reserved_slot = FALSE;
 
        memset(adv.data, 0, sizeof(adv.data));
        memset(scan_rsp.data, 0, sizeof(scan_rsp.data));
@@ -396,8 +398,9 @@ static void __bt_le_handle_server_instance_registered(event_gatts_register_t *da
                                        BT_INFO("LE Data set request is pending");
                                        if (info->is_adv) {
                                                memcpy(&adv.data, info->data, info->data_len);
+                                               rs_at.is_legacy = info->params.is_legacy;
                                                result = _bt_set_advertising_data(info->sender,
-                                                       info->adv_handle, &adv, info->data_len, FALSE);
+                                                       info->adv_handle, &adv, info->data_len, &rs_at);
                                                if (result != BLUETOOTH_ERROR_NONE) {
                                                        __bt_adapter_le_handle_pending_request_info(result,
                                                                BT_SET_ADVERTISING_DATA,
@@ -1448,7 +1451,8 @@ int _bt_set_custom_advertising(const char *sender, int adv_handle,
                }
                /* 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);
+                               params->type, BT_ADV_DEFAULT_CHANNEL_MAP, params->tx_power_level, BT_ADV_DEFAULT_TIMEOUT,
+                               params->is_legacy, params->primary_phy, params->secondary_phy);
                if (result != OAL_STATUS_SUCCESS) {
                        BT_ERR("OAL API adapter_ble_multi_adv_update Fail %d", result);
                        return _bt_convert_oal_status_to_bt_error(result);
@@ -1678,7 +1682,7 @@ static int __bt_set_multi_adv_param(oal_ble_multi_adv_param_setup_t *adv_setup,
 }
 
 int _bt_set_advertising_data(const char *sender, int adv_handle,
-               bluetooth_advertising_data_t *adv, int length, gboolean use_reserved_slot)
+               bluetooth_advertising_data_t *adv, int length, bluetooth_le_slot_and_adv_type_t *rs_at)
 {
        BT_CHECK_PARAMETER(adv, return);
        BT_CHECK_PARAMETER(sender, return);
@@ -1693,7 +1697,11 @@ int _bt_set_advertising_data(const char *sender, int adv_handle,
        int result = OAL_STATUS_SUCCESS;
        BT_DBG("+");
 
-       if (length > BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
+       int max_adv_data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX;
+       /* TODO : Change to following once LE EXTENDED feature is supported
+       int max_adv_data_len = rs_at->is_legacy ? BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX : BLUETOOTH_EXTENDED_ADVERTISING_DATA_LENGTH_MAX; */
+
+       if (length > max_adv_data_len)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
        if (__bt_is_factory_test_mode()) {
@@ -1701,7 +1709,7 @@ int _bt_set_advertising_data(const char *sender, int adv_handle,
                return BLUETOOTH_ERROR_NOT_SUPPORT;
        }
 
-       server_instance = _bt_get_allocated_server_instance(sender, adv_handle, use_reserved_slot);
+       server_instance = _bt_get_allocated_server_instance(sender, adv_handle, rs_at->use_reserved_slot);
 
        if (server_instance == -1) {
                BT_DBG("No available slot for the current sender and handle combination");
@@ -1720,6 +1728,7 @@ int _bt_set_advertising_data(const char *sender, int adv_handle,
                                info->data_len = length;
                                info->is_adv = TRUE;
                                info->is_data_set_pending = TRUE;
+                               info->params.is_legacy = rs_at->is_legacy;
                                memcpy(&info->data, &(adv->data[0]), length);
                                adv_data_pending_list = g_slist_append(adv_data_pending_list, info);
                                return BLUETOOTH_ERROR_NONE;
@@ -1756,6 +1765,8 @@ int _bt_set_advertising_data(const char *sender, int adv_handle,
        /* Set Server instance[Product Requirement] */
        adv_setup.tx_power = 4;
 
+       adv_setup.is_legacy = rs_at->is_legacy;
+
        BT_DBG("Service UUID len [%d], service data len [%d] Solicit UUID len [%d]",
                                adv_setup.solicit_uuid_len, adv_setup.service_uuid_len, adv_setup.service_data_len);
        result = adapter_ble_multi_adv_set_inst_data(server_instance, &adv_setup);
index 3efec07..4370d50 100644 (file)
@@ -2294,7 +2294,9 @@ int __bt_bluez_request(int function_name,
                int *adv_handle;
                bluetooth_advertising_data_t adv = { {0} };
                int length;
-               gboolean use_reserved_slot = FALSE;
+               bluetooth_le_slot_and_adv_type_t rs_at;
+               rs_at.is_legacy = TRUE;
+               rs_at.use_reserved_slot = FALSE;
 
                app = (char *)g_dbus_method_invocation_get_sender(context);
                adv_handle = g_malloc0(sizeof(int));
@@ -2306,9 +2308,9 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param2,
                                &adv, length);
                __bt_service_get_parameters(in_param4,
-                               &use_reserved_slot, sizeof(gboolean));
+                               &rs_at, sizeof(bluetooth_le_slot_and_adv_type_t));
                result = _bt_set_advertising_data(app, *adv_handle,
-                               &adv, length, use_reserved_slot);
+                               &adv, length, &rs_at);
                if (result != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("Set Advertising data failed!!");
                        g_free(adv_handle);
index 3c82ca4..97838ed 100644 (file)
@@ -75,7 +75,7 @@ int _bt_set_advertising(const char *sender, int adv_handle, gboolean enable, gbo
 
 int _bt_set_custom_advertising(const char *sender, int adv_handle, gboolean enable, bluetooth_advertising_params_t *params, gboolean use_reserved_slot);
 
-int _bt_set_advertising_data(const char *sender, int adv_handle, bluetooth_advertising_data_t *data, int length, gboolean use_reserved_slot);
+int _bt_set_advertising_data(const char *sender, int adv_handle, bluetooth_advertising_data_t *data, int length, bluetooth_le_slot_and_adv_type_t *rs_at);
 
 int _bt_set_scan_response_data(const char *sender, int adv_handle, bluetooth_scan_resp_data_t *response, int length, gboolean use_reserved_slot);
 
index 252c7d9..b892916 100644 (file)
@@ -444,6 +444,8 @@ typedef enum {
  * Advertising data
  */
 typedef struct {
+       /* TODO : Change to BLUETOOTH_EXTENDED_ADVERTISING_DATA_LENGTH_MAX
+        * once LE EXTENDED feature is supported */
        guint8 data[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX];
 } bluetooth_advertising_data_t;
 
@@ -623,6 +625,9 @@ typedef struct {
        guint8 filter_policy;
        guint8 type;
        int tx_power_level;
+       gboolean is_legacy;
+       int primary_phy;
+       int secondary_phy;
 } bluetooth_advertising_params_t;
 
 /**
@@ -1305,6 +1310,11 @@ typedef struct {
        guint8 data[BLUETOOTH_EXTENDED_ADVERTISING_DATA_LENGTH_MAX];
 } bluetooth_extended_advertising_data_t;
 
+typedef struct{
+       gboolean use_reserved_slot;
+       gboolean is_legacy;
+} bluetooth_le_slot_and_adv_type_t;
+
 typedef struct {
        int data_len;           /**< manafacturer specific data length */
        bluetooth_extended_advertising_data_t data;             /**< manafacturer specific data */
@@ -6306,7 +6316,7 @@ int bluetooth_get_advertising_data(bluetooth_advertising_data_t *value, int *len
  *
  * @remark     None
  */
-int bluetooth_set_advertising_data(int handle, const bluetooth_advertising_data_t *value, int length);
+int bluetooth_set_advertising_data(int handle, const bluetooth_advertising_data_t *value, int length, bool is_legacy);
 
 /**
  * @fn int bluetooth_check_privilege_advertising_parameter(void);
index a6fa094..a8cf78d 100644 (file)
@@ -211,6 +211,7 @@ typedef enum {
        BT_IS_ADVERTISING,
        BT_IS_LE_2M_PHY_SUPPORTED,
        BT_IS_LE_CODED_PHY_SUPPORTED,
+       BT_GET_MAXIMUM_ADVERTISING_DATA_LENGTH,
        BT_SET_MANUFACTURER_DATA,
        BT_LE_CONN_UPDATE,
        BT_LE_READ_MAXIMUM_DATA_LENGTH,
index b985fa0..c86ed9b 100644 (file)
@@ -132,7 +132,7 @@ int test_input_callback(void *data)
                TC_PRT("%x %x %x %x %x %x", data[0], data[1], data[2], data[3],
                                data[4], data[5]);
                memcpy(adv.data, data, sizeof(data));
-               ret = bluetooth_set_advertising_data(0, &adv, sizeof(data));
+               ret = bluetooth_set_advertising_data(0, &adv, sizeof(data), TRUE);
                break;
        }
        case 6: