Raspberry BLE Encryption / Pairing

2

I'm trying to use my Raspberry Pi 3B to communicate with a BLE enabled device which dosen't require a PIN.

I first tried with Ionic on iOS using cordova BLE central (https://github.com/don/cordova-plugin-ble-central), which worked as expected, here is the exchanged packets :

iOS (PacketLogger)

May 21 07:59:36.825  Note             0x0000                     Product: iPhone9,3  
May 21 07:59:36.825  Note             0x0000                     Software: Version 13.4 (Build 17E255)  
May 21 08:09:42.178  Config           0x0041  315X               Connected: C4:64:E3:9B:04:44 - Handle: 0x41 - 315X - C7D0F30E-78B4-C82C-6912-DD0F5A5BCA2E  
May 21 08:09:43.690  HCI Command      0x0041  00:00:00:00:00:00  Disconnect - Connection Handle: 0x0041 - Reason: Remote User Terminated Connection  
May 21 08:09:43.690  Power            0x0000                     H4 wake  
May 21 08:09:43.690  HCI Event        0x0000                     Command Status - Disconnect  
May 21 08:09:43.705  LMP Sent         0x0041  00:00:00:00:00:00  LE Terminate Indicator - Error: 0x13  
May 21 08:09:43.706  HCI Event        0x0041  00:00:00:00:00:00  Disconnection Complete - Success  
May 21 08:09:43.710  Config           0x0000                     (  
May 21 08:09:43.710  Config           0x0000                     Invalid packet  
May 21 08:09:43.710  Config           0x0000                     (  
May 21 08:09:43.710  Config           0x0000                     Invalid packet  
May 21 08:09:43.710  Config           0x0000                     Invalid packet  
May 21 08:09:43.710  Config           0x0000                     Invalid packet  
May 21 08:09:43.891  Power            0x0000                     H4 sleep  
May 21 08:09:47.801  HCI Command      0x0000                     LE Set Scan Enable - 0x00, Filter Duplicates: 1  
May 21 08:09:47.801  Power            0x0000                     H4 wake  
May 21 08:09:47.803  HCI Event        0x0000                     Command Complete [200C] - LE Set Scan Enable  
May 21 08:09:47.803  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:47.804  HCI Event        0x0000                     Command Complete [FCE9] -   
May 21 08:09:47.804  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:47.804  HCI Event        0x0000                     Command Complete [FCE9] -   
May 21 08:09:47.804  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:47.804  HCI Event        0x0000                     Command Complete [FCE9] -   
May 21 08:09:47.804  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:47.805  HCI Event        0x0000                     Command Complete [FCE9] -   
May 21 08:09:47.805  HCI Command      0x0000                     LE Set Scan Parameters - Active - 30/40 (ms)  
May 21 08:09:47.805  HCI Event        0x0000                     Command Complete [200B] - LE Set Scan Parameters  
May 21 08:09:47.805  HCI Command      0x0000                     LE Set Scan Enable - 0x01, Filter Duplicates: 1  
May 21 08:09:47.805  HCI Event        0x0000                     Command Complete [200C] - LE Set Scan Enable  
May 21 08:09:47.808  HCI Event        0x0000  315X               LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44  -59 dBm - Channel 37  
May 21 08:09:47.809  HCI Event        0x0000  315X               LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44  -60 dBm - Manufacturer Specific Data - 315X - Channel 37  
May 21 08:09:48.006  Power            0x0000                     H4 sleep  
May 21 08:09:48.636  HCI Command      0x0000  315X               LE Add Device To White List - Public - C4:64:E3:9B:04:44  
May 21 08:09:48.636  Power            0x0000                     H4 wake  
May 21 08:09:48.636  HCI Event        0x0000                     Command Complete [2011] - LE Add Device To White List  
May 21 08:09:48.643  HCI Command      0x0000                     LE Create Connection - 00:00:00:00:00:00, Scan Window/Interval: 30ms/30ms, Min/Max Conn Interval: 10ms/30ms   
May 21 08:09:48.647  HCI Event        0x0000                     Command Status - LE Create Connection  
May 21 08:09:48.701  HCI Event        0x0000  315X               LE - Advertising Report - 1 Report - Normal - Public - C4:64:E3:9B:04:44  -57 dBm - Channel 38/37  
May 21 08:09:48.702  HCI Event        0x0041  315X               LE - Enhanced Connection Complete - Master - Public - C4:64:E3:9B:04:44 local - 00:00:00:00:00:00 peer - 00:00:00:00:00:00 - Conn Interval: 30 ms  
May 21 08:09:48.704  HCI Command      0x0000  315X               LE Remove Device From White List - 0 - C4:64:E3:9B:04:44  
May 21 08:09:48.704  HCI Event        0x0000                     Command Complete [2012] - LE Remove Device From White List  
May 21 08:09:48.704  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:48.704  HCI Event        0x0000                     Command Complete [FDC1] -   
May 21 08:09:48.706  HCI Command      0x0041  315X               LE Start Encryption - Connection Handle: 0x0041  
May 21 08:09:48.706  HCI Event        0x0000                     Command Status - LE Start Encryption  
May 21 08:09:48.712  LMP Sent         0x0041  315X               LE Version Indicator  
May 21 08:09:48.741  LMP Received     0x0041  315X               LE Version Indicator  
May 21 08:09:48.772  LMP Sent         0x0041  315X               LE Encryption Request  
May 21 08:09:48.801  LMP Received     0x0041  315X               LE Encryption Response  
May 21 08:09:48.861  LMP Received     0x0041  315X               LE Start Encryption Request  
May 21 08:09:48.891  LMP Sent         0x0041  315X               LE Start Encryption Response  
May 21 08:09:48.922  HCI Event        0x0041  315X               Encryption Change Complete - Encryption Enabled  
May 21 08:09:48.922  HCI Command      0x0041  315X               Read Remote Version Information - Connection Handle: 0x0041  
May 21 08:09:48.922  LMP Received     0x0041  315X               LE Start Encryption Response  
May 21 08:09:48.922  HCI Event        0x0000                     Command Status - Read Remote Version Information  
May 21 08:09:48.922  HCI Event        0x0041  315X               Read Remote Version Information Complete  
May 21 08:09:48.922  HCI Command      0x0041  315X               LE Read Remote Used Features - Connection Handle: 0x0041  
May 21 08:09:48.922  HCI Event        0x0000                     Command Status - LE Read Remote Used Features  
May 21 08:09:48.923  HCI Command      0x0000                     Vendor Specific Command  
May 21 08:09:48.923  HCI Event        0x0000                     Command Complete [FD82] -   
May 21 08:09:48.952  LMP Sent         0x0041  315X               LE Feature Request - Feature Set: 0x00000000000000FD  
May 21 08:09:48.982  HCI Event        0x0041  315X               LE - Read Remote Used Features Complete - DPLE Supported  
May 21 08:09:48.982  LMP Received     0x0041  315X               LE Feature Response - Feature Set: 0x00000000000000FD  
May 21 08:09:49.012  LMP Sent         0x0041  315X               LE Length Request  
May 21 08:09:49.042  HCI Event        0x0041  315X               LE - Data Length Change  
May 21 08:09:49.042  LMP Received     0x0041  315X               LE Length Response  
May 21 08:09:49.044  ATT Send         0x0041  315X               Exchange MTU Request - MTU: 185  
May 21 08:09:49.101  ATT Receive      0x0041  315X               Exchange MTU Response - MTU: 65  
May 21 08:09:49.102  Config           0x0000                     A(  
May 21 08:09:49.102  Config           0x0000                     Invalid packet  
May 21 08:09:49.102  Config           0x0000                     A(  
May 21 08:09:49.102  Config           0x0000                     Invalid packet  
May 21 08:09:49.102  Config           0x0000                     Invalid packet  
May 21 08:09:49.102  Config           0x0000                     Invalid packet  
May 21 08:09:49.102  ATT Send         0x0041  315X               Read By Type Request - Start Handle: 0x0008 - End Handle: 0x0008 - UUID: GATT Characteristic Declaration  
May 21 08:09:49.130  HCI Event        0x0041  315X               Number Of Completed Packets - Handle: 0x0041 - Packets: 0x0002    
May 21 08:09:49.161  ATT Receive      0x0041  315X               Error Response - Attribute Handle: 0x0008 - Error Code: Attribute Not Found (0x0A)  
May 21 08:09:49.162  Config           0x0000                     Invalid packet  
May 21 08:09:49.162  Config           0x0000                     Invalid packet  
May 21 08:09:49.162  Config           0x0000                     Invalid packet  
May 21 08:09:49.162  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.165  Config           0x0000                     Invalid packet  
May 21 08:09:49.169  ATT Send         0x0041  315X               Read Request - Handle:0x0012  
May 21 08:09:49.222  ATT Receive      0x0041  315X               Read Response - Value: 4175 746F 6D6F 7765 7200 0000 0000 0000 …  
May 21 08:09:49.224  ATT Send         0x0041  315X               Write Request - Handle:0x000F - Value: 0100   
May 21 08:09:49.250  HCI Event        0x0041  315X               Number Of Completed Packets - Handle: 0x0041 - Packets: 0x0002    
May 21 08:09:49.281  ATT Receive      0x0041  315X               Write Response  

For raspberry I'm using noble (https://github.com/abandonware/noble), I'm able to discover device and read characteristics but look like the write commands dosen't work as expected.

hcidump

pi@raspberrypi:~ $ sudo hcidump -t -x
HCI sniffer - Bluetooth packet analyzer ver 5.50
device: hci0 snap_len: 1500 filter: 0xffffffff
2020-06-02 08:49:48.643635 < HCI Command: Set Event Mask (0x03|0x0001) plen 8
    Mask: 0xfffffbff07f8bf3d
2020-06-02 08:49:48.644192 > HCI Event: Command Complete (0x0e) plen 4
    Set Event Mask (0x03|0x0001) ncmd 1
    status 0x00
2020-06-02 08:49:48.644641 < HCI Command: LE Set Event Mask (0x08|0x0001) plen 8
    mask 0x1f00000000000000 (Reserved)
2020-06-02 08:49:48.645116 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Event Mask (0x08|0x0001) ncmd 1
    status 0x00
2020-06-02 08:49:48.645147 < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
2020-06-02 08:49:48.645641 > HCI Event: Command Complete (0x0e) plen 12
    Read Local Version Information (0x04|0x0001) ncmd 1
    status 0x00
    HCI Version: 4.1 (0x7) HCI Revision: 0x1ed
    LMP Version: 4.1 (0x7) LMP Subversion: 0x2209
    Manufacturer: Broadcom Corporation (15)
2020-06-02 08:49:48.645672 < HCI Command: Write LE Host Supported (0x03|0x006d) plen 2
  01 00 
2020-06-02 08:49:48.646081 > HCI Event: Command Complete (0x0e) plen 4
    Write LE Host Supported (0x03|0x006d) ncmd 1
    00 
2020-06-02 08:49:48.646264 < HCI Command: Read LE Host Supported (0x03|0x006c) plen 0
2020-06-02 08:49:48.646731 > HCI Event: Command Complete (0x0e) plen 6
    Read LE Host Supported (0x03|0x006c) ncmd 1
    00 01 00 
2020-06-02 08:49:48.646767 < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
2020-06-02 08:49:48.647206 > HCI Event: Command Complete (0x0e) plen 10
    Read BD ADDR (0x04|0x0009) ncmd 1
    status 0x00 bdaddr B8:27:EB:08:5F:F0
2020-06-02 08:49:48.654744 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.655164 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-06-02 08:49:48.655465 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x01 (active)
    interval 10.000ms window 10.000ms
    own address: 0x00 (Public) policy: All
2020-06-02 08:49:48.655928 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2020-06-02 08:49:48.669824 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.670225 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-06-02 08:49:48.670261 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x01 (active)
    interval 10.000ms window 10.000ms
    own address: 0x00 (Public) policy: All
2020-06-02 08:49:48.670716 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2020-06-02 08:49:48.670754 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
2020-06-02 08:49:48.671215 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2020-06-02 08:49:48.842103 > HCI Event: LE Meta Event (0x3e) plen 27
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr 9C:20:7B:BE:14:6E (Public)
      Flags: 0x1a
      Unknown type 0xff with 10 bytes data
      RSSI: -68
2020-06-02 08:49:48.842525 > HCI Event: LE Meta Event (0x3e) plen 12
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr 9C:20:7B:BE:14:6E (Public)
      RSSI: -68
2020-06-02 08:49:49.384917 > HCI Event: LE Meta Event (0x3e) plen 33
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr C4:64:E3:9B:04:44 (Public)
      Flags: 0x06
      Unknown type 0x06 with 16 bytes data
      RSSI: -95
2020-06-02 08:49:49.385781 > HCI Event: LE Meta Event (0x3e) plen 28
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr C4:64:E3:9B:04:44 (Public)
      Unknown type 0xff with 8 bytes data
      Shortened local name: '315X'
      RSSI: -95
2020-06-02 08:49:49.392478 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-02 08:49:49.394279 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2020-06-02 08:49:49.399822 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr C4:64:E3:9B:04:44 type 0
    interval 96 window 48 initiator_filter 0
    own_bdaddr_type 0 min_interval 6 max_interval 12
    latency 0 supervision_to 200 min_ce 4 max_ce 6
2020-06-02 08:49:49.400717 > HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
2020-06-02 08:49:59.914436 > HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 64, role master
      bdaddr C4:64:E3:9B:04:44 (Public)
2020-06-02 08:49:59.914783 < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2
  40 00 
2020-06-02 08:49:59.915700 > HCI Event: Command Status (0x0f) plen 4
    LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1
2020-06-02 08:50:00.205123 > HCI Event: LE Meta Event (0x3e) plen 12
    LE Read Remote Used Features Complete
      status 0x00 handle 64
      Features: 0x1d 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2020-06-02 08:50:00.211514 < ACL data: handle 64 flags 0x00 dlen 7
    ATT: MTU req (0x02)
      client rx mtu 256
2020-06-02 08:50:00.249993 > ACL data: handle 64 flags 0x02 dlen 7
    ATT: MTU resp (0x03)
      server rx mtu 65
2020-06-02 08:50:00.252698 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Group req (0x10)
      start 0x0001, end 0xffff
      type-uuid 0x2800
2020-06-02 08:50:00.295009 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-02 08:50:00.385200 > ACL data: handle 64 flags 0x02 dlen 18
    ATT: Read By Group resp (0x11)
      attr handle 0x0001, end group handle 0x0007
      value 0x00 0x18
      attr handle 0x0008, end group handle 0x0008
      value 0x01 0x18
2020-06-02 08:50:00.386993 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Group req (0x10)
      start 0x0009, end 0xffff
      type-uuid 0x2800
2020-06-02 08:50:00.460829 > ACL data: handle 64 flags 0x02 dlen 26
    ATT: Read By Group resp (0x11)
      attr handle 0x0009, end group handle 0xffff
      value 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x01 0x00 0xbd 0x98
2020-06-02 08:50:00.464756 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Type req (0x08)
      start 0x0009, end 0xffff
      type-uuid 0x2803
2020-06-02 08:50:00.490056 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-02 08:50:00.520226 > ACL data: handle 64 flags 0x02 dlen 27
2020-06-02 08:50:00.535226 > ACL data: handle 64 flags 0x01 dlen 27
2020-06-02 08:50:00.580143 > ACL data: handle 64 flags 0x01 dlen 15
    ATT: Read By Type resp (0x09)
      length: 21
        handle 0x000a, value 0x04 0x0b 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x02 0x00 0xbd 0x98 
        handle 0x000d, value 0x12 0x0e 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x03 0x00 0xbd 0x98 
        handle 0x0011, value 0x02 0x12 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x04 0x00 0xbd 0x98 
2020-06-02 08:50:00.582577 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Type req (0x08)
      start 0x0013, end 0xffff
      type-uuid 0x2803
2020-06-02 08:50:00.730061 > ACL data: handle 64 flags 0x02 dlen 9
    ATT: Error (0x01)
      Error: Attribute not found (10)
      Read By Type req (0x08) on handle 0x0013
2020-06-02 08:50:00.737443 < ACL data: handle 64 flags 0x00 dlen 7
    ATT: Read req (0x0a)
      handle 0x0012
2020-06-02 08:50:00.759998 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-02 08:50:00.760889 > ACL data: handle 64 flags 0x02 dlen 25
    ATT: Read resp (0x0b)
      41 75 74 6F 6D 6F 77 65 72 00 00 00 00 00 00 00 00 00 00 00 
2020-06-02 08:50:00.823478 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x2e 0x01 0x49 0x01 0x1f 0x8f 0x07 0x50 0x00 0x00 0x00 0x00 0x04 0x0d
2020-06-02 08:50:00.828900 < ACL data: handle 64 flags 0x00 dlen 14
    ATT: Write cmd (0x52)
      handle 0x000b value  0x61 0x69 0x06 0xe0 0x00 0xf0 0x03
2020-06-02 08:50:00.940081 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-02 08:50:01.294462 < ACL data: handle 64 flags 0x00 dlen 24
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x00 0xa0 0x00 0x91 0x1f 0x08 0xf7 0x05 0x00 0x7c 0x00 0x80 0x01 0x28 0x03
2020-06-02 08:50:01.562877 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 1
2020-06-02 08:50:01.774077 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x5a 0x12 0x00 0x20 0x00 0x00 0x00 0x02 0x30 0x03
2020-06-02 08:50:01.937876 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 1
2020-06-02 08:50:02.281245 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x38 0x12 0x00 0x20 0x00 0x00 0x00 0x08 0xe0 0x03
2020-06-02 08:50:02.562878 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 1
2020-06-02 08:50:02.773394 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x20 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x28 0x00 0x0a 0x0f 0x38 0x12 0x00 0x40 0x00 0x02 0x00 0x0d 0x20 0x04
2020-06-02 08:50:02.776651 < ACL data: handle 64 flags 0x00 dlen 9
    ATT: Write cmd (0x52)
      handle 0x000b value  0xee 0x03
2020-06-02 08:50:02.876322 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-02 08:50:03.284576 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0x38 0x12 0x00 0x30 0x00 0x00 0x00 0x00 0x10 0x03
2020-06-02 08:50:03.437917 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 1
2020-06-02 08:50:03.773593 < ACL data: handle 64 flags 0x00 dlen 32
    ATT: Write cmd (0x52)
      handle 0x000b value  0x02 0xfd 0x01 0x00 0x00 0x91 0x1f 0x08 0xf7 0x05 0x01 0x52 0x00 0x0a 0x0f 0xea 0x11 0x00 0x50 0x00 0x00 0x00 0x0e 0xc0 0x03
2020-06-02 08:50:03.937996 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 1

I've noticed that on iOs I've an encryption process which look like triggered automatically on connect :

a May 21 08:09:48.706  HCI Command      0x0041  315X               LE Start Encryption - Connection Handle: 0x0041

while on the Pi I only have a create connection :

2020-06-02 08:49:49.399822 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr C4:64:E3:9B:04:44 type 0
    interval 96 window 48 initiator_filter 0
    own_bdaddr_type 0 min_interval 6 max_interval 12
    latency 0 supervision_to 200 min_ce 4 max_ce 6

I've tried to manually pair the BLE device using bluetoothctl but look like the pairing isn't working :

pi@raspberrypi:~ $ bluetoothctl
Agent registered
[bluetooth]# connect C4:64:E3:9B:04:44
Attempting to connect to C4:64:E3:9B:04:44
[CHG] Device C4:64:E3:9B:04:44 Connected: yes
Connection successful
[NEW] Primary Service
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0008
        00001801-0000-1000-8000-00805f9b34fb
        Generic Attribute Profile
[NEW] Primary Service
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009
        98bd0001-0b0e-421a-84e5-ddbf75dc6de4
        Vendor specific
[NEW] Characteristic
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000a
        98bd0002-0b0e-421a-84e5-ddbf75dc6de4
        Vendor specific
[NEW] Descriptor
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000a/desc000c
        00002901-0000-1000-8000-00805f9b34fb
        Characteristic User Description
[NEW] Characteristic
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d
        98bd0003-0b0e-421a-84e5-ddbf75dc6de4
        Vendor specific
[NEW] Descriptor
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d/desc000f
        00002902-0000-1000-8000-00805f9b34fb
        Client Characteristic Configuration
[NEW] Descriptor
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char000d/desc0010
        00002901-0000-1000-8000-00805f9b34fb
        Characteristic User Description
[NEW] Characteristic
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char0011
        98bd0004-0b0e-421a-84e5-ddbf75dc6de4
        Vendor specific
[NEW] Descriptor
        /org/bluez/hci0/dev_C4_64_E3_9B_04_44/service0009/char0011/desc0013
        00002901-0000-1000-8000-00805f9b34fb
        Characteristic User Description
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device C4:64:E3:9B:04:44 UUIDs: 98bd0001-0b0e-421a-84e5-ddbf75dc6de4
[CHG] Device C4:64:E3:9B:04:44 ServicesResolved: yes
[315X]# pair C4:64:E3:9B:04:44
Attempting to pair with C4:64:E3:9B:04:44
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device C4:64:E3:9B:04:44 ServicesResolved: no
[CHG] Device C4:64:E3:9B:04:44 Connected: no

EDIT

Ok, it's look like the encryption process is being triggered when I try to subscribe to the notify characteristics but pairing fail :

2020-06-02 10:57:45.657381 > ACL data: handle 64 flags 0x02 dlen 9
    ATT: Error (0x01)
      Error: Insufficient authentication (5)
      Read By Type req (0x08) on handle 0x000f
2020-06-02 10:57:45.658692 < ACL data: handle 64 flags 0x00 dlen 11
    SMP: Pairing Request (0x01)
      capability 0x03 oob 0x00 auth req 0x01
      max key size 0x10 init key dist 0x00 resp key dist 0x01
      Capability: NoInputNoOutput (OOB data not present)
      Authentication: Bonding (No MITM Protection)
      Initiator Key Distribution:    
      Responder Key Distribution:  LTK  
2020-06-02 10:57:45.687326 > ACL data: handle 64 flags 0x02 dlen 6
    SMP: Pairing Failed (0x05)
      reason 0x05
      Reason Pairing Not Supported

I don't know how to solve this pairing issue

Edit 2

It look like this was a device issue which allow pairing inconsistently or is being activated via a specific gatt command, I'll dive deeper to figure out

node.js
raspberry-pi
bluetooth-lowenergy
asked on Stack Overflow Jun 2, 2020 by buildog • edited Jun 8, 2020 by buildog

1 Answer

0

This looks to be happening because pairing is not supported on the Raspberry Pi. You can resolve this through a combination of btmgmt and bluetoothctl commands:-

sudo btmgmt power off
sudo btmgmt discov on
sudo btmgmt connectable on
sudo btmgmt pairable on
sudo btmgmt power on

Also, according to your logs you have set the IO Capability to 0x03 (NoInputNoOutput). You can change this by launching bluetoothctl using:-

bluetoothctl --agent KeyboardDisplay

After that, you should be prompted to enter a passkey or accept incoming connection on the Raspberry Pi. You can play with all the different IO Capabilities to see which one works best for you. The commands for doing this are:-

bluetoothctl --agent DisplayOnly
bluetoothctl --agent DisplayYesNo
bluetoothctl --agent KeyboardOnly
bluetoothctl --agent NoInputNoOutput
bluetoothctl --agent KeyboardDisplay

More details can be found in the links below

I hope this helps.

answered on Stack Overflow Jun 7, 2020 by Youssif Saeed

User contributions licensed under CC BY-SA 3.0