Linux bluetooth development
 help / color / mirror / Atom feed
From: Andrea Daoud <andreadaoud6@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] adapter: Load defaults before probing drivers
Date: Mon, 30 Nov 2026 18:09:35 +0100	[thread overview]
Message-ID: <179605857505.1239633.6683321244449767140@gmail.com> (raw)

With AutoEnable=true, the first automatic power-on can ignore the
PageScanInterval set in main.conf. The controller starts listening for
BR/EDR connections at its previous interval. The configured interval
takes effect only on the next power-on. The reason is that the policy 
driver's probe can queue Set Powered before adapter registration
queues Set Default System Configuration. Linux therefore
programs the controller before it receives the configured interval.

Queue the defaults before probing adapter drivers so the first automatic
power-on uses the configured parameters.
---
Explanations:

During adapter registration, load_drivers() probes the policy plugin.
With AutoEnable enabled and the adapter off, policy_adapter_probe() calls
btd_adapter_restore_powered(), which queues Set Powered (0x0005).
Registration then calls load_defaults(), which queues Set Default System
Configuration (0x004c).

At power-on, Linux programs the controller with the page scan values
currently stored in hci_dev. The later Set Default System Configuration
command updates hci_dev, so the controller picks up the new values only on
the next power-on.

To reproduce this issue, use a BR/EDR adapter that supports interlaced page scan.
Leave fast connectable mode disabled so Linux uses the configured page
scan type and interval. Set the following in /etc/bluetooth/main.conf:

    [Policy]
    AutoEnable=true

    [BR]
    PageScanType=1
    PageScanInterval=1024
    PageScanWindow=36

Boot with the adapter present. Before toggling adapter power, read the
kernel defaults and the two controller registers:

    bluetoothctl mgmt.read-sysconfig
    bluetoothctl mgmt.hci-cmd 0x0c1b 0 2
    bluetoothctl mgmt.hci-cmd 0x0c46 0 2

The management types 0x0000, 0x0001 and 0x0002 are page scan type,
interval and window. The HCI commands are Read Page Scan Activity and
Read Page Scan Type. Interval and window use 0.625 ms units.

## Hardware results

Tested on an Intel AX200 using the existing Linux BR/EDR page-scan
implementation.
                                        Interval   Window     Type
    BlueZ 5.87, first power-on           1280 ms   11.25 ms   standard
    BlueZ 5.87, after manual off/on       640 ms   22.5 ms    interlaced
    BlueZ 5.87 + patch, first power-on    640 ms   22.5 ms    interlaced

On both boots, the kernel reported the configured values. On the first
power-on, the controller's activity/type replies changed from
"00 00 08 12 00" / "00 00" to "00 00 04 24 00" / "00 01" with the patch.

 src/adapter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/adapter.c b/src/adapter.c
index 112312651..1ec1c7039 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -10011,10 +10011,10 @@ load:
 
 	load_config(adapter);
 	fix_storage(adapter);
+	load_defaults(adapter);
 	load_drivers(adapter);
 	btd_profile_foreach(probe_profile, adapter);
 	clear_blocked(adapter);
-	load_defaults(adapter);
 	load_devices(adapter);
 
 	/* restore Service Changed CCC value for bonded devices */

                 reply	other threads:[~2026-11-30 17:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=179605857505.1239633.6683321244449767140@gmail.com \
    --to=andreadaoud6@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