Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154815; b=fZEDlcy8tzfbOgrCOd+bz/lMsSOmakx8p6rUf8idYuzI5XDCQcvfgJQWAhvGJ/jT3zAz H+SyNMpbloIP+fByyyaJzKecTa76I6ky8a2Iu1iloRe3EvpbKXJBjJE4NPvsgny6zJ0Bi HM7uaRSu2MbzvqV4Pi4fO+1Nlx45025yEcsolYMGLGVQradDoLO5xBBxchIFBYmZ5evQ2 ogcPArrQYAi+bCUrODrcYdrY3aTaaKqFg36PRGB22Rq+2zDPR7BO5llgo910nDZBIpVxL DBRCtGiqq3rcEipVM1/JTrQT9GGCMDDAC9s81Tg5PQe5lMiyOrvEkaHxvqkPv0LxrPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154815; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=EMGwQtsrKi0MrEeOnqZQ1ko/72+qQ5JkjfBgplky/CY=; b=V3djF9s0x55dfokhvsEzuD6gjC8ROys1FaUPCqTtr86Mo0PqWNBQivgynY/GMj/CR7em OfJBeHlFsIgBon9fcN4al013MlRu187p+Tw/JOjCRRHX+9Eo95e6790OhCukXzn7mZUQT S9i1T731U9sy/lE2ISrfiN4RB2WqyFlsvZ2juTokBUv9Fzi+ilesr3FlnQTS+ori8xze3 u1QMy97IYB4/EyswW2JHtzI2glpRnyzlXU2h6PZnrze9imU8eyK2m57BvDgln9/4InswS S2/y37JgUAAXiHKzVK+EUXZSuU4Az3SeQaJo/CLVbdNZ3wYYzXMNl8Deagzyhb9wrDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=streamunlimited.com; spf=pass smtp.mailfrom=streamunlimited.com; dkim=pass header.d=streamunlimited.com header.i=@streamunlimited.com header.a=rsa-sha256 header.s=google header.b=HZBbJZ6e; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1D4E606A320 for ; Tue, 1 Dec 2026 19:53:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A1D4E606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=streamunlimited.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=streamunlimited.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=streamunlimited.com header.i=@streamunlimited.com header.a=rsa-sha256 header.s=google header.b=HZBbJZ6e Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so125971775e9.2 for ; Tue, 01 Dec 2026 11:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1796154813; x=1796759613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EMGwQtsrKi0MrEeOnqZQ1ko/72+qQ5JkjfBgplky/CY=; b=HZBbJZ6eg3Kjugpjjcwl0WkwRn2iwOA8fQbVth2dYgHWYAo3tF4QHk8wyXelkRJAxq GXC0ch79DBcGRR+AoUp8hHbqK1uK7Of36OPCDhwl5sk6r5Sw0flMvtmcRUowCq5KWDQK 4uSWrJhJenZJCcV0ARni8YbaVtjH1TzCsHpKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796154813; x=1796759613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=EMGwQtsrKi0MrEeOnqZQ1ko/72+qQ5JkjfBgplky/CY=; b=e6vFJAexxeXokZZeuYun5Ni/ofmkewW84X5d8fnAqu/lBGINaX/LUE490hRoXh5rK1 HkxDKZyc6L0rPvwzT4PYwIxrQU0l6UtQBvkHCKDzp2zOPocmrIIc/t5W8El131UHpGA9 Cb7lXJYW9SD/DEGARO/yHxdaywHstpICIugCESc9mneTr04HooyinCI0Nk0WsLjinkTB soGmHJX5eHuePnIXxNfTAdhrOOQqiXiI3/bdoCaQRJlKz3vuTmI3HaC18xf2K/3NDWgw I52oeb+ZaIk+bJRt9ATVFWzzqKMTKt99Y/I+ktP+rgoxnj8jPJxx2iHb7cD+bD6jviEV VyTw== X-Gm-Message-State: APuU4Z8GDP3YesiljWbBTIK4R6AMrVXgJ5MCg8WziAH0fBKyfSjC+P9J H0J2opsCj212G11gcVPw7VKHqnrRU4cUDXrkk5kd64wxSMu9tKZ6hW6wM7P2LSzfr1dqYRmjB93 xlnJ/ X-Gm-Gg: AZFdTZejACLAxLJ+GzvgsnKlhssx3p0XnCWzd96nceXZT3HHf0ouwVyJ5N1yAL1MCpH jBIOStTBtG26X54bL+EGYiIXvELnkVe9acXiG6DnVxYRj0pjMlZR00CMqED1pjcgwU/0DYTSHX3 0PV0zsU7VT5v/LTnbRrN8iR+ZYmLGmtsz1tUewUg9n7tNhObv1zWk2a5pr0wxhfNroqxvutKiSw 8kI7YIMaKlTbYeFeNxpfLp3XyiK24aR/7N84pB5TBHzfSw55b/z9Q8na57beDTKYDFm+oIzJfnv nYPavPRTjrvVQ8/BNQ8uN4rhcv60kmRNHSoDmwzimkE33Tfw9z1/8v8oybK78qQnqyFoXLvgIl+ llXzOPS3NQox7VZLCtcEbNkFAXp2c+MJRy9lzRCvmANOOPeF/c60xfjpZA4o9wDHFeWx8fj0LHP /q1HyMgLS1nl5bULYRxtqBlXFxZiuz7l8p0qs9wGqaKjo/zZN5YLKihmdfmq8DpxjqQw8qEdSX7 tAqtM/AenPrpjgP+YJ1Gdc5iVH/+Y3ArVmdpN2zh2dxRdltb3WBtwm0OZYmTFT55VpdJbFpp6sJ YE3JZQRYymWblxSI/wBfRoD8kORK3JCIQiBcr6Zu/SfiUXs5Tn2JRtOMGnPSkBnmCw== X-Received: by 2002:a05:600c:3b84:b0:4bb:6f45:2a6d with SMTP id 5b1f17b1804b1-4bb888074bbmr901098765e9.12.1796154813223; Tue, 01 Dec 2026 11:53:33 -0800 (PST) Received: from SMI-ubuntu.tail1789c7.ts.net ([2a01:390:0:101:ee93:d613:741b:a9ba]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb39dd4e7sm345417185e9.0.2026.12.01.11.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 11:53:33 -0800 (PST) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ v4 2/2] main.conf: Add 'paired' to ReverseServiceDiscovery Date: Tue, 1 Dec 2026 20:53:30 +0100 Message-ID: <20261201195330.3564672-2-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201195330.3564672-1-simon.mikuda@streamunlimited.com> References: <20261201195330.3564672-1-simon.mikuda@streamunlimited.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When a device that is not paired connects to us over LE, its GATT client is created and the profiles are accepted on its services. Their attach reads characteristic values right away, e.g. BAP the PAC records or CSIP the SIRK. When the remote protects them it answers Insufficient Authentication (0x05) or Insufficient Encryption (0x0f), bt_att raises the security level to retry the read, and the device is asked to pair although nobody requested it. ReverseServiceDiscovery = false avoids this for LE by not creating the GATT client of such a link at all. Add 'paired' in addition to true and false: with it, the GATT client of a device that connected to us, and with it the profiles' accept, is started only once the device is paired, and reverse SDP of a BR/EDR device likewise waits for pairing. The default stays true. Assisted-by: Claude:claude-opus-5-5 --- src/btd.h | 8 +++++++- src/device.c | 31 +++++++++++++++++++++++++++---- src/main.c | 29 ++++++++++++++++++++++++++--- src/main.conf | 3 +++ 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/btd.h b/src/btd.h index 9bf310271..2c897756c 100644 --- a/src/btd.h +++ b/src/btd.h @@ -48,6 +48,12 @@ enum bt_gatt_export_t { BT_GATT_EXPORT_READ_WRITE, }; +enum reverse_discovery_t { + REVERSE_DISCOVERY_NEVER, + REVERSE_DISCOVERY_ALWAYS, + REVERSE_DISCOVERY_PAIRED, +}; + struct btd_br_defaults { uint16_t page_scan_type; uint16_t page_scan_interval; @@ -144,7 +150,7 @@ struct btd_opts { struct btd_defaults defaults; - bool reverse_discovery; + uint8_t reverse_discovery; bool name_resolv; bool debug_keys; bool fast_conn; diff --git a/src/device.c b/src/device.c index 0e34dd380..f469b099c 100644 --- a/src/device.c +++ b/src/device.c @@ -351,6 +351,18 @@ bool btd_device_is_initiator(struct btd_device *dev) return dev->att_io ? true : false; } +static bool reverse_discovery(struct btd_device *dev, uint8_t bdaddr_type) +{ + switch (btd_opts.reverse_discovery) { + case REVERSE_DISCOVERY_ALWAYS: + return true; + case REVERSE_DISCOVERY_PAIRED: + return device_is_paired(dev, bdaddr_type); + default: + return false; + } +} + static GSList *find_service_with_profile(GSList *list, struct btd_profile *p) { GSList *l; @@ -6483,7 +6495,8 @@ static void gatt_client_init(struct btd_device *device) gatt_client_cleanup(device); - if (!btd_device_is_initiator(device) && !btd_opts.reverse_discovery) { + if (!btd_device_is_initiator(device) && + !reverse_discovery(device, device->bdaddr_type)) { DBG("Reverse service discovery disabled: skipping GATT client"); return; } @@ -6982,6 +6995,12 @@ static int device_browse_gatt(struct btd_device *device, DBusMessage *msg) if (!req) return -EBUSY; + /* Connected without a client, as reverse discovery waited for the + * device to be paired: start it on the existing link. + */ + if (!device->client && device->att) + gatt_client_init(device); + if (device->client) { /* * If discovery has not yet completed, then wait for gatt-client @@ -7650,7 +7669,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, } else if (!state->svc_resolved && !state->browse && !state->discov_timer && (state->connected || !other->connected) && - btd_opts.reverse_discovery) { + reverse_discovery(device, bdaddr_type)) { /* If we are not initiators and there is no currently * active discovery or discovery timer, set discovery * timer on the bearer that was bonded. A bearer bonded @@ -7698,9 +7717,13 @@ unsigned int device_wait_for_svc_complete(struct btd_device *dev, dev->svc_callbacks = g_slist_prepend(dev->svc_callbacks, cb); - if (state->svc_resolved || !btd_opts.reverse_discovery) + /* A browse in progress resolves the services whatever the reverse + * discovery policy: the policy only keeps one from being started. + */ + if (state->svc_resolved || (!state->browse && + !reverse_discovery(dev, BDADDR_BREDR))) cb->idle_id = g_idle_add(svc_idle_cb, cb); - else { + else if (!state->browse) { if (dev->bredr_state.discov_timer > 0) timeout_remove(dev->bredr_state.discov_timer); diff --git a/src/main.c b/src/main.c index 3a051c5a4..3672bb707 100644 --- a/src/main.c +++ b/src/main.c @@ -924,6 +924,30 @@ static bool parse_config_bool(GKeyFile *config, const char *group, return true; } +static void parse_reverse_discovery(GKeyFile *config) +{ + char *str = NULL; + bool val; + + if (parse_config_bool(config, "General", "ReverseServiceDiscovery", + &val)) { + btd_opts.reverse_discovery = val ? REVERSE_DISCOVERY_ALWAYS : + REVERSE_DISCOVERY_NEVER; + return; + } + + if (!parse_config_string(config, "General", "ReverseServiceDiscovery", + &str)) + return; + + if (!strcmp(str, "paired")) + btd_opts.reverse_discovery = REVERSE_DISCOVERY_PAIRED; + else + warn("Invalid value for ReverseServiceDiscovery: %s", str); + + g_free(str); +} + static void parse_privacy(GKeyFile *config) { char *str = NULL; @@ -1096,8 +1120,7 @@ static void parse_general(GKeyFile *config) &btd_opts.pairto, 0, UINT32_MAX); parse_device_id(config); - parse_config_bool(config, "General", "ReverseServiceDiscovery", - &btd_opts.reverse_discovery); + parse_reverse_discovery(config); parse_config_bool(config, "General", "NameResolving", &btd_opts.name_resolv); parse_config_bool(config, "General", "DebugKeys", @@ -1473,7 +1496,7 @@ static void init_defaults(void) btd_opts.pairto = DEFAULT_PAIRABLE_TIMEOUT; btd_opts.discovto = DEFAULT_DISCOVERABLE_TIMEOUT; btd_opts.tmpto = DEFAULT_TEMPORARY_TIMEOUT; - btd_opts.reverse_discovery = TRUE; + btd_opts.reverse_discovery = REVERSE_DISCOVERY_ALWAYS; btd_opts.name_resolv = TRUE; btd_opts.debug_keys = FALSE; btd_opts.refresh_discovery = TRUE; diff --git a/src/main.conf b/src/main.conf index c9906148d..3ee6897c1 100644 --- a/src/main.conf +++ b/src/main.conf @@ -34,6 +34,9 @@ # BITE tester doesn't like us doing reverse SDP for some test cases, for LE # this disables the GATT client functionally so it can be used in system which # can only operate as peripheral (see also GATT Client option). +# Possible values: 'true', 'false' or 'paired'. With 'paired' it is done only +# once the device is paired, so that the profiles do not start pairing with a +# device that connected to us by reading characteristics that need encryption. # Defaults to 'true'. #ReverseServiceDiscovery = true -- 2.43.0