Table Of Contents
Introduction
Bluetooth Low Energy (BLE) is a wireless technology used by several projects applications: Internet of Things (IoT), health care (measuring heart rate ), smart cities and domotic home technologies. For IoT devices, BLE presents many advantages in performance metrics such as ensuring very low power consumption, reliability, BLE can support communication with different mobile devices iOS, android, blackberry, as well as Linux, Mac OS, and Windows operating systems. In this post, we will describe different packets upcoming from peripheral and central devices to understand how BLE Protocol works.
Bluetooth Low Energy Advertising Packets
On one side, when a BLE peripheral device is turned on, it will periodically send Broadcast packets on specific advertising channels 37, 38, 39 (2402MHz, 2426MHz, 2480MHz respectively) (Bluetooth Low Energy has 40 channels in the ISM band «2.4GHz» spaced with 2MHz frequency for communication) to indicate to other central devices that it is up and ready to receive connections, and on the other side, central devices are listening into those specific channels for upcoming future connection and need only to scan those 3 channels. During the advertising phase, there is a time interval between each packet sent. We call it the BLE Advertising Interval. He is one of the numerical values used to configure the advertising parameters :
|
|
BLE technology is designed following the concept of layers, Bluetooth Low Energy Link Layer is in charge of sending advertising packets and establishing connections between devices. BLE LL has 2 type of PDU in only one format packet, advertising channel packets, and data channel packets. The choice of the type of packets depends on the channels used for transmission.
- Advertising channel: for advertising and discovering central devices without prior connection state. Advertising uses channels 37, 38 and 39.
- Data channel: after establishing the connection Data Channel packets are transmitted between the two devices. Data channel uses channels from 0 to 36 included.
The figure above shows a capture with Wireshark of an advertising packet from a peripheral device. The packet has the following attributes :
- Access Address: 4 bytes length, configured with the default hex value 0x8E89BED6 and used to identify the radio communication on the physical link.
- Packet (or advertising) Header has the following attributes :
- PDU type: to describe the advertising channel type. ADV_IND means the device is connectable with undirected advertising. The PDU type ADV_IND give the possibility to the peripheral device to be in mode discoverable when he wants another unspecific master device to initiate a connection.
- RFU: reserved for future uses.
- TxAddr: it can take 4 values depending on the type of the MAC address configured in the GAP parameters :
|
|
- Adv. Address: MAC address fixed to 6 bytes length of the device ( we can change the Mac address with a random one )
- Adv. Data: for GAP configuration :
- Appearance: defines the external appearance of the device. Like GENERIC_PHONE, GENERIC_WATCH or Unknown or unspecified appearance type.
|
|
- Flags: choose between Bluetooth radio chipsets mode, « BR/EDR » mode for Basic Rate/Enhanced Data Rate and/or « LE » mode for Low Energy.
|
|
- 128-bit Service Class UUIDs: the peripheral devices known as GATT server holds objects called Services that contain specific data called Characteristics. Each service has a unique numeric identifier called UUID to distinguish between Services which can be 16-bit (2 bytes) or 128-bit (16 bytes) length.
|
|
Bluetooth Low Energy Scan Request and Scan Response Packets
After broadcasting useful data during the advertising event, the central devices (Phones and tablets) keep request additional data from the peripheral device with the Scan Request packet, then the peripheral then replies with the Scan Response Packet.
Bluetooth Low Energy Connect Request Packet
The Central device, « the initiator », sends the packet Connect_Req to a device with the connectable and discoverable mode to establish a connection link. This packet contains all the required data needed for the future connection between the two devices.
The data transmitted in the Link Layer Data represents the new connection setup :
- Access Address: new 4 bytes value different from the default Access Address mentioned in the advertising phase. This new address has been generated randomly by the central device, not a fixed address like in advertising PDU.
- CRC Init: initialization value of CRC.
- Window size and offset: the window size and offset fields represent the timing for the first data packet and the transmit window start respectively.
- Latency: define the Slave « peripheral device » latency, to save power on the device. We can define the number of time the slave can skip some connection events when there is no data.
- Channel Map: which RF channels will be used and which will not be used. «
0xff ff ff ff 1f
» means we can use channels from 1 to 36 dedicated to Data. - Hop: the Random number used as a parameter in an algorithm to calculate unmapped channels of the current connection event.
Note that these initial connection parameters are set up by the central device, but the peripheral can do an update to the connection parameters to change them :
|
|
Bluetooth Low Energy Data Channel Packet
We can recognize 3 type of Data Channel Packet by LLID ( Link Layer ID ) one of the components of the PDU Header :
Note that the new Access Address ( 0xbc75ca22
) used is the one generated by the central device.
Type 1 « LLID == 0x01»: called Empty PDU and also known as acknowledges packet, if the peripheral device has «
0x1
» ( our case ) as value, he will reply to every connection event packet sent from the Central device at every connection interval. The type LLID0x1
may signify whether it is an empty PDU or it is a continuation fragment of L2CAP packets.Type 2 « LLID == 0x02»: called Data PDU, In addition to Bluetooth Low Energy Link Layer, there are two other higher protocol Layers added, L2CAP and Security Manager Protocol. The L2CAP plays the role of support of a higher level protocol multiplexing over the same physical link. With L2CAP we can assign to SMP ( Security Manager protocol ) and ATT ( Attribute protocol ) a fixed logical channel CID -
0x0006
for SMP and0x0004
for ATT -.Type 3 « LLID == 0x03 »: called LL Control PDU to control the link layer connection. The payload of the PDU consists of:
- Opcode: 1-byte length, LL_FEATURE_REQ for features set up by the master’s Link Layer.
- Control data: feature Set is specified by the opcode LL_FEATURE_REQ, in our example, the LE Encryption will be established if the LL_FEATURE_RSP from the peripheral will agree.
Security Manager Protocol
The SMP resides on top of L2CAP to implement the security features between devices, by setting the secure connection flag, the MITM ( Man-In-The-Middle) flag, the Bonding flag, generate encryption keys, identity keys and handle the key distribution process in the pairing mode.
|
|
Attribute Protocol
The ATT protocol is based on client server communication, each device has its data organized in the form of attributes.
The client sends the Read By Type Request to obtain the attribute handler between the Starting Handle 0x0001
and the Ending Handle 0X009
:
The server replies with Read By Type Response with contains the attribute data handles, characteristic handles and UUID’s:
Conclusion
The following figure emphasizes the role of each BLE device, from the process of Advertising to establishing the connection.