2022-09-20 09:36 AM
Hello,
Setup:
STM32WB,
Wireless Firmware version 1.14.1
Wireless Firmware build 1
FUS version 1.1.0
Working on a custom board
Phone Xiaomi MI A2 Android 10
My issue is that my custom device (server) don't accept connection with a phone (client) that is already saved in the whitelist.
I followed the tutorial below to configure my device:
Steps:
1- On my device I start by initializing the BLE, then I clear the whitelist
2- On the phone I clear the bond of my device.
3- Device: start advertising (aci_gap_set_discoverable(ADV_IND, Min_Inter, Max_Inter, PUBLIC_ADDR, WHITE_LIST_FOR_ONLY_CONN, sizeof(local_name), (uint8_t*) &local_name, BleApplicationContext.BleApplicationContext_legacy.advtServUUIDlen, BleApplicationContext.BleApplicationContext_legacy.advtServUUID, 0, 0);
4- With my phone I connect then bond to the device (using ST toolbox last version).
5- On the phone I click disconnect
6- On the device on disconnection event I save whitelist (aci_gap_configure_whitelist())
7- Device: restart advertisement: aci_gap_set_undirected_connectable(Min_Inter, Max_Inter, PUBLIC_ADDR, WHITE_LIST_FOR_ALL);
8- Phone: try to connect to the device
In step 8 the device is not seen by the phone! while the advertise, checked by wireshark.
When I change step 7 to:
- Restart step 1 to 6 then:
7a- Device: restart advertisement, same command as step 3
8a- Phone: try to connect to the device and succeed
9a- Disconnect the phone and try to connect using another phone
10a- the connection and pairing succeed with the second phone while I want only 1 client that could connect and bond to my device.
My main question is how to configure whitelist and advertisement to have only one client that could connect and bond to my device?
I tried to add a check in HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE event:
bool device_in_whitelist = _aos_ble_core_check_device_in_whitelist(&bond_count, connection_complete_event->Peer_Address);
if ((!device_in_whitelist) && (bond_count >= MAX_BOUNDED_COUNT)) {
APP_DBG_MSG("Drop bonding: Max bounded devices reached (%d/%d dev)\n", bond_count, MAX_BOUNDED_COUNT);
aos_ble_core_stop_connectivity(true);
}
with MAX_BOUNDED_COUNT = 1
So I check if the connected client is not in whitelist and if the whitelist is full the device stop the connection then restart advertisement.
But here the bonded phone is not found in the whitelist while it was already saved!
I phone was not found because when I compare the ble addr in connection_complete_event->Peer_Address (from the event context) and Bonded_Device_Entry[i].Address (from aci_gap_get_bonded_devices(bond_count, Bonded_Device_Entry)) I don't get the same address.
In the first connection (step 4) the ble address read in connection_complete_event->Peer_Address is 6b 64 e5 52 d5 4a (this is the address that I see in wireshark)
And when I disconnect and save the phone in the whitelist, aci_gap_get_bonded_devices() return this address 48 2c a0 1b 01 6f (this one is the ble mac address that I see in the phone config)
Finally after when the phone try to connect again (step 8a) the address in connection_complete_event->Peer_Address is 53 3a 20 c7 37 ff
The phone seems to change it's address read in connection_complete_event->Peer_Address but the saved address in whitelist still the same 48 2c a0 1b 01 6f.
My device don't recognize the phone in step 8, is it because the advertised address is different from the saved address in whitelist? and how to resolve this issue?
Thanks