sputnikdev / eclipse-smarthome-bluetooth-binding

Eclipse SmartHome Bluetooth Binding
46 stars 10 forks source link

Add support for l2ping alike functionality as Low-Level Protocol presence detection #71

Open janlinders opened 5 years ago

janlinders commented 5 years ago

Bluez l2ping utility (device does not need to be in discovery mode as long as the MAC is known) I.e Now, lets see how the command responds when the Bluetooth ON

$ sudo l2ping 6C:C4:D5:6C:C5:BC Ping: 6C:C4:D5:6C:C5:BC from 70:1A:04:59:69:04 (data size 44) ... 44 bytes from 6C:C4:D5:6C:C5:BC id 0 time 5.93ms 44 bytes from 6C:C4:D5:6C:C5:BC id 1 time 8.76ms

Now, lets see how the command responds when the Bluetooth OFF

$ sudo l2ping 6C:C4:D5:6C:C5:BC Can't connect: Host is down

xrucka commented 5 years ago

Hi, this might not be realizable within the current architecture without adding middle layers. Speaking from experience on implementing bluez/dbus transport, bluez does not expose l2ping interface through dbus. Therefore, to perform l2ping, you need to actually call a seduid binary that can be bound to raw bluetooth socket + handle the way l2ping gets elevated priviledges.

Therefore, for practial use, I suggest to enable calling l2ping with sudoerrs and use - for example - exec binding or similar.

janlinders commented 5 years ago

Hi xrucka, thanks for the comment. I have the l2ping working through the Exec binding and it works fine. Having similar functionality available in the BT Binding would be much cleaner i guess without sudoers etc. However if that is becoming to complex, forget the requests. KR

vkolotov commented 5 years ago

Hi @janlinders, could you please elaborate what phone you are using? As far as I know, the l2ping utility is used for older BT devices (prior BT 4.0), new devices that support BT 4.0 won't be able to respond for l2ping. It would be great if they could. Please confirm.

Also could you please let us know what is rationale not to have discoverable mode enabled on your phone? Is this to achieve privacy?

janlinders commented 5 years ago

Hi Vlad, thanks for your reply.

The phones I have available are Huawei P7-L10 Android 5.1.1 kernel 3.0.8-00595-gc29cecf IPhone 5S ios 12.0.1 Also my television has BT onboard : [LG] webOS TV OLED55E6V

All 3 are giving response using l2ping with their respective BT MAC addresses.

Don't know what BT versions these run. I will see if I can find this. Discoverable on means indeed privacy issue and power usage.

I have openhab2 v 2.3 (openhabian) installed on an Raspberry PI Model 2 B+

BT USB dongle : CSR8510 A10

Bluez :● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2018-11-19 20:24:26 CET; 1s ago Docs: man:bluetoothd(8) Main PID: 21628 (bluetoothd) Status: "Running" CGroup: /system.slice/bluetooth.service └─21628 /usr/libexec/bluetooth/bluetoothd Nov 19 20:24:26 openHABianPi bluetoothd[21628]: Bluetooth daemon 5.47 Nov 19 20:24:26 openHABianPi bluetoothd[21628]: Starting SDP server Nov 19 20:24:27 openHABianPi bluetoothd[21628]: Bluetooth management interface 1.14 initialized

KR, Jan

On Mon, Nov 19, 2018 at 7:51 PM Vlad Kolotov notifications@github.com wrote:

Hi @janlinders https://github.com/janlinders, could you please elaborate what phone you are using? As far as I know, the l2ping utility is used for older BT devices (prior BT 4.0), new devices that support BT 4.0 won't be able to respond for l2ping. It would be great if they could. Please confirm.

Also could you please let us know what is rationale not to have discoverable mode enabled on your phone? Is this to achieve privacy?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440001370, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X0CjDtXFWYY9HYJRJXFjBUC0gVVzks5uwv2ZgaJpZM4Yo9F6 .

janlinders commented 5 years ago

Found I think the BT versions of the phones.

Huawei P10 BT 4.2, A2DP, LE, aptX iPhone 5s - BT 4.0 A2DP

On Mon, Nov 19, 2018 at 7:51 PM Vlad Kolotov notifications@github.com wrote:

Hi @janlinders https://github.com/janlinders, could you please elaborate what phone you are using? As far as I know, the l2ping utility is used for older BT devices (prior BT 4.0), new devices that support BT 4.0 won't be able to respond for l2ping. It would be great if they could. Please confirm.

Also could you please let us know what is rationale not to have discoverable mode enabled on your phone? Is this to achieve privacy?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440001370, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X0CjDtXFWYY9HYJRJXFjBUC0gVVzks5uwv2ZgaJpZM4Yo9F6 .

vkolotov commented 5 years ago

Very interesting. Are you saying that even if your phones are not in discoverable mode (make sure you close BT settings and leave it for 2-3 mins), you still can ping them via l2ping?

janlinders commented 5 years ago

Confirmed.

On Mon, Nov 19, 2018 at 8:41 PM Vlad Kolotov notifications@github.com wrote:

Very interesting. Are you saying that even if your phones are not in discoverable mode (make sure you close BT settings and leave it for 2-3 mins), you still can ping them via l2ping?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440017166, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X1XJ513r9iH2YS_12DvMli6rC-Lpks5uwwlmgaJpZM4Yo9F6 .

vkolotov commented 5 years ago

Very good, thank you. As @xrucka mentioned earlier, that would not be very easy to add support for.

What is rationale not to enable/(force to be enabled) discoverable mode in your devices? Privacy/security?

vkolotov commented 5 years ago

And yeah, just double checking. Do you mobile phones have fixed/static MAC address when in discoverable mode or they change it every so often?

janlinders commented 5 years ago

Thx.

I'm aware of the tools from the AppStore / PlayStore to force enable discoverable mode That means indeed Privacy/Security concerns if I have that on all the time. So even when from home (anywhere else) people can see the device and it's vulnerable for attacks.

KR

On Mon, Nov 19, 2018 at 9:20 PM Vlad Kolotov notifications@github.com wrote:

Very good, thank you. As @xrucka https://github.com/xrucka mentioned earlier, that would not be very easy to add support for.

What is rationale not to enable/(force to be enabled) discoverable mode in your devices? Privacy/security?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440028815, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X3i8ye-_1dClfVUmcXfLf3zoDJ-aks5uwxKdgaJpZM4Yo9F6 .

janlinders commented 5 years ago

what i noticed using bluetoothctl (after switching the devices to discover mode and bluetoothctl scan on) is that they have fixed MAC addresses.

On Mon, Nov 19, 2018 at 9:29 PM Vlad Kolotov notifications@github.com wrote:

And yeah, just double checking. Do you mobile phones have fixed/static MAC address when in discoverable mode or they change it every so often?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440031361, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X8t57H8lLYKcwuEhdXz-m0FVQFacks5uwxTHgaJpZM4Yo9F6 .

vkolotov commented 5 years ago

Right, that's the thing. This is quite unusual for new phones if they have static mac addresses. I'll try to ping my devices to see if it is possible, but I doubt it is... If it is possible, then we might have a good way to track presence, although that would be quite difficult to add support for. Furthermore, looks like bluegiga adapters do not support it at all.

janlinders commented 5 years ago

Understood.

Simple to test :

!/bin/sh

sudo /usr/bin/l2ping -c5 XX:XX:XX:XX:XX:XX >/dev/null 2>&1

if [ $? -eq 0 ] then echo HOME else echo AWAY fi

On Mon, Nov 19, 2018 at 9:41 PM Vlad Kolotov notifications@github.com wrote:

Right, that's the thing. This is quite unusual for new phones if they have static mac addresses. I'll try to ping my devices to see if it is possible, but I doubt it is... If it is possible, then we might have a good way to track presence, although that would be quite difficult to add support for. Furthermore, looks like bluegiga adapters do not support it at all.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/issues/71#issuecomment-440034502, or mute the thread https://github.com/notifications/unsubscribe-auth/ArE5X8mzhvDrYMWtNBCIdZ-daT2bTkvCks5uwxdjgaJpZM4Yo9F6 .