All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 6/8] Bluetooth: hci: Add hci_conn_set_state
Date: Mon, 18 Aug 2025 16:47:51 -0400	[thread overview]
Message-ID: <20250818204753.1203949-6-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20250818204753.1203949-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds hci_conn_set_state which prints the state transition of
hci_conn and replaces the direct setting of hci_conn->state.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 include/net/bluetooth/hci_core.h | 10 +++++++-
 net/bluetooth/hci_conn.c         | 20 +++++++--------
 net/bluetooth/hci_event.c        | 44 ++++++++++++++++----------------
 net/bluetooth/hci_sync.c         |  6 ++---
 net/bluetooth/iso.c              |  2 +-
 net/bluetooth/sco.c              |  2 +-
 6 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 66523b74f828..2d082c72937f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1704,6 +1704,14 @@ static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
 #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
 #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
 
+#define hci_conn_set_state(c, s) \
+	do { \
+		bt_dev_dbg((c)->hdev, "hcon %p handle 0x%04x state %s -> %s", \
+			   (c), (c)->handle, state_to_string((c)->state), \
+			   state_to_string(s)); \
+		(c)->state = s; \
+	} while (0)
+
 static inline void *hci_get_drvdata(struct hci_dev *hdev)
 {
 	return dev_get_drvdata(&hdev->dev);
@@ -2133,7 +2141,7 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
 
 	if (conn->state == BT_CONFIG) {
 		if (!status)
-			conn->state = BT_CONNECTED;
+			hci_conn_set_state(conn, BT_CONNECTED);
 
 		hci_connect_cfm(conn, status);
 		hci_conn_drop(conn);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 9b23865244b4..0bb7142bcac5 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -204,7 +204,7 @@ static void hci_add_sco(struct hci_conn *conn, __u16 handle)
 
 	bt_dev_dbg(hdev, "hcon %p", conn);
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	conn->out = true;
 
 	conn->attempt++;
@@ -296,7 +296,7 @@ static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
 
 	configure_datapath_sync(hdev, &conn->codec);
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	conn->out = true;
 
 	conn->attempt++;
@@ -413,7 +413,7 @@ static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
 
 	bt_dev_dbg(hdev, "hcon %p", conn);
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	conn->out = true;
 
 	conn->attempt++;
@@ -1311,7 +1311,7 @@ void hci_conn_failed(struct hci_conn *conn, u8 status)
 	test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags);
 	test_and_clear_bit(HCI_CONN_PA_SYNC_FAILED, &conn->flags);
 
-	conn->state = BT_CLOSED;
+	hci_conn_set_state(conn, BT_CLOSED);
 	hci_connect_cfm(conn, status);
 	hci_conn_del(conn);
 }
@@ -1582,7 +1582,7 @@ static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
 	if (IS_ERR(conn))
 		return conn;
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	conn->sid = sid;
 	conn->conn_timeout = timeout;
 
@@ -1633,7 +1633,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
 		return ERR_PTR(-EBUSY);
 	}
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	set_bit(HCI_CONN_SCANNING, &conn->flags);
 	conn->dst_type = dst_type;
 	conn->sec_level = BT_SECURITY_LOW;
@@ -2131,7 +2131,7 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
 	conn->iso_qos = *qos;
 	conn->dst_type = dst_type;
 	conn->sid = sid;
-	conn->state = BT_LISTEN;
+	hci_conn_set_state(conn, BT_LISTEN);
 	conn->conn_timeout = msecs_to_jiffies(qos->bcast.sync_timeout * 10);
 
 	hci_conn_hold(conn);
@@ -2193,7 +2193,7 @@ struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid,
 					      HCI_ROLE_MASTER);
 	if (conn) {
 		memcpy(qos, &conn->iso_qos, sizeof(*qos));
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		return conn;
 	}
 
@@ -2221,7 +2221,7 @@ struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid,
 			  hdev->le_tx_def_phys);
 
 	conn->iso_qos = *qos;
