Cannot pair on Pico 2 W with FreeRTOS

61 views
Skip to first unread message

Mattia

unread,
Jul 20, 2026, 11:32:21 AMJul 20
to btstack-dev
Hi, I'm trying to make some code based on this example work. 
Both the example and my modified code work great on the board that I'm working on. 
The problem arise when I try to implement it with FreeRTOS. 
When I first flashed the FreeRTOS modified version I could connect with my device, a Google Pixel 8a, which was already paired. 
I opened the Bluetooth settings and clicked on the device and it connected without problems. 
However, after I remove the pico from the list of paired device on my phone, I can't pair anymore.
I tried clearing the link keys from the TLV memory but it didn't help.
There are both the Wireshark file with the packets captured by the HCI dump from the pico and the dump from bluetooth_manager service on my Android device attached below.
Any help would be greatly appreciated, thanks.
Cheers 
Mattia

Mattia

unread,
Jul 20, 2026, 12:08:12 PMJul 20
to btstack-dev
I forget to mention that I use the pico-sdk version 2.3.0 and I tried my old code compiled under sdk version 2.3.0 no longer works, I think it's because of the updates made to the btstack that tighten security. I've tried to pair an iPad running iOS 18.7.9, a desktop arch linux just updated and a laptop arch linux with no luck.
Mattia

Brian Reinhold

unread,
Jul 21, 2026, 5:33:35 AM (13 days ago) Jul 21
to btsta...@googlegroups.com
Mattia,

First, I can't tell if you are working with classic Bluetooth or BLE. I see both in the traces and especially the Android capture. My knowledge of classic Bluetooth is pretty limited but it would certainly help if the traces were cleaned up a bit; especially the Android dump. There is so much stuff in there it's hard to tell what is relevant. The lack of correct time stamps in the Wireshark capture doesn't help with coordination.

However, in the Wireshark trace I see IRKs and related packet exchanges so I am assuming this is a BLE connection.
I have to also admit that I am not very good at HCI. I aways did over-the-air sniffs which is quite different. An 05 error in the LE exchange over the airwaves is 'insufficient authentication' which happens when you try to connect and pairing is needed. An 05 error in HCI means the pairing failed (wrong passkey, one side thinks it is already paired and the other doesnt so there is an inconsistent expectation of either a pairing request or an encryption request, or simply incorrect keys).

Are you sure you have a clean slate ? (Both sides know nothing of each other.)  My HCI is not good enough to tell if the 'MITM is required' is for this connection or just generic information about what one needs to do for security level 2.

