All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ayush Garg <ayush.garg@samsung.com>
To: linux-bluetooth@vger.kernel.org
Cc: anupam.r@samsung.com, nitin.j@samsung.com
Subject: [PATCH BlueZ 7/8] device: Save device PHY in storage and read it at init
Date: Thu, 22 Jul 2021 11:19:50 +0530	[thread overview]
Message-ID: <20210722054951.8291-8-ayush.garg@samsung.com> (raw)
In-Reply-To: <20210722054951.8291-1-ayush.garg@samsung.com>

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 <anupam.r@samsung.com>
---
 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


  parent reply	other threads:[~2021-07-22  6:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210722055008epcas5p28da6985b690d3bbc564a5957c1b209f4@epcas5p2.samsung.com>
2021-07-22  5:49 ` [PATCH BlueZ 0/8] Support for connection specific LE PHY configuration Ayush Garg
     [not found]   ` <CGME20210722055009epcas5p25e4997aa7e53cb2a6e3780fdb7301785@epcas5p2.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 1/8] doc/device-api: Add Phy property Ayush Garg
2021-07-22 17:33       ` Luiz Augusto von Dentz
     [not found]   ` <CGME20210722055010epcas5p45a16ff704c37d108a9df0d6c0a1942a8@epcas5p4.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 2/8] doc/mgmt-api: Add support for LE PHY Update Complete event Ayush Garg
2021-07-22 14:45       ` Marcel Holtmann
     [not found]   ` <CGME20210722055011epcas5p15299bfe8f8b8dd58e1354364071608e3@epcas5p1.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 3/8] btio: Add BT_IO_PHY option to set le phy options Ayush Garg
     [not found]   ` <CGME20210722055012epcas5p1bb92b3e31233da03906c4f562b22b4fc@epcas5p1.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 4/8] device: Add support for get/set PHY property Ayush Garg
     [not found]   ` <CGME20210722055013epcas5p350d88f402bbe4c55f1f868dbb2decbaf@epcas5p3.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 5/8] adapter: Add support for LE PHY Update Complete event Ayush Garg
     [not found]   ` <CGME20210722055015epcas5p4db389aa15f16f1577a74ba5ce446919b@epcas5p4.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 6/8] client: Add support for LE get/set device PHY in bluetoothctl Ayush Garg
     [not found]   ` <CGME20210722055016epcas5p267b70f0da3b5c1991d29ca47d685ab6d@epcas5p2.samsung.com>
2021-07-22  5:49     ` Ayush Garg [this message]
     [not found]   ` <CGME20210722055017epcas5p4da91b311c34a5fb869148b369338ed07@epcas5p4.samsung.com>
2021-07-22  5:49     ` [PATCH BlueZ 8/8] monitor: Add support for LE PHY Update event Ayush Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210722054951.8291-8-ayush.garg@samsung.com \
    --to=ayush.garg@samsung.com \
    --cc=anupam.r@samsung.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=nitin.j@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.