bluez tutorial BLE Link Layer Control Procedures

 

 

bluez tutorial BLE Link Layer Control Procedures
Chapter 8 Section 8.12 — LLCP Overview, All PDUs, Connection Update, Channel Map & Encryption Start
Procedures
9 core + 4 new
Sequential
One at a time
Exception
Termination any time
LTK
128-bit key
Keywords:

BLE LLCP control procedures LL_CONNECTION_UPDATE_REQ LL_CHANNEL_MAP_REQ BLE encryption start LL_ENC_REQ BLE long term key LTK BLE sequential control procedures BLE 4.1 4.2 enhancements BlueZ LLCP encryption

Completing the Connection State — Real Sniffer Values

The previous file left with the CONNECT_REQ payload fields. This file opens with the remaining captured values from Figure 8.21 that were printed on page 180, then moves into the main topic: Section 8.12, which covers every procedure the Link Layer uses to manage an active connection.

Remaining CONNECT_REQ Captured Values from Figure 8.21

Beyond connSlaveLatency = 0 (covered previously), the sniffer capture also showed these values:

Figure 8.22 — Connection State Transition with Real Values

Advertising (→ Slave) Initiator (→ Master)
Advertising
ADV_IND or ADV_DIRECT_IND
Initiator
Advertising
CONNECT_REQ
Initiator
Connection CREATED — both enter Connection state
SLAVE
MASTER
Data Channel PDU exchanged
Connection ESTABLISHED

connSupervisionTimeout 7000 ms — if no packet arrives for 7 seconds the connection is lost
ChannelMap Bitmap indicating which data channels are currently usable
HopIncrement 10 — the value added each hop: fn+1 = (fn + 10) mod 37

8.12 — Link Layer Control Procedures

What LLCP Does and Why It Exists

After a BLE connection is established, the connection parameters are not frozen forever. The environment changes, security needs may change, and both sides may need to update what they agreed on during the CONNECT_REQ exchange. The Link Layer Control Protocol (LLCP) provides the mechanism to negotiate and update these parameters without dropping the connection.

LLCP PDUs travel inside data channel PDUs. When a link layer control PDU is sent, the LLID field in the data channel PDU header is set to 0b11 (as opposed to 0b10 for regular L2CAP data). The receiver recognises this and passes the payload to its own link layer for processing rather than up to L2CAP.

Sequential rule: Only one LLCP procedure can be active at any time. A new procedure cannot be started until the previous one either completes successfully or times out. The only exception is the Termination procedure, which can be sent at any moment regardless of whether another procedure is in progress.

Table 8.5 — All LLCP Procedures and Their PDUs
Procedure PDU(s) Initiator Purpose
Connection Update LL_CONNECTION_UPDATE_REQ Master only Update connInterval, slave latency, supervision timeout
Channel Map Update LL_CHANNEL_MAP_REQ Master only Change which data channels are enabled (AFH support)
Encryption Start LL_ENC_REQ / RSP
LL_START_ENC_REQ / RSP
Master only Enable AES-128 encryption on the link using the LTK
Encryption Pause LL_PAUSE_ENC_REQ / RSP Master only Pause then restart encryption with a new key
Feature Exchange LL_FEATURE_REQ / RSP Master (4.0)
Either (4.1+)
Share supported feature bitmaps between devices
Version Exchange LL_VERSION_IND Either Exchange company ID, LL version, sub-version number
Termination LL_TERMINATE_IND Either — anytime Gracefully close the connection
Unsupported PDU LL_UNKNOWN_RSP Either Response when an unrecognised PDU is received
Rejection LL_REJECT_IND Either Reject a request — e.g. Slave rejects encryption it does not support
Conn Params Request
(4.1 new)
LL_CONNECTION_PARAM_REQ / RSP Either (4.1) Either side requests connection parameter update
LE Ping
(4.1 new)
LL_PING_REQ / RSP Either (4.1) Verify the remote link layer is still present
Data Length Update
(4.2 new)
LL_LENGTH_REQ / RSP Either (4.2) Negotiate larger PDU payload sizes (up to 251 bytes)
Slave Feature Req
(4.1 new)
LL_SLAVE_FEATURE_REQ Slave (4.1) Slave requests the Master’s feature set
Extended Rejection
(4.1 new)
LL_REJECT_IND_EXT Either (4.1) Extended rejection with error reason included

8.12.1 — Connection Update Procedure

Updating Three Key Parameters Mid-Connection

After a connection is established the Master can change three of the connection timing parameters at any time without dropping the connection. This is important because the best parameters at connection setup may not be the best parameters during later phases of use. For example, a device may connect with a short interval to quickly exchange initial data, then switch to a longer interval to save battery during an idle period.

The three parameters the Master can update:

Connection Interval

How often connection events happen

Slave Latency

How many events the Slave can skip

Supervision Timeout

How long before the link is declared lost