It might help if you explain what your device is and what kind of pairing is being attempted (legacy (SSP and it's various friends) or the 'new' secure connections). For me it would really help if you had an over the air sniff.

--
You received this message because you are subscribed to the Google Groups "btstack-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/d49f699a-878b-4b5d-bad2-f4f0bfb02140n%40googlegroups.com.

Matthias Ringwald

unread,
Jul 21, 2026, 5:40:38 AM (13 days ago) Jul 21
to btsta...@googlegroups.com
Hi Matthia

Looking at the BTstack WireShark, you can see that the pairing fails after there's no confirmation for the "HCI Event User Confirmation Request".

Jan 01 11:00:10.674 HCI Event User Confirmation Request - FC:41:16:DD:B9:7A
Jan 01 11:00:42.663 HCI Event Simple Pairing Complete - FC:41:16:DD:B9:7A - Authentication Failure

The most likely case is that we increased the default security requirements for the stack in the latest v1.8,2 after receiving various "Vulnerability Disclosure" reports that result from the examples configure to "just work" as much as possible.
All examples have been update to e.g accept pairing, but print a warning that a user should be asked if that's ok.

For the a2dp sink, you need to accept the pairingon HCI_EVENT_USER_CONFIRMATION_REQUEST, like here:
https://github.com/bluekitchen/btstack/commit/9dd2e3bc4c0bd162163288cfbde68c5fcf07c645

Cheers
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/1736c096-b639-411f-97c1-1c3a9b68941cn%40googlegroups.com.

Mattia

unread,
Jul 21, 2026, 7:29:43 AM (13 days ago) Jul 21
to btstack-dev
Hi, 
thanks both for the help, my theory was correct, in fact I tried recompile with the old pico-sdk which has the older btstack release and it worked.  As Matthias said it was the increased default security requirements. 
For the moment I set the security to the old defaults as I find in the manual:

The default SMP configuration in BTstack is to be as open as possible:

  • accept all Short Term Key (STK) Generation methods,

  • accept encryption key size from 7..16 bytes,

  • expect no authentication requirements,

  • don't require LE Secure Connections, and

  • IO Capabilities set to IO_CAPABILITY_NO_INPUT_NO_OUTPUT.

    // Set to old defaults
    sm_set_accepted_stk_generation_methods(SM_STK_GENERATION_METHOD_JUST_WORKS);
    sm_set_encryption_key_size_range(7,16);
    sm_set_authentication_requirements(SM_AUTHREQ_BONDING);
    sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);

With this configuration everything works even if it's not secure but I look more into it later.

I have another question I'm trying to connect from the pico to my phone directly, the MAC address of the phone is saved in pico's memory and they are already paired.
How can i do it?
Referring Matthias' example if I call the function a2dp_sink_establish_stream(device_addr, &myConnection->a2dp_cid);
the a2dp_packet_handler callback reports that the connection failed mostly with error 0x66 which is L2CAP_CONNECTION_BASEBAND_DISCONNECT.

I'm experimenting with l2cap_create_channel(l2cap_packet_handler, device_addr, 0x01, HCI_ACL_PAYLOAD_SIZE, &local_cid) to establish a connection and it connects to the phone
but I need to establish the a2dp sink connection so i call a2dp_sink_establish_stream(...), the system seems to hang for like 15-20 seconds but the other tasks continue to run (I'm using FreeRTOS and I can use the touchscreen in the meantime) and then it establish the stream and everything works.

I know I'm missing something and probably the way I'm doing it's not correct.

Mattia.

Mattia

unread,
Jul 21, 2026, 8:08:14 AM (13 days ago) Jul 21
to btstack-dev
I made a mistake it was error 0x6a which is L2CAP_CONNECTION_BASEBAND_DISCONNECT not 0x66.
Mattia

Matthias Ringwald

unread,
Jul 21, 2026, 9:10:38 AM (13 days ago) Jul 21
to btsta...@googlegroups.com
Hi Mattia

To initiate a connection a2dp_sink_establish_stream(..) is the correct API. If that fails, please paste the local HCI log.

If you're using an RTOS like FreeRTOS, it's important that you only call BTstack API functions from the BTstack main thread. You can use "btstack_run_loop_execute_on_main_thread" to schedule a function to get called on the BTstack thread which then could check some globals or a thread-safe queue on what to do. If not, anything might or might not happen.

Cheers
Matthias
> To view this discussion visit https://groups.google.com/d/msgid/btstack-dev/f285fc34-ab15-4d09-9e11-a520add63435n%40googlegroups.com.


Mattia

unread,
Jul 21, 2026, 9:58:14 AM (13 days ago) Jul 21
to btstack-dev
Hi Matthias,
I created a thread for the bluetooth configuration and from there I call btstack_run_loop_execute_on_main_thread(..) as the last thing before entering an infinite loop in that thread. Is it correct? I don't call any btstack API outside of this thread.
Do I need to set a higher priority for this thread or can it stay the same as the others?
If I connect from the phone it works but the other way around it does not.
Here it is the Wireshark capture.

Best regards,
Mattia.

Mattia

unread,
Jul 24, 2026, 9:19:31 AM (10 days ago) Jul 24
to btstack-dev
Hi Matthias, 
so now I'm trying the a2dp_sink_demo example compiled for the Pimoroni pico 2W plus board with sdk version 2.3 and btstack 1.8.2 and I'm experiencing the same behaviour.
I have set the MAC address of my phone (Pixel 8a) in the device_addr_string variable in the code. 
If I try to connect to my phone with the 'b' command, after successful pairing, but after I restarted the pico, it doesn't work, it gives error 0x66 or sometimes 0x6a. 
If I try to connect to the pico using my phone, always after a successful pairing, it doesn't work, it seems to connect for a second but it immediately disconnects.
The last odd behaviour I'm experiencing is that after deleting the paired pico from the list on my phone and pair it again, 
the phone connects to the pico and if I disconnect the pico with the 'B' command, I can reconnect it with 'b' command but only if I don't restart the pico.
The last thing is that the Cover Art Client can't connect anymore with the phone using the 'd' command.
I attach the packet log of the different scenarios.

Thanks,
Best regards,
Mattia.

Mattia

unread,
Jul 28, 2026, 4:51:57 PM (6 days ago) Jul 28
to btstack-dev
Hi Matthias,
Do you have any new ideas on how to resolve the problem?
I bought a BLESniffer, tomorrow it will arrive, I hope it will shed some light on the causes of the error. I tried different combination of security settings but with no luck.
The code of the bluetooth part is the same as that in the example (a2dp_sink_demo), do you need me to share the code, will it be easier to pinpoint the problem?

Thanks in advance for any help.

Best regards,
Mattia.
Reply all
Reply to author
Forward
0 new messages