takawata / FreeBSD-BLE

15 stars 9 forks source link

Pairing Elecom Bitra mouse fails #15

Open rhaberkorn opened 3 weeks ago

rhaberkorn commented 3 weeks ago

I have an Elecom Bitra trackball, that's apparently using BLE. Unfortunately, it does not pair:

# sudo le_enable
Password:
SET EVENT MASK0 0
LE_EVENT_MASK 0 0
READ_LE_BUFFER_SIZE 0 0 251 3
LOCAL SUPPOREDED:0 0 255
SCANTYPE0 INTERVAL18 ADDRTYPE0 WINDOW18 POLICY0
SCAN_PARAM 0 0 1
SEt SCAN RESPONSE 0 0 1
LE_STATUS:0 0 3ffffffffff
SCAN ENABLE0 0 1
START SCANNING
HOGEHOGE
SCAN_RESULT 3e c
Subevent  2
NumRecord 1
Eventtype 1
AddrType 1
Addr:[dc:ab:02:c4:e7:00]
length_data 0
DATA:
RSSI: b1 (-79 db)
SCAN ENABLE0 0 1
# sudo lepair dc:ab:02:c4:e7:00
connect: Operation now in progress
RECV Error
HCI_RECV: Operation timed out
^C

Do you have any idea, how this could be debugged?

rhaberkorn commented 3 weeks ago

I did make some progress. Turns out that le_enable is hardcoded for public addresses, while the device has random addresses instead. So I changed BDADDR_LE_PUBLIC to BDADDR_LE_RANDOM in le_enable/le_enable.c. Perhaps this could also be done via hccontrol LE_Connect?

# sudo le_enable/le_enable -s
Password:
SET EVENT MASK0 0
LE_EVENT_MASK 0 0
READ_LE_BUFFER_SIZE 0 0 251 3
LOCAL SUPPOREDED:0 0 255
SCANTYPE0 INTERVAL18 ADDRTYPE0 WINDOW18 POLICY0
SCAN_PARAM 0 0 1
SEt SCAN RESPONSE 0 0 1
LE_STATUS:0 0 3ffffffffff
SCAN ENABLE0 0 1
START SCANNING
HOGEHOGE
SCAN_RESULT 3e c
Subevent  2
NumRecord 1
Eventtype 1
AddrType 1
Addr:[dc:ab:02:c4:f7:00]
length_data 0
DATA:
RSSI: ce (-50 db)
SCAN ENABLE0 0 1
# sudo lepair/lepair -r dc:ab:02:c4:f7:00
connect: Operation now in progress
PIN:0 0
device{
        name "thisdevice";
        bdaddr dc:ab:02:c4:f7:00;
        addrtype lernd;
        ediv 0xc277;
        rand 0xdfeef5f6617134e9;
        key 0xc077fc8796c27f3d2bcedf943158d6b1;
        pin nopin;
}

So pairing worked. I then pasted the device-block into lesecd/hcsecd.conf and launched lesecd and lehid in separate consoles.

# cd lesecd
# sudo ./lesecd
SEND CRYPTO
# sudo lehid/lehid -r -s dc:ab:02:c4:f7:00
CONNECT
connect: Operation not permitted
CONNECTOK
no more rows available

There was apparently some kind of authentication taking place, but ultimately failing. Kernel log contains the entry encryption_change: ubt0hci - failed to change encryption mode, status=6. This is apparently from sys/netgraph/bluetooth/hci/ng_hci_evnt.c in the kernel.