Generally speaking, we call the implementation code of a certain protocol a protocol stack. The Bluetooth protocol stack is the code that implements the low-power Bluetooth protocol. Understanding and mastering the Bluetooth protocol is a prerequisite for implementing the Bluetooth protocol stack. The Bluetooth protocol stack is divided into: usage layer, main protocol layer, and control layer.
1. Control layer
PHY: Physical layer, mainly responsible for specifying the wireless frequency band of BLE, modulation and demodulation methods and methods, etc. Directly determines the power consumption sensitivity of the BLE chip.
LL: Link layer (protocol stack center), this layer is the RF controller, used to control the radio frequency state of the device. The controlled device will be in one of five states: standby (preparation), advertising (broadcast), scanning (monitoring/ Scanning), initiating (recommended connection), connected (already connected). The switching of the five states is described as: advertising (broadcasting) can send data without a connection (tell everyone, I am here);
Scanning (monitoring/scanning) data from the broadcast; the initiator (initiator) will respond to the broadcaster with a connection request (connection request). If the advertiser (broadcaster) agrees to the request, then the broadcaster and the initiator will enter the connected state. In this case, the device recommended for connection becomes master (host), and the device receiving the connection request becomes slave (slave).
HCI: Host control interface (optional), standard communication protocol and communication instructions between two chips. This layer can be implemented through software API or hardware interfaces, such as UART, SPI, USB.
2.main protocol layer
GAP: Generic Access Profile: It is an interface that communicates directly with applications or profiles, handles device discovery and connection-related services, and also handles the initialization of security features. Provide application program interfaces to superiors, and manage intelligent departments at all levels to superiors, especially instructing the LL layer controller to switch between 5 states. GAP is currently mainly used for broadcasting, scanning and initiating connections.
L2CAP: Logical link control and adaptation protocol, which encapsulates LL. The LL layer distinguishes the transmission data itself. L2CAP cares about whether it is an encrypted channel or a normal channel and manages the connection distance.
SMP: Secure Management Protocol, handles BLE encryption and security. Pairing and key distribution methods are defined. And provide services for secure connections and exchange of data between other layers of the protocol stack and other devices.
ATT: Attribute protocol, which defines user instructions and data variables for instruction operations. ATT is used to describe a piece of data.
GATT: General Attribute Protocol Layer, which allows devices to present a specific piece of data to other devices, called an “attribute”. In the ATT environment, the device that exhibits “features” is called the server, and the device paired with it is called the client. The link layer status (master and slave) and the device’s ATT character are independent of each other. For example, the host device can be either an ATT server or an ATT client. The slave device can be an ATT client or an ATT server.
3. Use layers
Including public tasks defined by the SIG Bluetooth protocol group and private tasks defined by users.Keywords: 16-channel IO control