-	conn->state = BT_BOUND;
+	hci_conn_set_state(conn, BT_BOUND);
 
 	/* Link BISes together */
 	parent = hci_conn_hash_lookup_big(hdev,
@@ -2602,7 +2602,7 @@ void hci_conn_hash_flush(struct hci_dev *hdev)
 	while ((conn = list_first_entry_or_null(head,
 						struct hci_conn,
 						list)) != NULL) {
-		conn->state = BT_CLOSED;
+		hci_conn_set_state(conn, BT_CLOSED);
 		hci_disconn_cfm(conn, HCI_ERROR_LOCAL_HOST_TERM);
 		hci_conn_del(conn);
 	}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6e0c095ef244..c2b3069525c0 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2256,7 +2256,7 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
 
 	if (status) {
 		if (conn && conn->state == BT_CONNECT) {
-			conn->state = BT_CLOSED;
+			hci_conn_set_state(conn, BT_CLOSED);
 			hci_connect_cfm(conn, status);
 			hci_conn_del(conn);
 		}
@@ -2299,7 +2299,7 @@ static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
 		link = list_first_entry_or_null(&acl->link_list,
 						struct hci_link, list);
 		if (link && link->conn) {
-			link->conn->state = BT_CLOSED;
+			hci_conn_set_state(link->conn, BT_CLOSED);
 
 			hci_connect_cfm(link->conn, status);
 			hci_conn_del(link->conn);
@@ -2582,7 +2582,7 @@ static void hci_setup_sync_conn_status(struct hci_dev *hdev, __u16 handle,
 		link = list_first_entry_or_null(&acl->link_list,
 						struct hci_link, list);
 		if (link && link->conn) {
-			link->conn->state = BT_CLOSED;
+			hci_conn_set_state(link->conn, BT_CLOSED);
 
 			hci_connect_cfm(link->conn, status);
 			hci_conn_del(link->conn);
@@ -3138,7 +3138,7 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
 			goto done;
 
 		if (conn->type == ACL_LINK) {
-			conn->state = BT_CONFIG;
+			hci_conn_set_state(conn, BT_CONFIG);
 			hci_conn_hold(conn);
 
 			if (!conn->out && !hci_conn_ssp_enabled(conn) &&
@@ -3147,7 +3147,7 @@ static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
 			else
 				conn->disc_timeout = HCI_DISCONN_TIMEOUT;
 		} else
-			conn->state = BT_CONNECTED;
+			hci_conn_set_state(conn, BT_CONNECTED);
 
 		hci_debugfs_create_conn(conn);
 		hci_conn_add_sysfs(conn);
@@ -3294,7 +3294,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
 	if (ev->link_type == ACL_LINK ||
 	    (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) {
 		struct hci_cp_accept_conn_req cp;
-		conn->state = BT_CONNECT;
+		hci_conn_set_state(conn, BT_CONNECT);
 
 		bacpy(&cp.bdaddr, &ev->bdaddr);
 
@@ -3306,7 +3306,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
 		hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
 	} else if (!(flags & HCI_PROTO_DEFER)) {
 		struct hci_cp_accept_sync_conn_req cp;
-		conn->state = BT_CONNECT;
+		hci_conn_set_state(conn, BT_CONNECT);
 
 		bacpy(&cp.bdaddr, &ev->bdaddr);
 		cp.pkt_type = cpu_to_le16(conn->pkt_type);
@@ -3320,7 +3320,7 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
 		hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp),
 			     &cp);
 	} else {
-		conn->state = BT_CONNECT2;
+		hci_conn_set_state(conn, BT_CONNECT2);
 		hci_connect_cfm(conn, 0);
 	}
 
@@ -3368,7 +3368,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
 		goto unlock;
 	}
 
-	conn->state = BT_CLOSED;
+	hci_conn_set_state(conn, BT_CLOSED);
 
 	mgmt_connected = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags);
 
@@ -3472,7 +3472,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, void *data,
 			hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
 				     &cp);
 		} else {
-			conn->state = BT_CONNECTED;
+			hci_conn_set_state(conn, BT_CONNECTED);
 			hci_connect_cfm(conn, ev->status);
 			hci_conn_drop(conn);
 		}
@@ -3708,7 +3708,7 @@ static void hci_remote_features_evt(struct hci_dev *hdev, void *data,
 	}
 
 	if (!hci_outgoing_auth_needed(hdev, conn)) {
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		hci_connect_cfm(conn, ev->status);
 		hci_conn_drop(conn);
 	}
@@ -4249,7 +4249,7 @@ static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status)
 			if (test_and_clear_bit(HCI_CONN_CREATE_CIS,
 					       &conn->flags))
 				pending = true;
-			conn->state = BT_CLOSED;
+			hci_conn_set_state(conn, BT_CLOSED);
 			hci_connect_cfm(conn, status);
 			hci_conn_del(conn);
 		}
@@ -4879,7 +4879,7 @@ static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data,
 	}
 
 	if (!hci_outgoing_auth_needed(hdev, conn)) {
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		hci_connect_cfm(conn, ev->status);
 		hci_conn_drop(conn);
 	}
@@ -4946,7 +4946,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,
 	case 0x00:
 		status = hci_conn_set_handle(conn, __le16_to_cpu(ev->handle));
 		if (status) {
-			conn->state = BT_CLOSED;
+			hci_conn_set_state(conn, BT_CLOSED);
 			break;
 		}
 
@@ -4974,7 +4974,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,
 		fallthrough;
 
 	default:
-		conn->state = BT_CLOSED;
+		hci_conn_set_state(conn, BT_CLOSED);
 		break;
 	}
 
