linux-bluetooth.vger.kernel.org archive mirror
 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 5/8] adapter: Add support for LE PHY Update Complete event
Date: Thu, 22 Jul 2021 11:19:48 +0530	[thread overview]
Message-ID: <20210722054951.8291-6-ayush.garg@samsung.com> (raw)
In-Reply-To: <20210722054951.8291-1-ayush.garg@samsung.com>

This change will subscribe the MGMT LE PHY Update
Complete event.
This event will come whenever the particular PHYs changed
either autonomously or as a response of set PHY property.
Upon receiving the event, it will notify the user by emitting
"Phy" property changed event.

Reviewed-by: Anupam Roy <anupam.r@samsung.com>
---
 lib/mgmt.h    |  8 ++++++++
 src/adapter.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/device.c  |  7 +++++++
 src/device.h  |  2 ++
 4 files changed, 57 insertions(+)

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 0a6349321..4d2acb778 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -1014,6 +1014,13 @@ struct mgmt_ev_controller_resume {
 	uint8_t wake_reason;
 } __packed;
 
+#define MGMT_EV_LE_PHY_UPDATE_COMPLETE	0x002f
+struct mgmt_ev_le_phy_update_complete {
+	struct mgmt_addr_info addr;
+	uint8_t status;
+	uint32_t phys;
+} __packed;
+
 static const char *mgmt_op[] = {
 	"<0x0000>",
 	"Read Version",
@@ -1152,6 +1159,7 @@ static const char *mgmt_ev[] = {
 	"Advertisement Monitor Removed",
 	"Controller Suspend",
 	"Controller Resume",
+	"LE PHY Update Complete",				/* 0x002f */
 };
 
 static const char *mgmt_status[] = {
diff --git a/src/adapter.c b/src/adapter.c
index 5de92a570..f616879fd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -9740,6 +9740,41 @@ static void phy_configuration_changed_callback(uint16_t index,
 					ADAPTER_INTERFACE, "PhyConfiguration");
 }
 
+static void le_phy_update_complete_callback(uint16_t index,
+					uint16_t length, const void *param,
+					void *user_data)
+{
+	const struct mgmt_ev_le_phy_update_complete *ev = param;
+	struct btd_adapter *adapter = user_data;
+	struct btd_device *device;
+	char addr[18];
+
+	if (length < sizeof(*ev)) {
+		btd_error(adapter->dev_id, "Too small le phy update complete event");
+		return;
+	}
+
+	if (ev->status != MGMT_STATUS_SUCCESS) {
+		btd_error(adapter->dev_id, "Failed to set le phy: %s (0x%02x)",
+						mgmt_errstr(ev->status), ev->status);
+		return;
+	}
+
+	ba2str(&ev->addr.bdaddr, addr);
+
+	DBG("hci%u device %s PHYs updated %u", index, addr, ev->phys);
+
+	device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+								ev->addr.type);
+	if (!device) {
+		btd_error(adapter->dev_id,
+				"Unable to get device object for %s", addr);
+		return;
+	}
+
+	device_le_phy_updated(device, ev->phys);
+}
+
 static void read_info_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -9980,6 +10015,11 @@ static void read_info_complete(uint8_t status, uint16_t length,
 						phy_configuration_changed_callback,
 						adapter, NULL);
 
+	mgmt_register(adapter->mgmt, MGMT_EV_LE_PHY_UPDATE_COMPLETE,
+						adapter->dev_id,
+						le_phy_update_complete_callback,
+						adapter, NULL);
+
 	set_dev_class(adapter);
 
 	set_name(adapter, btd_adapter_get_name(adapter));
diff --git a/src/device.c b/src/device.c
index 6f74989c7..4b11772b8 100644
--- a/src/device.c
+++ b/src/device.c
@@ -5684,6 +5684,13 @@ done:
 	}
 }
 
+void device_le_phy_updated(struct btd_device *dev, uint32_t phy)
+{
+	dev->pending_phys = false;
+
+	device_set_phy(dev, phy);
+}
+
 int device_connect_le(struct btd_device *dev)
 {
 	struct btd_adapter *adapter = dev->adapter;
diff --git a/src/device.h b/src/device.h
index 4ae9abe0d..b3b32b231 100644
--- a/src/device.h
+++ b/src/device.h
@@ -154,6 +154,8 @@ int device_unblock(struct btd_device *device, gboolean silent,
 void btd_device_set_pnpid(struct btd_device *device, uint16_t source,
 			uint16_t vendor, uint16_t product, uint16_t version);
 
+void device_le_phy_updated(struct btd_device *dev, uint32_t phy);
+
 int device_connect_le(struct btd_device *dev);
 
 typedef void (*device_svc_cb_t) (struct btd_device *dev, int err,
-- 
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     ` Ayush Garg [this message]
     [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     ` [PATCH BlueZ 7/8] device: Save device PHY in storage and read it at init Ayush Garg
     [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-6-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 \
    --subject='Re: [PATCH BlueZ 5/8] adapter: Add support for LE PHY Update Complete event' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).