public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Uhr <uhrmar@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Markus Uhr <uhrmar@gmail.com>
Subject: [PATCH v2] Add pattern matching for service UUIDs
Date: Sun, 25 Aug 2024 22:58:17 +0200	[thread overview]
Message-ID: <20240825205817.70066-1-uhrmar@gmail.com> (raw)

This commit extends the pattern matching capabilities of advertisement
monitors with matching for service UUIDs. This functionality was lost
with bc2ab4b (see #652) and not added with b0656c2.
---
 src/shared/ad.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/shared/ad.c b/src/shared/ad.c
index d08ce7af9..53c4628b6 100644
--- a/src/shared/ad.c
+++ b/src/shared/ad.c
@@ -1362,6 +1362,46 @@ static bool match_manufacturer(const void *data, const void *user_data)
 	return false;
 }
 
+static bool match_uuid(const void *data, const void *user_data)
+{
+	const bt_uuid_t *uuid = data;
+	const struct pattern_match_info *info = user_data;
+	const struct bt_ad_pattern *pattern;
+
+	if (!uuid || !info)
+		return false;
+
+	if (info->matched_pattern)
+		return false;
+
+	pattern = info->current_pattern;
+
+	if (!pattern)
+		return false;
+
+	switch (pattern->type) {
+	case BT_AD_UUID16_ALL:
+	case BT_AD_UUID16_SOME:
+		if (pattern->offset != 0 || pattern->len != sizeof(uint16_t))
+			return false;
+		break;
+	case BT_AD_UUID32_ALL:
+	case BT_AD_UUID32_SOME:
+		if (pattern->offset != 0 || pattern->len != sizeof(uint32_t))
+			return false;
+		break;
+	case BT_AD_UUID128_ALL:
+	case BT_AD_UUID128_SOME:
+		if (pattern->offset != 0 || pattern->len != sizeof(uint128_t))
+			return false;
+		break;
+	default:
+		return false;
+	}
+
+	return !memcmp(&uuid->value, pattern->data, pattern->len);
+}
+
 static bool match_service(const void *data, const void *user_data)
 {
 	const struct bt_ad_service_data *service_data = data;
@@ -1451,6 +1491,14 @@ static void pattern_match(void *data, void *user_data)
 		matched = queue_find(ad->manufacturer_data, match_manufacturer,
 				user_data);
 		break;
+	case BT_AD_UUID16_ALL:
+	case BT_AD_UUID16_SOME:
+	case BT_AD_UUID32_ALL:
+	case BT_AD_UUID32_SOME:
+	case BT_AD_UUID128_ALL:
+	case BT_AD_UUID128_SOME:
+		matched = queue_find(ad->service_uuids, match_uuid, user_data);
+		break;
 	case BT_AD_SERVICE_DATA16:
 	case BT_AD_SERVICE_DATA32:
 	case BT_AD_SERVICE_DATA128:
-- 
2.46.0


             reply	other threads:[~2024-08-25 20:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-25 20:58 Markus Uhr [this message]
2024-08-25 22:42 ` [v2] Add pattern matching for service UUIDs bluez.test.bot
2024-11-09  9:35 ` [PATCH v2] " Markus Uhr

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=20240825205817.70066-1-uhrmar@gmail.com \
    --to=uhrmar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox