noble / node-bluetooth-hci-socket

MIT License
154 stars 188 forks source link

Fix packet reassembly #16

Closed Loghorn closed 8 years ago

sandeepmistry commented 8 years ago

@Loghorn thanks for submitting!

I understand the changes, just curious as to what type of setup you were seeing the issues with? (USB adapter, peripheral used etc)

Loghorn commented 8 years ago

I found the issue with a USB adapter. While debugging I found that the packets were correct at first, then became misaligned, so I implemented this fix. However, after testing it, I found that the problem was that some packet from the USB were missing and this caused the actual misalignment (I suspect there is an issue with the USB controller, because using the same adapter in another port works fine). Anyway, I thought that sending the PR with the fix was worth it, in case someone has a USB adapter that sends data in odd ways :smile:

bragma commented 8 years ago

@sandeepmistry I've seen this issue on a linux embedded device using an external USB Bluetooth dongle. The old reassembly code expected HCI events data to terminate in mid of packet or at the exact end of a packet. It's a weak assumption, since lower lever reassembly can cause 2 packets to be merged in a single HCI event data buffer. If it happens, the entire stream reassembly is broken forever. The hardware I've seen it happen is an RK3288 ARM device.

sandeepmistry commented 8 years ago

@Loghorn thanks!

sandeepmistry commented 8 years ago

@bragma were you using node-hci-socket is USB mode? By default on Linux is uses kernel mode, and does not use the file @Loghorn modified.

bragma commented 8 years ago

@sandeepmistry yes I was forcing USB mode because I needed to test an external USB BT Dongle without kernel driver support.

sandeepmistry commented 8 years ago

@bragma ok, let us know if this change helps :)