Definition
The Link Layer is the part of a Bluetooth Low Energy (BLE) §7.1 device that runs the radio protocol: it decides when the device transmits and listens, on which radio channel, and what happens to each packet that arrives. It sits in the Controller, the lower part of a BLE device that contains the radio, below the Host, the upper part that runs the higher protocols and the applications. It sets up connections, schedules every exchange, and checks, acknowledges, resends and encrypts packets. The Bluetooth Core Specification defines it.
The idea
Radio is unreliable: interference corrupts or destroys packets, a packet can arrive twice, and many other devices share the frequencies. A battery-powered device also cannot keep its receiver on, so the two ends of a link must agree exactly when they will next talk. During a connection, a device must start its reply a fixed time, normally 150 microseconds, after the other device’s packet ends, far too soon for application software to take part. The Link Layer does this work inside the Controller and offers the Host a simpler service: for each connection, intact data packets in their original order without duplicates, plus notices such as “connection lost”.
A mailroom is a fair picture. It signs for envelopes, throws away damaged ones and duplicate copies, and asks senders to send again; only intact, new envelopes go upstairs, and the office never learns what was thrown away. The picture fails in one respect: the mailroom’s signature, like a Link Layer acknowledgment, means only that the mailroom has the envelope, not that anyone upstairs has read it. So by the time any Host software, and therefore any application policy code, sees an event, the Link Layer has already made decisions about it and spent radio time, energy and memory on it.
How it works
Channels and states. BLE divides the 2.4-gigahertz band into 40 radio channels: 3 for advertising, the short broadcasts with which devices announce themselves and set up connections, and 37 for the data of connections. The specification describes the Link Layer as a state machine §8.33 whose main states are Standby (idle), Advertising (sending advertisements), Scanning (listening for them), Initiating (sending a connection request) and Connection. In a connection, the device that sent the request is the central and the other device is the peripheral.
The packet. On the 1-megabit and 2-megabit radio modes, a packet carries a preamble of 1 or 2 bytes respectively, which lets the receiver lock on to the signal; a 4-byte access address, which on a connection is a random value chosen for that connection; a 2-byte header; a payload of up to 251 bytes; on an encrypted connection, if the payload is not empty, a 4-byte MIC (message integrity §1.9 check), a tag computed with the session key that reveals a change to the payload; and a 3-byte CRC §4.32 (cyclic redundancy check), an error-detecting code computed over header, payload and MIC. The header holds, among other fields, a length field, which counts the bytes of the payload and of the MIC when one is present, a 1-bit sequence number SN, a 1-bit next expected sequence number NESN, a more-data bit, and a field LLID that marks the payload as a Link Layer control message or as Host data. The MIC also covers the payload length and LLID, but not SN, NESN or the more-data bit.
Decisions on each received packet, in this order, before any Host software sees it:
Heard or not. Both devices compute the channel of each connection event, the burst of exchanges that starts once every connection interval §7.7, from a shared hopping rule. A packet sent at another time or on another channel is never received.
Access address. A packet with another link’s access address is ignored.
CRC. A packet whose CRC does not match is discarded and not acknowledged, so the sender sends it again.
New or repeated. If
SNis not the sequence number expected next, the packet is a repeat and is discarded. A new packet is accepted unless the receive buffer is full; then it is left unacknowledged and the sender must resend it later, which is the Link Layer’s flow control.Its own last packet.
NESNtells the receiver whether its own last packet arrived; if not, the receiver sends that packet again.Decryption. On an encrypted connection, a packet that fails the MIC check makes the Link Layer consider the connection lost at once. Its Host learns only that the connection was terminated because of a MIC failure, and the peer, which is not told, notices only through its supervision timeout §7.8.
Control or data. The Link Layer handles control messages itself: changes of connection interval, of the channels in use or of radio mode, the start of encryption, the exchange of supported features, and termination. Only data goes up to the Host.
Supervision. Each valid packet restarts a timer; if none arrives for the supervision timeout, the Link Layer declares the connection lost.
Other decisions. Before a connection exists, the Host can tell an advertising device to drop scan and connection requests from addresses that are not on its Filter Accept List, the specification’s name for a list of allowed devices; the Host never hears of the dropped requests. A few decisions need the Host: when encryption starts, the peripheral’s Controller asks its Host, through the HCI §7.5 (Host Controller Interface), for the long-term key §7.28 from an earlier pairing §7.17, and the Host supplies it or refuses. Above the Link Layer, L2CAP §7.15 (Logical Link Control and Adaptation Protocol) joins the pieces of each message and checks its length, and ATT §7.9 (Attribute Protocol) checks that the addressed attribute exists and that the link’s security satisfies its permissions. Only then does GATT §7.10 (Generic Attribute Profile) call the application’s handler.
Worked example
A central C and a peripheral P have just connected. Each keeps two 1-bit counters, both 0 at the start: , the sequence number of the packet it is trying to deliver, and , the sequence number it expects next. Every packet carries its sender’s as SN and its sender’s as NESN. For a packet that passes the CRC check, the receiver applies two rules. If SN equals its own , the packet is new: accept it and flip . If NESN differs from its own , its own packet was delivered: flip and move on to a new packet; otherwise send the current packet (again).
C sends packet A:
SN0,NESN0. At P,SN0 equals P’s , so P accepts A and sets .NESN0 equals P’s , so P sends its current packet, an empty one.P sends
SN0,NESN1. At C,NESN1 differs from C’s : A was delivered, and C sets .SN0 equals C’s , so C sets .C sends packet B:
SN1,NESN1. Interference corrupts it, P’s CRC check fails, and P discards B and changes nothing.P must still answer the central. Unable to read B’s
NESN, P sends its empty packet again:SN0,NESN1. At C,NESN1 equals C’s , so B was not delivered.SN0 differs from C’s , so the empty packet is a repeat, and C discards it.C sends B again, unchanged. At P the CRC matches;
SN1 equals P’s , so P accepts B and sets ;NESN1 differs from P’s , so P sets .
P’s Host received A and B once each and never learned that B was corrupted. The radio paid for the repair. Suppose B is an unencrypted packet with a 27-byte payload, sent on the 1-megabit radio mode (1 million bits per second). It is bytes, or bits, which take 296 s. B cost s of air time for one delivery, and the repeated empty packet of bytes another 80 s, all invisible above the Link Layer.
Stated precisely
For one connection, the Link Layer gives the Host this contract, provided both Link Layers follow the specification:
Order and uniqueness. Data packets reach the receiving Host in the order sent, each at most once. One-bit sequence numbers suffice because each side has at most one unacknowledged packet in flight.
Noise. The CRC uses the 24-bit generator polynomial . It detects every error burst of at most 24 bits and misses a random corruption with probability about , roughly 1 in 16.8 million.
Attackers. The CRC gives no protection, because anyone can compute it. On an encrypted connection, a packet whose payload was altered or forged without the session key fails the MIC check, except with probability about per attempt, and because each packet’s encryption includes a packet counter, an old packet sent again fails it too. This holds only while the attacker does not know the session key, which depends on how pairing created the keys. The MIC does not protect empty packets, which carry none, or the
SN,NESNand more-data bits. An attacker can therefore change those bits or send empty packets of its own, including forged acknowledgments; that can delay or drop data, or end the connection, but cannot change the data that reaches the Host.Acknowledgment. An acknowledged packet is in the receive buffer of the peer’s Link Layer, unless an attacker forged the acknowledgment. Nothing more is promised.
No deadline. A packet is resent until it is acknowledged or the connection is lost; then unacknowledged packets are dropped.
Limits and common mistakes
A Link Layer acknowledgment is not an application acknowledgment. The peer’s Host or application may still discard or reject the packet, and the peer may lose power before acting on it.
Application policy code cannot see what the Link Layer dropped or handled itself: corrupted packets, repeats, filtered requests, and control procedures such as a change of connection interval. A policy enforced in an application handler covers only the operations that reach that handler.
Rejection is not free. A packet that the application rejects has already used air time, energy, buffers and processor time, so a peer whose every request is refused can still consume these resources, a form of denial of service §1.28.
The CRC is not a security check. The access address and the starting value of the CRC travel unencrypted in the connection request, so an eavesdropper on that request can forge packets that pass both checks. Only encryption with a MIC stops this, and only for packets with a payload: an empty packet carries no MIC, so a forged empty packet is still accepted.
The Link Layer does not decide who the peer is. Pairing, run by the Security Manager Protocol §7.19 in the Host, creates the keys, and the Link Layer uses whatever key the Host supplies. Nor can the Link Layer stop jamming, deliberate radio noise; resending and the supervision timeout only cope with it.
The exact split of decisions between Controller and Host software varies between products. The order given here follows the specification.
Questions answered
Which decisions happen before higher-layer policy code sees an event?
Before higher-layer policy code sees an event on a Bluetooth Low Energy (BLE) connection, the Link Layer in the Controller has already decided whether the packet was heard, whether it belongs to this connection, whether it arrived intact, whether it is new or a repeat, whether to acknowledge it or have it sent again, whether it decrypts with a valid integrity tag, and whether it is a control message that the Link Layer handles itself, such as a change of connection timing. Before the connection existed, the Link Layer decided whether to accept the connection request, and throughout the connection it decides when the link counts as lost.
Next, the Host’s L2CAP (Logical Link Control and Adaptation Protocol) layer reassembles and length-checks each message, and its ATT (Attribute Protocol) layer checks that the addressed attribute exists and that the link’s security meets the attribute’s permissions. Any of these steps can drop a packet, end the connection, or spend radio time, energy and memory without the policy code learning of it, so a policy enforced at the application layer covers only the operations that reach it.
Related entries: BLE Controller and Host (§7.4), Cross-layer security (§7.38), Complete mediation (§1.16), Supervision timeout (§7.8), Retransmission and duplicate delivery (§7.36). Further reading: [93].