Bluetooth-Devices / bthome-ble

Parser for BTHome BLE devices
https://bthome.io/
MIT License
69 stars 14 forks source link

Incorrect description of the Advertising Packet format. #32

Closed pvvx closed 1 year ago

pvvx commented 1 year ago

https://bthome.io/format/ contains an incorrect description of the Advertising Packet format.

Core Specification 5.3

image

image

https://novelbits.io/bluetooth-low-energy-advertisements-part-1/

image

What is indicated in https://bthome.io/format/ most likely refers to some HCI implementation?

We assume that you understand the basics of BLE advertisements (if not, read this). -> For ease of use, Bluetooth defines a single packet format for both advertising and data transmissions. This packet consist of four components: preamble (1 octet), access address (4 octets), Protocol Data Unit – PDU (2-257 octets), and Cyclic Redundancy Check – CRC (3 octets);

Ernst79 commented 1 year ago

Thanks, yes, I still use the HCI format, as we use that in BLE monitor (by using aioblescan). But given your info, this is not the way it is actually being send. I will fix the documentation, but there is one thing I don't understand (yet). An HCI message looks like the following (example of an xiaomi sensor).

-----------------------------------------------------------------------------------------------------------------------------------------------------------
HCI  Evt Len Sub Num Evt  Peer -------MAC-------   Len Len Type Val Len  AD  Xiaomi Frame Product Frame ------MAC--------   -----PAYLOAD-------------  RSSI
type code    evt rep type addr                             flag         type  UUID   ctrl   ID    cnt                      Type  Len  Temp   Hum   Batt
 A    B  C    D  E    F    G          H            I   J    K   L   M    N     O      P     Q      R           S            T     U    V      W     X   Y
-----------------------------------------------------------------------------------------------------------------------------------------------------------
 04   3e 25  02  01   00   00  9b b8 dd a8 65 4c   19  02   01  06  15   16  95 fe  50 20  aa 01   fe   9b b8 dd a8 65 4c   0d 10 04  b2 00  75 02      cb

In the example,

But where can I find the byte with the PDU Type, RFU, ChSel, TxAdd (first byte from the PDU)?

Ernst79 commented 1 year ago

Created a attempt to change the format explanation in this PR

https://github.com/home-assistant/bthome.io/pull/27

pvvx commented 1 year ago

The reason for creating the question is that it is being asked to me, because. people do not understand what kind of "package" this is and how to form it in their devices :) I think that it is possible to leave the description of only the PDU of the part, and if the rest is indicated, then as an example of obtaining data in a specific implementation.

PS: as I understand it, this is a set of several HCI requests to the adapter.

Ernst79 commented 1 year ago

Yes, i understand. The PR now only describes the PDU payload. I removed the other parts.