adapter: Check flags are supported
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 15 Aug 2022 22:32:42 +0000 (15:32 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This makes sure the flags are supported before attempting to set it.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/device.c
src/device.h

index 8828985..be8a062 100644 (file)
@@ -10302,10 +10302,12 @@ void adapter_set_device_flags(struct btd_adapter *adapter,
                                mgmt_request_func_t func, void *user_data)
 {
        struct mgmt_cp_set_device_flags cp;
+       uint32_t supported = btd_device_get_supported_flags(device);
        const bdaddr_t *bdaddr;
        uint8_t bdaddr_type;
 
-       if (!btd_has_kernel_features(KERNEL_CONN_CONTROL))
+       if (!btd_has_kernel_features(KERNEL_CONN_CONTROL) ||
+                               (supported | flags) != supported)
                return;
 
        bdaddr = device_get_address(device);
index d0a0dad..ae18ff0 100644 (file)
@@ -10307,6 +10307,11 @@ uint32_t btd_device_get_current_flags(struct btd_device *dev)
        return dev->current_flags;
 }
 
+uint32_t btd_device_get_supported_flags(struct btd_device *dev)
+{
+       return dev->supported_flags;
+}
+
 /* This event is sent immediately after add device on all mgmt sockets.
  * Afterwards, it is only sent to mgmt sockets other than the one which called
  * set_device_flags.
index 5045143..2d28070 100644 (file)
@@ -261,6 +261,7 @@ int device_discover_services(struct btd_device *device);
 int btd_device_connect_services(struct btd_device *dev, GSList *services);
 
 uint32_t btd_device_get_current_flags(struct btd_device *dev);
+uint32_t btd_device_get_supported_flags(struct btd_device *dev);
 void btd_device_flags_changed(struct btd_device *dev, uint32_t supported_flags,
                              uint32_t current_flags);