2021-07-22 06:03:08

by Ayush Garg

[permalink] [raw]
Subject: [PATCH BlueZ 7/8] device: Save device PHY in storage and read it at init

This change will save the current LE connection PHY in
the storage when LE PHY Updated Event is received.
It will also load and set the last stored LE PHY when
that device is re-connected.

Reviewed-by: Anupam Roy <[email protected]>
---
src/device.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/src/device.c b/src/device.c
index 4b11772b8..b708fc822 100644
--- a/src/device.c
+++ b/src/device.c
@@ -275,6 +275,7 @@ struct btd_device {

uint32_t phys;
bool pending_phys;
+ uint32_t stored_phys;
};

static const uint16_t uuid_list[] = {
@@ -448,6 +449,12 @@ static gboolean store_device_info_cb(gpointer user_data)
g_key_file_remove_key(key_file, "General", "Services", NULL);
}

+ if (device->stored_phys)
+ g_key_file_set_integer(key_file, "General", "Phy",
+ device->stored_phys);
+ else
+ g_key_file_remove_key(key_file, "General", "Phy", NULL);
+
if (device->vendor_src) {
g_key_file_set_integer(key_file, "DeviceID", "Source",
device->vendor_src);
@@ -3576,6 +3583,14 @@ next:
gerr = NULL;
}

+ /* Get PHY */
+ device->stored_phys = g_key_file_get_integer(key_file,
+ "General", "Phy", &gerr);
+ if (gerr) {
+ g_error_free(gerr);
+ gerr = NULL;
+ }
+
if (store_needed)
store_device_info(device);
}
@@ -5578,6 +5593,9 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io)

device_set_phy(dev, phys);

+ if (dev->stored_phys)
+ set_preferred_phy(dev, dev->stored_phys);
+
bt_att_ref(dev->att);

bt_att_set_debug(dev->att, BT_ATT_DEBUG, gatt_debug, NULL, NULL);
@@ -5688,6 +5706,9 @@ void device_le_phy_updated(struct btd_device *dev, uint32_t phy)
{
dev->pending_phys = false;

+ dev->stored_phys = phy;
+ store_device_info(dev);
+
device_set_phy(dev, phy);
}

--
2.17.1