This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Android 6+ can´t (re)connect to nRF51822 in DIRECT ADVERTISE mode

Hi,

We are using nRF51822, SDK12.3, pca10028, S130 with "Red Bear BLE Nano V1.5" board.
We try also in nRF51DK and our own board (designed by us) and the issue is the same.
So we think the problem is not in module but in Android version or in code.
We try in several Smartphones: Samsung S9 (Android 8), Samsung Note 8 (Android 7.1.1),
Samsung S8 (Android 7.0), Huawei Y7 (Android 7.0) and Samsung S4 (Android 5.0.1).
With Samsung S4 (Android 5) everything works great.
In smartphones (Android) we use "nRF Connect" App.

We start with ble_app_uart example code, and change it to addapt to our specific needs.
The program have whitelist enabled and PASSKEY to bond.
The program start advertise in SLOW ADVERTISE mode, bond just one smartphone (with PASSKEY) and then if smartphone disconnect, the program start advertise in DIRECT ADVERTISE mode, forever until the smartphone in whiteliste, connect with it again. For tests we put DIRECT ADVERTISE mode just with 3 minutes and then pass to advertise in SLOW ADVERTISE mode.
So, with Samsung S4, everything works great. With other smartphones (Android 6+ versions) just work the first step (connect in SLOW ADVERTISE mode and bond with PASSKEY). When nRF51822 start advertise in DIRECT ADVERTISE mode, it's not possible connect with it again. If advertise pass to SLOW ADVERTISE mode again, it is possible connect without any problem.
We try change the intervals and other things but with no success.
Now we are use
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(12, UNIT_1_25_MS) //100
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(16, UNIT_1_25_MS) //200

ble_adv_modes_config_t options;
memset(&options, 0, sizeof(options));
options.ble_adv_whitelist_enabled = true;
options.ble_adv_fast_enabled = false;
options.ble_adv_slow_enabled = true;
options.ble_adv_slow_interval = 300;
options.ble_adv_slow_timeout = 0; //Forever, until connect.
options.ble_adv_directed_enabled = true;
options.ble_adv_directed_slow_enabled = true;
options.ble_adv_directed_slow_interval = 40; //0x320;
options.ble_adv_directed_slow_timeout = 180; //0;

We also use nRF51DK with sniffer to capture packets and also use the option (HCI snoop log Bluetooth) in smartphones to capture all the packets.

In first screenshot (captured in samsung S4) we see packet #16083 "LE Create Connection" and #16085 "LE Connection Complete". This is the re(connect) to DIRECT ADVERTISE and work perfectly.
We see "Peer Address Type: Random Device Address (0x01)" and "Own Address Type: Public Device address (0x00)".
Before "LE Create Connection" packet exist other packet #16081 "LE Set Advertising Parameters". I don't know the importance of this packet because with (Android 6+) we don't have this packet.

In second screenshot (captured with sniffer nRF51DK) we see packet #12748 "ADV_DIRECT_IND".
In Packet Header we have "Tx Address: Random" and "Rx address: Public" and in packet #12749 "CONNECT REQ".
So, this is the scenario with Samsung S4 where everything works great.

Now, with other smartphones (Android 6+):
In third screenshot (captured in Samsung S8) we see packet #3021 "LE Create Connection".
"Peer Address Type: Random (Static) Identity Address (Private) (0x03)" and "Own Address Type: Random (Static) Identity Address (Private) (0x03)".
We think the problem is here!!!
And in packet #3023 the smartphone takes the initiative to cancel the "Create Connection", after 5 seconds.
We don't understand why smartphone cancel the connection.
In nRF Connect App in android have "Error: 133 (0x85): GATT ERROR".
Here we try turn off and on again the bluetooth, several times, but without any success.

In nRF51DK sniffer don't appear any packet from smartphone.
We have in fourth screenshot the DIRECT ADVERTISE packet, and we see in Packet Header "Tx Address: Random" and "Rx Address: Public".

Other info (I don't know if it matters):
In SLOW ADVERTISE mode, the Packet Header is 0x2240 (Type: ADV_IND ; Tx Address: Random (1) ; Reserver: False (0)).

Connecting with Samsung S8 (Android 6+) the packet CONNECT_REQ have Packet Header 0x22C5 (type: CONNECT_REQ ; Tx Address: Random (1) ; Rx Address: Random (1)).
And then DIRECT ADVERTISE the packet ADV_DIRECT_IND have Packet Header 0xC41 (type: ADV_DIRECT_IND ; Tx Address: Random (1) ; Rx Address: Public (0)).

Connecting with Samsung S4 (Android 5) the packet CONNECT_REQ have Packet Header 0x2285 (type: CONNECT_REQ ; Tx Address: Public (0) ; Rx Address: Random (1)).
And then DIRECT ADVERTISE the packet ADV_DIRECT_IND have Packet Header 0xC41 (type: ADV_DIRECT_IND ; Tx Address: Random (1) ; Rx Address: Public (0)).

I know this is long, but i try to put here relevant info to anyone try to help us.

Thanks in advance.

Related