@@ -5107,7 +5107,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
 
 	if (conn->state == BT_CONFIG) {
 		if (!ev->status)
-			conn->state = BT_CONNECTED;
+			hci_conn_set_state(conn, BT_CONNECTED);
 
 		hci_connect_cfm(conn, ev->status);
 		hci_conn_drop(conn);
@@ -5706,7 +5706,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
 	mgmt_device_connected(hdev, conn, NULL, 0);
 
 	conn->sec_level = BT_SECURITY_LOW;
-	conn->state = BT_CONFIG;
+	hci_conn_set_state(conn, BT_CONFIG);
 
 	/* Store current advertising instance as connection advertising instance
 	 * when software rotation is in use so it can be re-enabled when
@@ -5742,7 +5742,7 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
 
 		hci_conn_hold(conn);
 	} else {
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		hci_connect_cfm(conn, status);
 	}
 
@@ -6475,7 +6475,7 @@ static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,
 			else
 				status = ev->status;
 
-			conn->state = BT_CONNECTED;
+			hci_conn_set_state(conn, BT_CONNECTED);
 			hci_connect_cfm(conn, status);
 			hci_conn_drop(conn);
 		}
@@ -6759,14 +6759,14 @@ static void hci_le_cis_established_evt(struct hci_dev *hdev, void *data,
 	}
 
 	if (!ev->status) {
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		hci_debugfs_create_conn(conn);
 		hci_conn_add_sysfs(conn);
 		hci_iso_setup_path(conn);
 		goto unlock;
 	}
 
-	conn->state = BT_CLOSED;
+	hci_conn_set_state(conn, BT_CLOSED);
 	hci_connect_cfm(conn, ev->status);
 	hci_conn_del(conn);
 
@@ -6884,7 +6884,7 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
 					__le16_to_cpu(ev->bis_handle[i++])))
 			continue;
 
-		conn->state = BT_CONNECTED;
+		hci_conn_set_state(conn, BT_CONNECTED);
 		set_bit(HCI_CONN_BIG_CREATED, &conn->flags);
 		hci_debugfs_create_conn(conn);
 		hci_conn_add_sysfs(conn);
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 46c20476dae5..5faee247920e 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5682,7 +5682,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)
 	 * safely.
 	 */
 	if (disconnect) {
-		conn->state = BT_CLOSED;
+		hci_conn_set_state(conn, BT_CLOSED);
 		hci_disconn_cfm(conn, reason);
 		hci_conn_del(conn);
 	} else {
@@ -6518,7 +6518,7 @@ static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data)
 	bt_dev_dbg(hdev, "conn %p", conn);
 
 	clear_bit(HCI_CONN_SCANNING, &conn->flags);
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 
 	/* If requested to connect as peripheral use directed advertising */
 	if (conn->role == HCI_ROLE_SLAVE) {
@@ -6858,7 +6858,7 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
 			bt_dev_warn(hdev, "Failed to cancel inquiry %d", err);
 	}
 
-	conn->state = BT_CONNECT;
+	hci_conn_set_state(conn, BT_CONNECT);
 	conn->out = true;
 	conn->role = HCI_ROLE_MASTER;
 
diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c
index 5c68c0ea7d97..8d2127c15b2d 100644
--- a/net/bluetooth/iso.c
+++ b/net/bluetooth/iso.c
@@ -1462,7 +1462,7 @@ static void iso_conn_defer_accept(struct hci_conn *conn)
 
 	BT_DBG("conn %p", conn);
 
-	conn->state = BT_CONFIG;
+	hci_conn_set_state(conn, BT_CONFIG);
 
 	cp.handle = cpu_to_le16(conn->handle);
 
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index d382d980fd9a..dc079d1b03f2 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -830,7 +830,7 @@ static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
 
 	BT_DBG("conn %p", conn);
 
-	conn->state = BT_CONFIG;
+	hci_conn_set_state(conn, BT_CONFIG);
 
 	if (!lmp_esco_capable(hdev)) {
 		struct hci_cp_accept_conn_req cp;
-- 
2.50.1


  parent reply	other threads:[~2025-08-18 20:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 20:47 [PATCH v2 1/8] Bluetooth: hci_core: Convert instances of BT_DBG to bt_dev_dbg Luiz Augusto von Dentz
2025-08-18 20:47 ` [PATCH v2 2/8] Bluetooth: hci_conn: " Luiz Augusto von Dentz
2025-08-18 20:57   ` Paul Menzel
2025-08-18 20:47 ` [PATCH v2 3/8] Bluetooth: hci_event: " Luiz Augusto von Dentz
2025-08-18 20:47 ` [PATCH v2 4/8] Bluetooth: hci_sock: " Luiz Augusto von Dentz
2025-08-18 20:47 ` [PATCH v2 5/8] Bluetooth: hci_sync: " Luiz Augusto von Dentz
2025-08-18 20:47 ` Luiz Augusto von Dentz [this message]
2025-08-18 20:47 ` [PATCH v2 7/8] Bluetooth: hci_conn: Add bt_conn_dbg Luiz Augusto von Dentz
2025-08-18 20:47 ` [PATCH v2 8/8] Bluetooth: Add function and line information to bt_dbg Luiz Augusto von Dentz
2025-08-18 20:56 ` [PATCH v2 1/8] Bluetooth: hci_core: Convert instances of BT_DBG to bt_dev_dbg Paul Menzel
2025-08-18 21:34 ` [v2,1/8] " bluez.test.bot
2025-08-27 19:10 ` [PATCH v2 1/8] " patchwork-bot+bluetooth

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=20250818204753.1203949-6-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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.