[web-bluetooth] Wrong handling of property 'name' of Bluetooth devices (#570)

Z80sp has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== Wrong handling of property 'name' of Bluetooth devices  ==
Hi team,

I currently get troubles interacting with a BLE device from which advertisement data is dynamic.
It runs a scenario where the AD structure LOCAL NAME (AD_TYPE 0x09) needs to update regularly its raw binary content.

Here are the 2 issues encountered:

1) Web BLE API assumes LOCAL_NAME to be a NULL terminated string whereas the BLE specifications clearly don't.
   An AD structure looks like this :   (1)[LENGTH] + (LENGTH)[ (N)[AD_TYPE] + (LENGTH-N)[AD_DATA] ]
   For an AD structure of type LOCAL_NAME containing 4 bytes :  (1)[0x05] (5)[ (1)[0x09] + (4)[0x00 0x01 0x02 0x03]  ]
   ==> Final byte sequence is : (6)[ 0x05 0x09 0x00 0x01 0x02 0x03 ]

   But in such case Web BLE API returns a 0 byte long name instead of 4 bytes long string "\x00\x01\x02\x03"
   Whatever bytes are non ASCII nor displayable, the AD length byte is the only reliable data telling how long the local name is and since it's allowed to pass raw binary data there, null byte should not be interpreted as 'end of string'.


 2) BluetoothDevice.name always contains the same value while the device dynamically updates advertised data.
   Even using watchAdvertisements() and event 'advertisementreceived', property 'name' remains the same. It seems the value 
   is cached at pairing stage then never updated anymore where it should.
   


Case 1) is trivial to experiment : just introduce a null byte in LOCAL_NAME AD structure of any advertising BLE device...
Case 2) is easily verified trhrough this demo page:  https://googlechrome.github.io/samples/web-bluetooth/watch-advertisements.html


Best Regards,


Phil



Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/570 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 10 December 2021 17:29:50 UTC