Definition
The Host Controller Interface (HCI), defined in the Bluetooth Core Specification [275], is the standard interface between a Bluetooth device’s Host, its upper protocol layers, and its Controller, the radio and the Link Layer §7.6. HCI has three kinds of packet: commands, which the Host sends to ask the Controller to do something; events, which the Controller sends to report results and occurrences; and data packets, which carry connection data in both directions. HCI transports carry these packets between chips, for example over USB or a UART §6.23 (universal asynchronous receiver-transmitter) serial link.
The idea
A laptop maker buys Bluetooth chips from different suppliers, while the laptop’s operating system contains a single Host. That Host must start advertising, open connections and send data on every chip without knowing how any chip works inside. HCI makes this possible. It is a fixed vocabulary of numbered commands and events, so the bytes that mean “start advertising” are the same on every Controller that follows the specification.
HCI is also asynchronous: the Host sends a command and carries on, and the Controller answers later with an event. Some answers mean “done”. Others mean only “started”: a connection, for example, forms only when the peer is found, which may take seconds. The Host must therefore keep track of which of its requests are still open, and match each event to the request it answers. This is a case of asynchronous completion §9.28, in which the result of an operation arrives separately from the call that started it.
How it works
Packets.
Command (Host to Controller): 2 bytes that name the command, which the specification calls the opcode, then 1 byte that gives the length of the parameters, then the parameters. The opcode joins a 6-bit group number, the opcode group field (OGF), and a 10-bit number within the group, the opcode command field (OCF): , where because the OCF takes the low 10 bits. The commands specific to BLE §7.1 (Bluetooth Low Energy) are in group
0x08.Event (Controller to Host): 1 byte of event code, 1 byte of parameter length, then the parameters. Two events report on commands. Command Complete (code
0x0E) carries a command’s result, and Command Status (code0x0F) says whether the Controller has started a command whose result comes later. Other events report what happened, such as Disconnection Complete (0x05). The events specific to BLE share the code0x3E, the LE Meta event (LE stands for Low Energy); its first parameter byte, the subevent code, says which event it is, for example0x01for LE Connection Complete and0x02for LE Advertising Report.ACL data packet (both directions): ACL stands for asynchronous connection-oriented, the name of the link that carries ordinary connection data. A 4-byte header holds a 12-bit connection handle, the number that the Controller gave the connection when it formed, 4 bits of flags, 2 of which say whether the packet starts a message or continues one, and a 2-byte length. The data is an L2CAP §7.15 (Logical Link Control and Adaptation Protocol) message or a fragment of one.
Other data packets carry audio and other time-bound data: synchronous packets for BR/EDR (Basic Rate/Enhanced Data Rate), the older Bluetooth radio system, and isochronous packets, added in version 5.2, for BLE.
A number longer than one byte is sent least significant byte first.
Transports. When Host and Controller are separate chips, an HCI transport carries the packets between them. On a UART link, one byte before each packet says its kind: 0x01 command, 0x02 ACL data, 0x03 synchronous data, 0x04 event, 0x05 isochronous data. The specification also defines transports for USB and other links. On a single chip, an implementation may pass the same packets through a queue in memory, or replace HCI with direct function calls into the Controller.
Flow control. The Controller has limited buffers. Every Command Complete and Command Status event carries a number, Num_HCI_Command_Packets, that says how many more commands the Controller can accept now. For data, the Host learns how many data packets the Controller can buffer, counts the packets it sends, and waits when the count reaches that number; the Number Of Completed Packets event (code 0x13) reports packets that the Controller has finished with, which frees their places.
Two ways a command finishes.
A command that the Controller can carry out at once is answered by Command Complete, which carries the result. Reset and the command that turns advertising on are examples.
A command that starts a procedure is answered first by Command Status. Status 0 means only that the procedure has started. A later event, specific to the command, reports the outcome. After LE Create Connection, for example, the outcome is an LE Connection Complete event. It arrives when the peer has been found and the connection has formed, which can take any length of time, or, with an error status, when the attempt fails or the Host cancels it.
Worked example
Two commands show the two ways a command finishes. In the first, a sensor’s Host turns advertising on over a UART link.
The Host sends 5 bytes:
01 0A 20 01 01. The first01says that a command follows. LE Set Advertising Enable has OGF0x08and OCF0x000A, so its opcode is , which is0x200A, sent low byte first as0A 20. The next01says that 1 parameter byte follows, and the last01is that parameter: enable.The Controller answers with 7 bytes:
04 0E 04 01 0A 20 00.04says that an event follows;0Eis Command Complete;04says that 4 parameter bytes follow;01says that the Controller can accept 1 more command;0A 20names the command being answered; and00is the status, success. Advertising is now on.
In the second, a phone’s Host opens a connection to that sensor.
At time 0 the Host sends LE Create Connection, opcode , which is
0x200D, with the sensor’s address among its parameters.At 1 ms the Controller answers
04 0F 04 00 01 0D 20: an event, Command Status, 4 parameter bytes, status00(started), room for 1 more command, and the opcode0x200D. No connection exists yet.At 800 ms, having received one of the sensor’s advertisements and sent a connection request, the Controller sends an LE Meta event, code
0x3E, with subevent0x01, LE Connection Complete. It carries the new connection handle and the connection’s parameters.
The command took 1 ms to be accepted and the procedure took 800 ms. A Host that treated the Command Status at 1 ms as “connected” would act 799 ms early, and wrongly if the connection never formed.
Stated precisely
HCI states the following contract.
The Host may send a command only while the Controller has room for one: the last
Num_HCI_Command_Packetsvalue received, minus the commands sent since, is above 0.Apart from a few exceptions that the specification names, the Controller answers every command with exactly one Command Complete event or one Command Status event, and that event repeats the command’s opcode.
A Command Status with status 0 promises a later event that reports the outcome. A Command Status with any other status means that the command was rejected and no procedure started.
Events about a connection carry its connection handle. A handle names a connection only while that connection exists: after its Disconnection Complete event, the Controller may give the same handle to a new connection.
From this contract follows the matching rule. The Host matches a command result to its command by the opcode, and a connection event to its connection by the handle. An event that answers a request the Host has already abandoned must be discarded; it must not complete a newer request of the same kind.
Limits and common mistakes
Accepted is not done. A Command Status with status 0 says that a procedure started, not that it succeeded. The latency of a procedure is measured to its final event, not to the Command Status.
HCI carries secrets. To start encryption, the Host passes the long-term key §7.28 (LTK) to the Controller inside an HCI command. In a two-chip design, anyone who can probe the wires between the chips, or capture the USB traffic of a Bluetooth adapter, can read the key.
Each side trusts the other. The Controller carries out every valid command from the Host, and the Host usually believes every event from the Controller. A faulty or compromised Controller can send malformed events, so the Host must check the lengths and fields of events as carefully as radio data.
HCI is a local interface. A remote device cannot send HCI commands, but the content of its radio packets reaches the Host inside HCI events, such as advertising reports, and inside data packets, so those carry bytes that a remote device chose.
Where a single-chip product keeps HCI, the interface divides the work but does not isolate memory: both parts run in one address space unless the chip enforces a separation, for example with a memory protection unit §6.8 (MPU).
Supported commands differ between Controllers and between specification versions, so a Host asks the Controller which commands and features it supports instead of assuming them.
Questions answered
Does a single-chip build still preserve logical HCI boundaries?
It can, but it need not, and where it does, the boundary divides the work without isolating the two parts. The Host Controller Interface (HCI) is the set of commands, events and data packets defined between a Bluetooth device’s Host (its upper protocol layers) and its Controller (the radio and the Link Layer). On a single chip, some implementations keep passing HCI packets between the two parts through a queue in memory, so the interface and its contract are preserved exactly. Others call Controller functions directly through a supplier’s own interface; HCI then does not exist inside the chip, although the division of responsibilities between Host and Controller remains.
In either case, unless the chip enforces a separation, for example with a memory protection unit (MPU) that limits which memory each part may access, both parts share one memory and the same access rights, so a memory-corruption defect in one part can damage the other. Which design a given product uses has to be established from its software, not assumed from the specification.
Related entries: BLE Controller and Host (§7.4), Asynchronous completion (§9.28), ABA problem (§9.25), Long-term key (LTK) (§7.28), UART (§6.23). Further reading: [19, 275].