Add and remove device from whitelist 73/214373/4
authorhimanshu <h.himanshu@samsung.com>
Fri, 20 Sep 2019 15:52:35 +0000 (21:22 +0530)
committerhimanshu <h.himanshu@samsung.com>
Fri, 27 Sep 2019 13:41:58 +0000 (19:11 +0530)
Change-Id: I476224d047e4e5a2b7ddb7b79d209bb6a5baba00
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 152bca5..3acf1cf 100644 (file)
@@ -965,3 +965,49 @@ void _bt_hal_unregister_gatt_le_dbus_handler_cb(void)
 {
        gatt_le_event_cb = NULL;
 }
+
+/*add/remove remote device address from white list*/
+int _bt_hal_adapter_le_set_white_list(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add)
+{
+       GDBusProxy *proxy;
+       char address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+       GError *error = NULL;
+       GVariant *ret;
+
+       if (address_type != BLUETOOTH_HAL_DEVICE_PUBLIC_ADDRESS &&
+               address_type != BLUETOOTH_HAL_DEVICE_RANDOM_ADDRESS)
+               return BT_STATUS_PARM_INVALID;
+
+       _bt_hal_convert_addr_type_to_string(address, device_address->address);
+
+       proxy = _bt_hal_get_adapter_proxy();
+       if (proxy == NULL)
+               return BT_STATUS_FAIL;
+       if (is_add)
+               ret = g_dbus_proxy_call_sync(proxy, "AddDeviceWhiteList",
+                               g_variant_new("(su)", address, address_type),
+                               G_DBUS_CALL_FLAGS_NONE, -1,
+                               NULL, &error);
+       else
+               ret = g_dbus_proxy_call_sync(proxy, "RemoveDeviceWhiteList",
+                               g_variant_new("(su)", address, address_type),
+                               G_DBUS_CALL_FLAGS_NONE, -1,
+                               NULL, &error);
+
+       if (error) {
+               if (is_add)
+                       ERR("RemoveDeviceWhiteList Fail: %s", error->message);
+               else
+                       ERR("AddDeviceWhiteList Fail: %s", error->message);
+               g_clear_error(&error);
+               return BT_STATUS_FAIL;
+       }
+
+       if (ret)
+               g_variant_unref(ret);
+       if (is_add)
+               INFO("Device Added to white list");
+       else
+               INFO("Device Removed from white list");
+       return BT_STATUS_SUCCESS;
+}
index d20e475..ab51773 100644 (file)
@@ -81,6 +81,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_white_list(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 513b550..1f8a36d 100644 (file)
@@ -461,6 +461,7 @@ static const bt_interface_t bluetooth_if = {
        .set_le_static_random_address = _bt_hal_set_le_static_random_address,
        .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,
 #endif
 };
 
index 603c61e..581581e 100644 (file)
@@ -440,6 +440,14 @@ typedef enum {
        BT_DISC_ROLE_DUAL
 } bt_disc_role_type_t;
 
+/**
+* This is Bluetooth device address type
+*/
+typedef enum {
+        BLUETOOTH_HAL_DEVICE_PUBLIC_ADDRESS = 0x00,
+       BLUETOOTH_HAL_DEVICE_RANDOM_ADDRESS
+} bt_dev_addr_type_t;
+
 /** Bluetooth Trusted Profiles */
 typedef enum {
        BT_TRUSTED_PROFILE_PBAP = 1,
@@ -858,6 +866,10 @@ typedef struct {
        */
         int (*set_hal_le_request_state)(int enable);
 
+       /*
+        * 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);
 #endif
 } bt_interface_t;
 
index 23b98c4..83e0b35 100644 (file)
@@ -444,6 +444,22 @@ oal_status_t adapter_set_le_static_random_address(int enable);
  * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
  */
 oal_status_t is_advertising(void);
+
+/**
+ * @brief Add/removes device to/from whitelist
+ *
+ * @param remote device address
+ * @param remote device address type
+ * @param whether to add/remove from white list
+ *
+ * @details adds/removes device to/from controller's white list.
+ *
+ * @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_set_white_list(bt_address_t* device_address, int address_type, bool is_add);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index e3f2d7d..4022dc6 100644 (file)
@@ -738,6 +738,27 @@ oal_status_t adapter_set_le_static_random_address(int enable)
        return ret;
 }
 
+oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_type, bool is_add)
+{
+       int ret;
+       bdstr_t bdstr;
+
+       CHECK_OAL_INITIALIZED();
+       API_TRACE();
+
+       BT_INFO("BT remote device Address: %s", bdt_bd2str(device_address, &bdstr));
+
+       ret = blued_api->adapter_le_set_white_list((bt_bdaddr_t*)device_address, address_type, is_add);
+       if (ret != BT_STATUS_SUCCESS) {
+               if(is_add)
+                       BT_ERR("Add to White List Failed: [%s]",status2string(ret));
+               else
+                       BT_ERR("Remove from White List Failed: [%s]",status2string(ret));
+       }
+       ret = convert_to_oal_status(ret);
+       return ret;
+}
+
 static void cb_adapter_properties(bt_status_t status,
                int num_properties,
                bt_property_t *properties)
index 1e638a3..3901536 100644 (file)
@@ -1732,6 +1732,35 @@ gboolean _bt_is_le_coded_phy_supported(void)
                return FALSE;
 }
 
+int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       if (__bt_is_factory_test_mode()) {
+               if(is_add)
+                       BT_ERR("Unable to add to white list in factory binary !!");
+               else
+                       BT_ERR("Unable to remove white list in factory binary !!");
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       BT_CHECK_PARAMETER(device_address, return);
+
+       if(_bt_adapter_get_status() != BT_ACTIVATED ){
+               BT_ERR("Bluetooth adapter is disabled");
+               return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+       }
+
+       result = adapter_set_white_list((bt_address_t*)device_address, address_type, is_add);
+       if (result != OAL_STATUS_SUCCESS) {
+               if(is_add)
+                       BT_ERR("Add to White List Failed %d", result);
+               else
+                       BT_ERR("Remove from white list Failed %d", result);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       return result;
+}
 
 /*************************************** LE Scan APIs *********************************************/
 
@@ -1760,4 +1789,3 @@ int _bt_set_le_static_random_address(gboolean is_enable)
 
        return result;
 }
-
index dd6a6eb..ad15ee8 100644 (file)
@@ -840,6 +840,28 @@ int __bt_bluez_request(int function_name,
                result = _bt_set_authorization(&address, authorize);
                break;
        }
+       case BT_ADD_WHITE_LIST: {
+               bluetooth_device_address_t address = { {0} };
+               int address_type = 0;
+               bool is_add = true;
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &address_type, sizeof(int));
+               result = _bt_set_white_list(&address, address_type, is_add);
+               break;
+       }
+       case BT_REMOVE_WHITE_LIST: {
+               bluetooth_device_address_t address = { {0} };
+               int address_type = 0;
+               bool is_add = false;
+               __bt_service_get_parameters(in_param1,
+                               &address, sizeof(bluetooth_device_address_t));
+               __bt_service_get_parameters(in_param2,
+                               &address_type, sizeof(int));
+               result = _bt_set_white_list(&address, address_type, is_add);
+               break;
+        }
        case BT_IS_DEVICE_CONNECTED: {
                bluetooth_device_address_t address = { {0} };
                gboolean connected = FALSE;
index 0bfa5d0..c8bb849 100644 (file)
@@ -95,6 +95,7 @@ gboolean _bt_is_le_coded_phy_supported(void);
 
 int _bt_set_le_static_random_address(gboolean is_enable);
 
+int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */