Skip to contentSkip to conversation

btdev: Fix not removing connection and advertising set on reset

PATCH In review Luiz Augusto von Dentz 3 participants 4 messages May 2, 2022 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 btdev: Fix not removing connection and advertising set on reset

From: Luiz Augusto von Dentz <[email protected]>

This makes sure that all connections and advertising sets are cleanup on reset.

---
 emulator/btdev.c | 76 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 36 deletions(-)
emulator/btdev.c +40 -36
index d3f565438..641e308b3 100644
@@ -509,6 +509,42 @@ void btdev_set_rl_len(struct btdev *btdev, uint8_t len)
 	btdev->le_rl_len = len;
 }
 
+static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2)
+{
+	conn1->link = NULL;
+	conn2->link = NULL;
+}
+
+static void conn_remove(void *data)
+{
+	struct btdev_conn *conn = data;
+
+	if (conn->link) {
+		struct btdev_conn *link = conn->link;
+
+		conn_unlink(conn, conn->link);
+		conn_remove(link);
+	}
+
+	queue_remove(conn->dev->conns, conn);
+
+	free(conn->data);
+	free(conn);
+}
+
+static void le_ext_adv_free(void *data)
+{
+	struct le_ext_adv *ext_adv = data;
+
+	/* Remove to queue */
+	queue_remove(ext_adv->dev->le_ext_adv, ext_adv);
+
+	if (ext_adv->id)
+		timeout_remove(ext_adv->id);
+
+	free(ext_adv);
+}
+
 static void btdev_reset(struct btdev *btdev)
 {
 	/* FIXME: include here clearing of all states that should be
@@ -517,12 +553,16 @@ static void btdev_reset(struct btdev *btdev)
 
 	btdev->le_scan_enable		= 0x00;
 	btdev->le_adv_enable		= 0x00;
+	btdev->le_pa_enable		= 0x00;
 
 	al_clear(btdev);
 	rl_clear(btdev);
 
 	btdev->le_al_len = AL_SIZE;
 	btdev->le_rl_len = RL_SIZE;
+
+	queue_remove_all(btdev->conns, NULL, NULL, conn_remove);
+	queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free);
 }
 
 static int cmd_reset(struct btdev *dev, const void *data, uint8_t len)
@@ -674,29 +714,6 @@ static bool match_handle(const void *data, const void *match_data)
 	return conn->handle == handle;
 }
 
-static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2)
-{
-	conn1->link = NULL;
-	conn2->link = NULL;
-}
-
-static void conn_remove(void *data)
-{
-	struct btdev_conn *conn = data;
-
-	if (conn->link) {
-		struct btdev_conn *link = conn->link;
-
-		conn_unlink(conn, conn->link);
-		conn_remove(link);
-	}
-
-	queue_remove(conn->dev->conns, conn);
-
-	free(conn->data);
-	free(conn);
-}
-
 static void disconnect_complete(struct btdev *dev, uint16_t handle,
 					uint8_t status, uint8_t reason)
 {
@@ -4627,19 +4644,6 @@ static struct le_ext_adv *le_ext_adv_new(struct btdev *btdev, uint8_t handle)
 	return ext_adv;
 }
 
-static void le_ext_adv_free(void *data)
-{
-	struct le_ext_adv *ext_adv = data;
-
-	/* Remove to queue */
-	queue_remove(ext_adv->dev->le_ext_adv, ext_adv);
-
-	if (ext_adv->id)
-		timeout_remove(ext_adv->id);
-
-	free(ext_adv);
-}
-
 static int cmd_set_adv_rand_addr(struct btdev *dev, const void *data,
 							uint8_t len)
 {
Signature · 1 line
2.35.1
author maintainer
#1 lore raw

PATCH 2/2 monitor: Decode LTV fields of Basic Audio Announcements

From: Luiz Augusto von Dentz <[email protected]>

This decodes the LTV fields of Basic Audio Announcements:

< HCI Command: LE Set Periodic Advertising Data (0x08|0x003f) plen 41

        Handle: 0
        Operation: Complete ext advertising data (0x03)
        Data length: 0x26
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 1
            Codec: LC3 (0x06)
            Codec Specific Configuration #0: len 0x02 type 0x01
            Codec Specific Configuration: 03
            Codec Specific Configuration #1: len 0x02 type 0x02
            Codec Specific Configuration: 01
            Codec Specific Configuration #2: len 0x05 type 0x03
            Codec Specific Configuration: 01000000
            Codec Specific Configuration #3: len 0x03 type 0x04
            Codec Specific Configuration: 2800
            Metadata #0: len 0x03 type 0x02
            Metadata: 0200
              BIS #0:
              Index: 1
              Codec Specific Configuration:
---
 monitor/packet.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)
monitor/packet.c +40 -2
index d409e4e63..99ed9c281 100644
@@ -3318,6 +3318,44 @@ static void *iov_pull(struct iovec *iov, size_t len)
 	return data;
 }
 
+static void print_ltv(const char *label, const uint8_t *data, uint8_t len)
+{
+	struct iovec iov;
+	int i;
+
+	iov.iov_base = (void *) data;
+	iov.iov_len = len;
+
+	for (i = 0; iov.iov_len; i++) {
+		uint8_t l, t, *v;
+
+		l = get_u8(iov_pull(&iov, sizeof(l)));
+		if (!l) {
+			print_field("%s #%d: len 0x%02x", label, i, l);
+			break;
+		}
+
+		v = iov_pull(&iov, sizeof(*v));
+		if (!v)
+			break;
+
+		t = get_u8(v);
+
+		print_field("%s #%d: len 0x%02x type 0x%02x", label, i, l, t);
+
+		l -= 1;
+
+		v = iov_pull(&iov, l);
+		if (!v)
+			break;
+
+		print_hex_field(label , v, l);
+	}
+
+	if (iov.iov_len)
+		print_hex_field(label , iov.iov_base, iov.iov_len);
+}
+
 static void print_base_annoucement(const uint8_t *data, uint8_t data_len)
 {
 	struct iovec iov;
@@ -3368,7 +3406,7 @@ static void print_base_annoucement(const uint8_t *data, uint8_t data_len)
 		if (!iov_pull(&iov, codec_cfg->len))
 			goto done;
 
-		print_hex_field("    Codec Specific Configuration",
+		print_ltv("    Codec Specific Configuration",
 					codec_cfg->data, codec_cfg->len);
 
 		metadata = iov_pull(&iov, sizeof(*metadata));
@@ -3378,7 +3416,7 @@ static void print_base_annoucement(const uint8_t *data, uint8_t data_len)
 		if (!iov_pull(&iov, metadata->len))
 			goto done;
 
-		print_hex_field("    Metadata", metadata->data, metadata->len);
+		print_ltv("    Metadata", metadata->data, metadata->len);
 
 		/* Level 3 - BIS(s)*/
 		for (j = 0; j < subgroup->num_bis; j++) {
Signature · 1 line
2.35.1
#2 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=637722

---Test result---

Test Summary:

CheckPatch                    FAIL      2.98 seconds
GitLint                       PASS      1.95 seconds
Prep - Setup ELL              PASS      50.92 seconds
Build - Prep                  PASS      0.76 seconds
Build - Configure             PASS      10.03 seconds
Build - Make                  PASS      1421.90 seconds
Make Check                    PASS      12.93 seconds
Make Check w/Valgrind         PASS      520.30 seconds
Make Distcheck                PASS      272.81 seconds
Build w/ext ELL - Configure   PASS      10.27 seconds
Build w/ext ELL - Make        PASS      1394.51 seconds
Incremental Build with patchesPASS      2867.14 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf Output:
[BlueZ,2/2] monitor: Decode LTV fields of Basic Audio Announcements ERROR:SPACING: space prohibited before that ',' (ctx:WxW) #151: FILE: monitor/packet.c:3352:
+ print_hex_field(label , v, l);
^

ERROR:SPACING: space prohibited before that ',' (ctx:WxW) #155: FILE: monitor/packet.c:3356:
+ print_hex_field(label , iov.iov_base, iov.iov_len);
^

/github/workspace/src/12834736.patch total: 2 errors, 0 warnings, 60 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12834736.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 7 lines · On Mon, 2 May 2022 14:05:52 -0700 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

This makes sure that all connections and advertising sets are cleanup on reset.

---
 emulator/btdev.c | 76 +++++++++++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 36 deletions(-)

Here is the summary with links:
- [BlueZ,1/2] btdev: Fix not removing connection and advertising set on reset

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c75ff36b77f8

- [BlueZ,2/2] monitor: Decode LTV fields of Basic Audio Announcements (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html