From a8b03d7b300236a8d63746b1d9eeb1c198ce04a0 Mon Sep 17 00:00:00 2001 From: himanshu Date: Thu, 3 Oct 2019 13:09:14 +0530 Subject: [PATCH] Port the Set LE Privacy functionality into BT HAL framework. Sets the enable privacy functionality of LE Adapter Change-Id: I8f05f7c5e01103ffbd0106f63c49da4d8927d469 Signed-off-by: himanshu --- bt-oal/bluez_hal/src/bt-hal-adapter-le.c | 31 ++++++++++++++++++++++ bt-oal/bluez_hal/src/bt-hal-adapter-le.h | 2 ++ bt-oal/bluez_hal/src/bt-hal-bluetooth.c | 1 + bt-oal/hardware/bluetooth.h | 5 ++++ bt-oal/include/oal-adapter-mgr.h | 14 ++++++++++ bt-oal/oal-adapter-mgr.c | 15 +++++++++++ .../services/adapter/bt-service-core-adapter-le.c | 24 +++++++++++++++++ .../services/bt-request-handler.c | 7 +++++ .../services/include/bt-service-core-adapter-le.h | 2 ++ 9 files changed, 101 insertions(+) diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c index 751afee..7852be2 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c @@ -925,6 +925,37 @@ int _bt_hal_adapter_le_stop_scan(void) return BT_STATUS_SUCCESS; } +/*sets the privacy functionality of the adapter*/ +int _bt_hal_adapter_le_set_privacy(uint8_t set_privacy) +{ + GDBusProxy *proxy; + GError *error = NULL; + GVariant *result = NULL; + proxy = _bt_hal_get_adapter_proxy(); + if (proxy == NULL) + return BT_STATUS_FAIL; + + result = g_dbus_proxy_call_sync(proxy, + "SetLePrivacy", + g_variant_new("(b)", set_privacy), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (!result) { + if (error != NULL) { + ERR("Failed to SetLePrivacy (Error: %s)", error->message); + g_clear_error(&error); + } else + ERR("Failed to SetLePrivacy"); + return BT_STATUS_FAIL; + } + + g_variant_unref(result); + INFO("SetLePrivacy as %d", set_privacy); + return BT_STATUS_SUCCESS; +} int _bt_hal_adapter_le_set_scan_parameters( int scan_type, int scan_interval, int scan_window) diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-le.h b/bt-oal/bluez_hal/src/bt-hal-adapter-le.h index ab51773..b84ca20 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-le.h +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-le.h @@ -82,6 +82,8 @@ void _bt_hal_get_gatt_server_instance_initialized(int *instance); int _bt_hal_le_init(void); void _bt_hal_le_deinit(void); +int _bt_hal_adapter_le_set_privacy(uint8_t set_privacy); + int _bt_hal_adapter_le_set_white_list(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add); #ifdef __cplusplus } diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index 1f8a36d..547a613 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -462,6 +462,7 @@ static const bt_interface_t bluetooth_if = { .set_hal_adapter_request_state = set_hal_adapter_request_state, .set_hal_le_request_state = set_hal_le_request_state, .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list, + .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy, #endif }; diff --git a/bt-oal/hardware/bluetooth.h b/bt-oal/hardware/bluetooth.h index 581581e..1d978ee 100644 --- a/bt-oal/hardware/bluetooth.h +++ b/bt-oal/hardware/bluetooth.h @@ -870,6 +870,11 @@ typedef struct { * adds/removes the remote device address to/from the white list */ int (*adapter_le_set_white_list)(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add); + + /* + * Sets the privacy functionality of the adapter + */ + int (*adapter_le_set_privacy)(uint8_t set_privacy); #endif } bt_interface_t; diff --git a/bt-oal/include/oal-adapter-mgr.h b/bt-oal/include/oal-adapter-mgr.h index 83e0b35..4a4860f 100644 --- a/bt-oal/include/oal-adapter-mgr.h +++ b/bt-oal/include/oal-adapter-mgr.h @@ -460,6 +460,20 @@ oal_status_t is_advertising(void); * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED */ oal_status_t adapter_set_white_list(bt_address_t* device_address, int address_type, bool is_add); + +/** + * @brief Set the privacy functionality of the adapter + * + * @param privacy mode + * + * @details Set the privacy functionality of the adaptor. + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + */ +oal_status_t adapter_ble_set_privacy(int set_privacy); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 4022dc6..6426439 100644 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -759,6 +759,21 @@ oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_ty return ret; } +oal_status_t adapter_ble_set_privacy(int set_privacy) +{ + int res; + + CHECK_OAL_INITIALIZED(); + API_TRACE(); + + res = blued_api->adapter_le_set_privacy(set_privacy); + if (res != BT_STATUS_SUCCESS) + BT_ERR("Setting LE Privacy Failed: [%s]", status2string(res)); + res = convert_to_oal_status(res); + + return res; +} + static void cb_adapter_properties(bt_status_t status, int num_properties, bt_property_t *properties) diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c index 3901536..97583eb 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c @@ -1732,6 +1732,30 @@ gboolean _bt_is_le_coded_phy_supported(void) return FALSE; } +int _bt_set_le_privacy(gboolean set_privacy) +{ + int result = BLUETOOTH_ERROR_NONE; + + if (__bt_is_factory_test_mode()) { + BT_ERR("Unable to set le privacy in factory binary !!"); + return BLUETOOTH_ERROR_NOT_SUPPORT; + } + + if (_bt_adapter_get_status() != BT_ACTIVATED && + _bt_adapter_get_le_status() != BT_LE_ACTIVATED) { + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + } + + result = adapter_ble_set_privacy(set_privacy); + if (result != OAL_STATUS_SUCCESS) { + BT_ERR("adapter_set_le_privacy failed: %d", result); + result = BLUETOOTH_ERROR_INTERNAL; + } + + return result; +} + + int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add) { int result = BLUETOOTH_ERROR_NONE; diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index ad15ee8..3e3fbed 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -840,6 +840,13 @@ int __bt_bluez_request(int function_name, result = _bt_set_authorization(&address, authorize); break; } + case BT_SET_LE_PRIVACY: { + gboolean set_privacy; + __bt_service_get_parameters(in_param1, &set_privacy, + sizeof(gboolean)); + result = _bt_set_le_privacy(set_privacy); + break; + } case BT_ADD_WHITE_LIST: { bluetooth_device_address_t address = { {0} }; int address_type = 0; diff --git a/bt-service-adaptation/services/include/bt-service-core-adapter-le.h b/bt-service-adaptation/services/include/bt-service-core-adapter-le.h index c8bb849..8e76e76 100644 --- a/bt-service-adaptation/services/include/bt-service-core-adapter-le.h +++ b/bt-service-adaptation/services/include/bt-service-core-adapter-le.h @@ -95,6 +95,8 @@ gboolean _bt_is_le_coded_phy_supported(void); int _bt_set_le_static_random_address(gboolean is_enable); +int _bt_set_le_privacy(gboolean set_privacy); + int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add); #ifdef __cplusplus } -- 2.7.4