adapter: Fix toggling of experimental features
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 24 Jun 2021 22:01:50 +0000 (15:01 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:35 +0000 (19:08 +0530)
When toggling experimental features it may cause the old value to still
be in effect since it was read after read info which upon completion
would attempt to call adapter_register without first updating the
experimental features which could affect the likes of advertising
instances when LL Privacy is enabled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c

index 6d2c755..3677f7a 100644 (file)
@@ -15524,14 +15524,15 @@ static void set_exp_debug_complete(uint8_t status, uint16_t len,
 static void exp_debug_func(struct btd_adapter *adapter, uint32_t flags)
 {
        struct mgmt_cp_set_exp_feature cp;
+       uint8_t action = btd_opts.experimental ? 0x01 : 0x00;
 
-       /* If already enabled don't attempt to set it again */
-       if (flags & BIT(0))
+       /* If already set don't attempt to set it again */
+       if (action == (flags & BIT(0)))
                return;
 
        memset(&cp, 0, sizeof(cp));
        memcpy(cp.uuid, debug_uuid, 16);
-       cp.action = 0x01;
+       cp.action = btd_opts.experimental ? 0x01 : 0x00;
 
        if (mgmt_send(adapter->mgmt, MGMT_OP_SET_EXP_FEATURE,
                        adapter->dev_id, sizeof(cp), &cp,
@@ -15560,14 +15561,15 @@ static void set_rpa_resolution_complete(uint8_t status, uint16_t len,
 static void rpa_resolution_func(struct btd_adapter *adapter, uint32_t flags)
 {
        struct mgmt_cp_set_exp_feature cp;
+       uint8_t action = btd_opts.experimental ? 0x01 : 0x00;
 
-       /* If already enabled don't attempt to set it again */
-       if (flags & BIT(0))
+       /* If already set don't attempt to set it again */
+       if (action == (flags & BIT(0)))
                return;
 
        memset(&cp, 0, sizeof(cp));
        memcpy(cp.uuid, rpa_resolution_uuid, 16);
-       cp.action = 0x01;
+       cp.action = action;
 
        if (mgmt_send(adapter->mgmt, MGMT_OP_SET_EXP_FEATURE,
                        adapter->dev_id, sizeof(cp), &cp,
@@ -15782,10 +15784,6 @@ static void read_info_complete(uint8_t status, uint16_t length,
                adapter->central_rpa_res_support = 0x01;
 #endif
 
-       if (btd_opts.experimental &&
-                       btd_has_kernel_features(KERNEL_EXP_FEATURES))
-               read_exp_features(adapter);
-
        err = adapter_register(adapter);
        if (err < 0) {
                btd_error(adapter->dev_id, "Unable to register new adapter");
@@ -16090,6 +16088,9 @@ static void index_added(uint16_t index, uint16_t length, const void *param,
                return;
        }
 
+       if (btd_has_kernel_features(KERNEL_EXP_FEATURES))
+               read_exp_features(adapter);
+
        /*
         * Protect against potential two executions of read controller info.
         *