An Overview of the BLE Protocol Stack (Part 1)

The BLE protocol stack is mainly divided into three layers: the application layer, the host layer, and the controller layer. Many people are likely familiar with this diagram.An Overview of the BLE Protocol Stack (Part 1)The application layer mainly consists of various applications with BLE functionality. The host layer provides various protocols and profiles for BLE communication, while also offering API interfaces for communication between the application layer and the controller layer. The controller layer is primarily hardware-related, essentially concerning the BLE chip. It is mainly responsible for the transmission and reception of wireless data, modulation, and demodulation.In this article, we will first discuss the host layer of BLE. From the diagram above, we can see that the host layer mainly includes the following levels:

  • GAP – (Generic Access Profile)
  • GATT – (Generic Attribute Profile)
  • ATT – (Attribute Protocol)
  • SMP – (Security Manager Protocol)
  • L2CAP – (Logical Link Control and Adaptation Protocol)
  • HCI – (Host Controller Interface) – host side

Although I am not sure why they have such convoluted names, sometimes profile and sometimes protocol, this is how the protocol is defined. Let’s take a look at the functions of each layer.We will not discuss HCI here; it is essentially a UART communication interface used for communication between the host and the controller.

  • L2CAP – (Logical Link Control and Adaptation Protocol)

L2CAP mainly serves the purposes of multiplexing, segmentation and reassembly of data, PDU data adaptation, and supporting signaling and connection control.Multiplexing refers to the ability to carry multiple different upper-layer protocols over the same physical link, distinguished by CID. Additionally, the L2CAP layer can also add its own signaling to establish, configure, and release physical channels.An Overview of the BLE Protocol Stack (Part 1)The L2CAP layer also has its own encapsulation format, which mainly adds length, code, and CID.An Overview of the BLE Protocol Stack (Part 1)

  • SMP – (Security Manager Protocol)

The main functions of SMP include:

  • Pairing, which establishes a security mechanism for generating and sharing keys between two BLE devices.
  • Key distribution, which involves distributing and storing security keys between devices after successful pairing.
  • Encryption and authentication, which triggers link layer encryption, with the actual encryption performed at the link layer.
  • Privacy protection, which supports periodic changes of Bluetooth addresses.
  • Security level management, such as whether encryption is enabled, whether devices are paired, and whether they are bonded.
  • ATT – (Attribute Protocol)

The ATT layer provides a unified “attribute data access mechanism” for BLE, enabling read and write operations between clients and servers.In BLE, all data is abstracted as attributes. The structure of an attribute is as follows:An Overview of the BLE Protocol Stack (Part 1)ATT provides standard methods for reading and writing these attributes.ATT is a typical client-server architecture. For example, a Bluetooth heart rate monitor can act as a server storing heart rate and temperature data, while a smartphone can act as a client to read and manipulate this data. The way to read and manipulate this data is defined by the ATT layer.The ATT layer defines six types of PDU, including request, response, command, confirmation, notification, and indication. The PDU packet format is as follows:An Overview of the BLE Protocol Stack (Part 1)The interaction relationship of these PDU types between the client and server is as follows:An Overview of the BLE Protocol Stack (Part 1)

  • GATT – (Generic Attribute Profile)

GATT utilizes the attribute mechanism provided by the ATT layer to organize all attributes into a higher-level structure:

  • Service: a collection of attributes that are functionally related, such as the heart rate service of a Bluetooth heart rate monitor.
  • Characteristic: specific data within a service, such as the value of the heart rate.
  • Descriptor: additional descriptive information about a characteristic, such as the unit and range of the heart rate.

At the GATT layer, BLE SIG has also defined a large number of standard services, such as heart rate service, battery service, blood pressure service, etc. Different manufacturers can communicate directly as long as they adhere to the GATT definitions.

  • GAP – (Generic Access Profile)

GAP mainly provides a framework for communication between BLE devices, which includes the following content:

  • Modes and roles of BLE devices.
  • Broadcasting (including advertising, scanning, and their respective parameters and data).
  • Establishing connections (initiating, connection parameters, etc.).
  • Security.

In simple terms, GAP = device discovery + broadcasting/scanning + connection establishment + basic security functions.An important aspect of GAP is determining the roles of BLE devices, which can be divided into connection mode and non-connection mode.In non-connection mode, devices are mainly divided into broadcasters and observers, where the broadcaster only sends data and does not receive data, while the observer only receives data and does not send data.An Overview of the BLE Protocol Stack (Part 1)When two devices are in a connected state, they are divided into centrals and peripherals. Peripherals are similar to broadcasters, initiating broadcasts, but they also receive connection requests. Centrals are similar to observers, but they also initiate connection requests.An Overview of the BLE Protocol Stack (Part 1)A device can be both a central and a peripheral, such as a typical smartphone.An Overview of the BLE Protocol Stack (Part 1)Through the host and controller layers, two Bluetooth devices can communicate normally.An Overview of the BLE Protocol Stack (Part 1)In summary:

  • GAP addresses the issue of how devices discover and connect.
  • GATT addresses the interoperability of data.
  • ATT addresses the unified method of data access.
  • SMP addresses communication security and identity authentication.
  • L2CAP addresses how upper-layer protocols share the underlying link layer.

That’s all!

Leave a Comment