0

I'm using https://github.com/edrosten/libblepp for communicating with BLE devices from C++.

Until now I've successfully connected to a few devices but now there is a device which fails when I try to read some GATT characteristic with this error:

Attribute requires authentication before read/write

When I try with gatttool, it is working:

# gatttool -t random -b MAC --char-read --handle=0x0001
Characteristic value/descriptor: a b c d

I've then found this question: Attribute requires authentication before read/write which holds the answer (at least I think).

gatttool by default uses 'low' as security level based on the help:

# gatttool --help-all
...
-l, --sec-level=[low | medium | high]     Set security level. Default: low

(How) is it possible to change security level with libblepp? (Is this security level setting just some basic binary command flag, or something more complex?)

Daniel
  • 1,887
  • 2
  • 18
  • 40
  • That lib is kind of a many years old hack into the backend part of the BlueZ stack. It doesn't seem to support pairing. You should use BlueZ from the DBUS API instead. – Emil Jun 10 '20 at 12:30
  • gatttool seems to use `setsockopt(sock, SOL_BLUETOOTH, BT_SECURITY, &sec, sizeof(sec))` after bind (`sec` is a `bt_security` struct with level field set to 1 by default). I prefer not to use DBUS for sending 2 bytes on a standard unix socket so I'd avoid it if I can. – Daniel Jun 10 '20 at 14:08
  • However there should also be something else, because even after adding this setsockopt (which succeeds), still the connection is not able to execute gatt commands. – Daniel Jun 10 '20 at 14:10

0 Answers0