Who can start it: Only the Master. The Slave cannot initiate this procedure in BLE 4.0. In BLE 4.1, the Slave gains the ability to request parameter changes using the Connection Parameters Request procedure (LL_CONNECTION_PARAM_REQ).

Figure 8.23 — Connection Update Procedure
Master Slave
Using old parameters…
LL_CONNECTION_UPDATE_REQ
(new interval, latency, timeout)
No response PDU — Slave simply applies the new parameters at the instant defined by the Instant field
Using new parameters…
/* Updating connection parameters from a Central (Master) with BlueZ */
/* The host stack sends HCI LE Connection Update to the controller    */

/* Using hcitool to update connection interval:                       */
/* hcitool lecup --handle 0x0040 --min 0x0028 --max 0x0028           */
/*               --latency 0 --timeout 0x00C8                         */
/* --min/max 0x0028 = 40 × 1.25ms = 50ms connection interval         */
/* --latency 0      = Slave must respond every event                  */
/* --timeout 0xC8   = 200 × 10ms  = 2000ms supervision timeout       */

8.12.2 — Channel Map Update Procedure

Adaptive Frequency Hopping in Action

In a real deployment, the radio environment around a BLE device changes over time. A Wi-Fi router nearby may switch channels. A microwave oven may start causing interference. Some data channels that were clean at connection setup may develop persistent noise later.

The Channel Map Update procedure allows the Master to tell the Slave which channels are now considered good and which should be avoided. The Master continuously monitors signal quality on the data channels and updates the bitmap whenever it detects that a channel has become unreliable. This is the foundation of BLE’s Adaptive Frequency Hopping (AFH) capability.

Two parameters are included in the update:

Channel Map

The new 37-bit bitmap. Bit = 1 means the channel is enabled for use. Bit = 0 means it has interference and the hopping algorithm will remap any hop that lands on it.

Hop Increment

The number of channels to advance on each hop. This can also be changed during the update to alter the hopping pattern.

By disabling channels with interference, the Master reduces the number of retransmissions — which directly saves power and increases throughput for the same energy budget.

Figure 8.24 — Channel Map Update Procedure
Master Slave
Old channel map, old hop increment active…
LL_CHANNEL_MAP_REQ
(new channel map + hop increment + Instant)
Both devices switch to new map at the defined Instant
New channel map, new hop increment active…

8.12.3 — Encryption Start Procedure

Enabling AES-128 Encryption with a 4-PDU Handshake

A BLE connection can start unencrypted (for example, to exchange non-sensitive discovery data) and then switch to encrypted mode when sensitive data needs to be transferred. The Encryption Start procedure handles this transition.

It is initiated by the host of the Master side. The Master’s host sends an HCI command down to its link layer that includes the Long_Term_Key (LTK) — a 128-bit key that was established during the pairing process. The link layer uses the LTK to derive a session key that will encrypt all subsequent link layer PDUs for this connection.

Figure 8.25 — Encryption Start Procedure
Master Slave
Host sends LE Start Encryption command with LTK to Master link layer
LL_ENC_REQ (Master nonce + EDIV)
LL_ENC_RSP (Slave nonce)
Slave requests LTK from its host using the EDIV
LL_START_ENC_REQ
LL_START_ENC_RSP ← 3-way handshake done
LL_START_ENC_RSP (second, acknowledges Master’s)
Link is now encrypted with AES-128

The three-way handshake (LL_START_ENC_REQ → LL_START_ENC_RSP → LL_START_ENC_RSP) confirms that both sides have computed the same session key from the LTK. Only after both sides have confirmed can encrypted packets flow. If the Slave does not support encryption, it responds with LL_REJECT_IND instead.

/* Initiating encryption on a BLE connection with BlueZ  */
/* After pairing, the host sends LE Start Encryption HCI */

/* Using bluetoothctl: */
/* [bluetooth]# pair AA:BB:CC:DD:EE:FF  */
/* Pairing successful                   */
/* [AA:BB:CC:DD:EE:FF]# trust           */
/* Trust successful                     */
/* The link is now encrypted            */

/* Programmatic — BlueZ HCI LE Start Encryption command: */
/* OGF=0x08, OCF=0x0019                                  */
/* Parameters: handle, random, EDIV, LTK (16 bytes)      */
typedef struct {
    uint16_t handle;
    uint64_t random;
    uint16_t ediv;
    uint8_t  ltk[16]; /* 128-bit Long Term Key */
} __attribute__((packed)) le_start_enc_cp;

Next — Encryption Pause, Feature Exchange & More

You have seen the first three LLCP procedures. The next file covers Encryption Pause/Restart, Feature Exchange with the full feature bit table, and the section 8.12.4 details.

Next: Encryption Pause, Feature Exchange (PDF 1618) → ← PDF 1012

Leave a Reply

Your email address will not be published. Required fields are marked *