1

Problem description I have a BLE device. I want to communicate with it. My Android application code:

device.connectGatt(context, false, ...)

If the device is in pairing mode, I can connect to it. But if I want to connect to already paired device with the same code, I get an error. Exactly the same use case works well on my Linux PC with the device in pairing and non-pairing mode. (I've used Python gatt module for it)

I've dumped the Bluetooth traffic and I see some differences there during the connection.

Linux/not pairing

  • Sent: LE Create Connection
  • Rcvd: Command Status (LE Create Connection)
  • Rcvd: LE Meta (LE Connection Complete)
  • Sent: LE Read Remote Features
  • Rcvd: LE Meta (LE Channel Selection Algorithm)
  • Rcvd: Command Status (LE Read Remote Features)
  • Rcvd: LE Meta (LE Read Remote Features Complete)
  • Sent: LE Start Encryption

Android/pairing

  • Sent: LE Create Connection
  • Rcvd: Command Status (LE Create Connection)
  • Rcvd: LE Meta (LE Enhanced Connection Complete)
  • Sent: LE Read Peer Resolvable Address
  • Rcvd: Command Complete (LE Read Peer Resolvable Address)
  • Sent: LE Read Remote Features
  • Rcvd: Command Status (LE Read Remote Features)
  • Rcvd: LE Meta (LE Read Remote Features Complete)
  • Sent: Read Remote Version Information
  • Rcvd: Command Status (Read Remote Version Information)
  • Rcvd: Read Remote Version Information Complete
  • Sent: LE Start Encryption

Android/not pairing

  • Sent: LE Create Connection
  • Rcvd: Command Status (LE Create Connection)
  • Rcvd: LE Meta (LE Enhanced Connection Complete)
  • Sent: LE Read Peer Resolvable Address
  • Rcvd: Command Complete (LE Read Peer Resolvable Address)
  • Sent: LE Read Remote Features
  • Rcvd: Command Status (LE Read Remote Features)
  • Rcvd: LE Meta (LE Read Remote Features Complete) <-- Failed with Status: Connection Failed to be Established (0x3e)

So I've decided to compare the content of

LE Meta (LE Read Remote Features Complete)

packets of all 3 tries:

Linux/not pairing: Supported LE Features: 0x0000000000004105, LE Encryption, Extended Reject Indication, LE 2M PHY, Channel Selection Algorithm #2

Android/pairing: Supported LE Features: 0x0000000000000005, LE Encryption, Extended Reject Indication

Android/not pairing: Supported LE Features: 0x00000000000000ef, LE Encryption, Connection Parameters Request Procedure, Extended Reject Indication, Slave-Initiated Features Exchange, Data Packet Length Extension, LL Privacy, Extended Scanner Filter Policies

Does anyone knows how can I solve this problem?

Dmitriy Erlih
  • 507
  • 2
  • 4
  • 12

1 Answers1

2

"Connection failed to be established" means that after the master sent out CONNECT_IND in response to an ADV_IND, the slave does not seem to respond to any data packets the master sends out. This either happens due to some hardware or firmware failure, bad signal quality or that the peripheral uses white listing to ignore connections from unwanted devices. There are no other reasons for this error to occur.

If white listing is in use by the peripheral, make sure it correctly handles resolvable addresses.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Thanks for your answer! Unfortunately I have almost no experience with BT and especially BLE topic :-( I think it shouldn't be a whitelist on a peripheral. It's a consumer device. Do you know if this connection diagram looks valid? https://asset-group.github.io/disclosures/sweyntooth/Figures/ble_sequence.pdf.svg – Dmitriy Erlih Sep 09 '20 at 17:51
  • Yes it looks ok – Emil Sep 10 '20 at 08:19