IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.61k stars 490 forks source link

Passive scan returns different address type than active scan for BLE devices #262

Closed gcelosia closed 6 years ago

gcelosia commented 6 years ago

Hi,

First, thank you for your work. I really enjoy this Bluetooth python module and its simplicity of use.

Unfortunately, I've discovered that, with passive scan, a found BLE device doesn't have the same address type than if it is discovered during an active scan. I checked the scanned results with Wireshark and it seems that the problem comes from the bluepy python module as Wireshark detects the same device address type whether an active or a passive scan is triggered.

Actually, I'm using the original python code from scanner.py (available in bluepy/bluepy/scanner.py) and I just changed the lines:

To illustrate my issue, for instance, when I run an active scan (with scanner.scan(10.0)), I have the following : ... 11:22:33:44:55:66 random.... And, you would have understood it, when I run a passive scan (with scanner.scan(10.0,passive=True)), I have the following : ... 11:22:33:44:55:66 public...

So please, can you fix this little problem ? Or maybe I can help you to do this if you can show me the code part involved in this process of finding device address type ?

Thanks in advance.

G.C.

gandy92 commented 6 years ago

Hi,

you want to take a look at hci_monitor_cb() in bluepy-helper.c. I can try to look into this in the next few weeks, unless you'd like to debug it yourself.

Best, Andy.

gcelosia commented 6 years ago

Hi Andy,

Thanks for your answer. I quickly took a look at hci_monitor_cb() in bluepy-helper.c. It seems not very easy to understand. So it would be nice if you debug it yourself. I think that it will take me more time than you to do the same thing.

Don't hesitate to ping me if you need help, I will try to do my best :).

Cheers, G.C.

gandy92 commented 6 years ago

Hi, I committed a possible fix to https://github.com/gandy92/bluepy. Unfortunately I don't have any BLE devices advertising with random address, so I cannot test it. May I ask you to to verify the solution before I create a pull request? Cheers, Andy.

gcelosia commented 6 years ago

Andy,

I've just tried your fix with a BLE device which advertises with random address. I've the pleasure to announce you that it works well ! Both active and passive scans show that advertising address used is random for this device. Thank you really much for your good job :).

Cheers, G.C.

gandy92 commented 6 years ago

Great, thanks for the feedback. Cheers, Andy.