Port the Set LE Privacy functionality into BT HAL framework. 13/215113/2 accepted/tizen/unified/20191007.234828 submit/tizen/20191007.001051
authorhimanshu <h.himanshu@samsung.com>
Thu, 3 Oct 2019 07:39:14 +0000 (13:09 +0530)
committerhimanshu <h.himanshu@samsung.com>
Thu, 3 Oct 2019 08:34:14 +0000 (14:04 +0530)
Sets the enable privacy functionality of LE Adapter

Change-Id: I8f05f7c5e01103ffbd0106f63c49da4d8927d469
Signed-off-by: himanshu <h.himanshu@samsung.com>
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-bluetooth.c
bt-oal/hardware/bluetooth.h
bt-oal/include/oal-adapter-mgr.h
bt-oal/oal-adapter-mgr.c
bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/include/bt-service-core-adapter-le.h

index 751afee..7852be2 100644 (file)
@@ -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)
index ab51773..b84ca20 100644 (file)
@@ -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
 }
index 1f8a36d..547a613 100644 (file)
@@ -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
 };
 
index 581581e..1d978ee 100644 (file)
@@ -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;
 
index 83e0b35..4a4860f 100644 (file)
@@ -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 */
index 4022dc6..6426439 100644 (file)
@@ -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)
index 3901536..97583eb 100644 (file)
@@ -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;
index ad15ee8..3e3fbed 100644 (file)
@@ -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;
index c8bb849..8e76e76 100644 (file)
@@ -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
 }