BGAPI#
BGAPI message header format#
The BGAPI message header is the first 4 bytes of a BGAPI message. It consists of device and message types, IDs, and data payload length.
Byte 1#
Bits 0 - 2: Highest 3 bits of the data payload length field
Bits 3 - 5: Device type
Bit value 100: Bluetooth LE
Bit value 101: Bluetooth Mesh
Bit 6: Reserved
Bit 7: Message type
Bit value 0: The message is a command or a response to command.
Bit value 1: The message is an event.
Byte 2#
This byte is the lowest 8 bits of the data payload length field.
Byte 3#
This byte is the BGAPI class ID.
Byte 4#
This byte is the message ID of a command, response or event.
A device type, class ID, message type and message ID together construct a unique identifer of a message within the BGAPI protocol.
Endianness#
BGAPI protocol stores data in little endian.
Concurrency#
When the application runs in an RTOS, the Bluetooth RTOS adaptation component has a mechanism to synchronize the handling of individual BGAPI commands. Thus, individual BGAPI commands are safe to be called from multiple threads when the Bluetooth RTOS adaptation component is used.
BGAPI commands cannot be called from interrupt context. Calling a command from interrupt context may delay the radio activity. Furthermore, when commands are also called from the main event loop or an RTOS task simultaneously, concurrent BGAPI calls may cause memory issues in the stack.
Payload Length Calculation#
Use SL_BGAPI_MSG_LEN to calculate the payload length of a BGAPI message.
Decode a BGAPI Message#
On an NCP host, a received API message is either a response or an event. As the message is in binary format, users may need to decode the binary to its corresponding named message definition. Following method can be used to decode a message binary received on NCP host:
Find out the device type from Byte 1 of the message header. Go to the BGAPI message summary table according to the device type. The table may be the BGAPI message summary in this document, or a table in another API reference manual. Bluetooth LE and Bluetooth Mesh APIs have separate API reference manuals.
Find out the message type of the message from bit 7 of the Byte 1 in the message header.
Find out the class ID which is the Byte 3 of the message header. Together with the message type, locate either the command or event message group for this class.
Locate the row in the message group according to the message ID which is the Byte 4 of the message header.
If the row is a command, the decoded message is a response to this command. Go to the command documentation. The 5th and 6th bytes of the binary are the error code returned for the command. Rest data of the binary maps to the [out] parameters of the command in declaration order.
If the row is an event, go to the event documentation. Data starting from the 5th byte maps to the event data structure fields in declaration order.
BGAPI message summary#
The following table summarizes the class and message IDs of commands and events in the BGAPI protocol. A response message has the same class and message ID as the command it responds to.
The table also shows the minimum payload length for each message. Messages that have an array parameter can have longer payload length depending on the length of the array.
Message Name | Class ID | Message ID | Minimum Payload Length |
---|---|---|---|
Commands | |||
0x00 | 0x01 | 4 | |
0x00 | 0x02 | 1 | |
0x00 | 0x03 | 0 | |
Events | |||
0x00 | 0x00 | 4 | |
0x00 | 0x01 | 2 | |
Commands | |||
0x01 | 0x00 | 0 | |
0x01 | 0x1c | 0 | |
0x01 | 0x1d | 0 | |
0x01 | 0x1b | 0 | |
0x01 | 0x01 | 1 | |
0x01 | 0x0c | 1 | |
0x01 | 0x0e | 2 | |
0x01 | 0x17 | 4 | |
0x01 | 0x18 | 0 | |
0x01 | 0x13 | 7 | |
0x01 | 0x15 | 0 | |
0x01 | 0x0b | 1 | |
0x01 | 0x12 | 1 | |
0x01 | 0x14 | 0 | |
0x01 | 0x0f | 1 | |
0x01 | 0x1a | 10 | |
Events | |||
0x01 | 0x00 | 18 | |
0x01 | 0x06 | 3 | |
0x01 | 0x05 | 2 | |
0x01 | 0x08 | 3 | |
0x01 | 0x03 | 4 | |
0x01 | 0x04 | 0 | |
0x01 | 0x07 | 1 | |
Commands | |||
0x5f | 0x00 | 0 | |
0x5f | 0x01 | 8 | |
0x5f | 0x02 | 2 | |
0x5f | 0x03 | 1 | |
0x5f | 0x04 | 0 | |
Events | |||
0x5f | 0x00 | 4 | |
Commands | |||
0x02 | 0x01 | 2 | |
0x02 | 0x02 | 1 | |
0x02 | 0x03 | 1 | |
0x02 | 0x04 | 7 | |
Commands | |||
0x04 | 0x01 | 0 | |
0x04 | 0x12 | 5 | |
0x04 | 0x03 | 12 | |
0x04 | 0x04 | 2 | |
0x04 | 0x0b | 3 | |
0x04 | 0x05 | 2 | |
0x04 | 0x10 | 8 | |
0x04 | 0x11 | 1 | |
0x04 | 0x0a | 1 | |
0x04 | 0x02 | 1 | |
0x04 | 0x06 | 3 | |
0x04 | 0x07 | 5 | |
0x04 | 0x08 | 5 | |
0x04 | 0x0f | 3 | |
0x04 | 0x0e | 2 | |
0x04 | 0x09 | 3 | |
0x04 | 0x0c | 9 | |
0x04 | 0x0d | 1 | |
Events | |||
0x04 | 0x01 | 1 | |
0x04 | 0x02 | 9 | |
Commands | |||
0x56 | 0x00 | 3 | |
0x56 | 0x01 | 2 | |
0x56 | 0x02 | 2 | |
0x56 | 0x03 | 9 | |
Commands | |||
0x57 | 0x00 | 3 | |
0x57 | 0x01 | 2 | |
0x57 | 0x02 | 1 | |
0x57 | 0x03 | 2 | |
0x57 | 0x04 | 6 | |
0x57 | 0x05 | 13 | |
Commands | |||
0x58 | 0x00 | 2 | |
0x58 | 0x01 | 1 | |
0x58 | 0x02 | 9 | |
0x58 | 0x03 | 1 | |
Events | |||
Commands | |||
0x05 | 0x06 | 5 | |
0x05 | 0x07 | 10 | |
0x05 | 0x05 | 0 | |
0x05 | 0x01 | 5 | |
0x05 | 0x02 | 2 | |
0x05 | 0x03 | 2 | |
Events | |||
0x05 | 0x00 | 19 | |
0x05 | 0x02 | 27 | |
0x05 | 0x01 | 18 | |
Commands | |||
0x42 | 0x02 | 8 | |
0x42 | 0x00 | 8 | |
0x42 | 0x03 | 3 | |
0x42 | 0x04 | 6 | |
0x42 | 0x01 | 2 | |
Events | |||
0x42 | 0x00 | 16 | |
0x42 | 0x03 | 21 | |
0x42 | 0x02 | 6 | |
0x42 | 0x01 | 4 | |
Commands | |||
0x50 | 0x00 | 5 | |
0x50 | 0x01 | 8 | |
Commands | |||
0x51 | 0x00 | 6 | |
0x51 | 0x01 | 7 | |
Commands | |||
0x52 | 0x00 | 4 | |
Commands | |||
0x5b | 0x00 | 5 | |
Commands | |||
Events | |||
0x53 | 0x00 | 16 | |
0x53 | 0x01 | 21 | |
0x53 | 0x02 | 8 | |
Commands | |||
0x54 | 0x02 | 3 | |
0x54 | 0x03 | 8 | |
Events | |||
0x54 | 0x00 | 20 | |
0x54 | 0x01 | 25 | |
0x54 | 0x02 | 11 | |
Commands | |||
0x55 | 0x00 | 14 | |
0x55 | 0x01 | 5 | |
0x55 | 0x02 | 9 | |
0x55 | 0x03 | 1 | |
Events | |||
0x55 | 0x00 | 3 | |
0x55 | 0x02 | 2 | |
0x55 | 0x01 | 9 | |
Commands | |||
0x06 | 0x00 | 12 | |
0x06 | 0x01 | 2 | |
0x06 | 0x10 | 2 | |
0x06 | 0x04 | 8 | |
0x06 | 0x06 | 13 | |
0x06 | 0x08 | 3 | |
0x06 | 0x03 | 2 | |
0x06 | 0x02 | 1 | |
0x06 | 0x07 | 1 | |
0x06 | 0x09 | 2 | |
0x06 | 0x0a | 2 | |
0x06 | 0x0b | 2 | |
0x06 | 0x0c | 2 | |
0x06 | 0x0d | 1 | |
0x06 | 0x0e | 1 | |
0x06 | 0x11 | 5 | |
0x06 | 0x05 | 1 | |
0x06 | 0x0f | 1 | |
Events | |||
0x06 | 0x00 | 13 | |
0x06 | 0x02 | 10 | |
0x06 | 0x04 | 2 | |
0x06 | 0x03 | 3 | |
0x06 | 0x05 | 7 | |
0x06 | 0x06 | 5 | |
0x06 | 0x07 | 5 | |
0x06 | 0x08 | 2 | |
0x06 | 0x09 | 9 | |
0x06 | 0x01 | 3 | |
Commands | |||
0x09 | 0x00 | 2 | |
0x09 | 0x01 | 1 | |
0x09 | 0x02 | 2 | |
0x09 | 0x10 | 5 | |
0x09 | 0x03 | 5 | |
0x09 | 0x04 | 6 | |
0x09 | 0x06 | 3 | |
0x09 | 0x14 | 5 | |
0x09 | 0x05 | 4 | |
0x09 | 0x0d | 1 | |
0x09 | 0x07 | 3 | |
0x09 | 0x12 | 7 | |
0x09 | 0x11 | 2 | |
0x09 | 0x08 | 6 | |
0x09 | 0x09 | 4 | |
0x09 | 0x0a | 4 | |
0x09 | 0x0b | 6 | |
0x09 | 0x13 | 6 | |
0x09 | 0x0c | 2 | |
0x09 | 0x0e | 3 | |
0x09 | 0x0f | 4 | |
Events | |||
0x09 | 0x00 | 3 | |
0x09 | 0x01 | 6 | |
0x09 | 0x02 | 5 | |
0x09 | 0x03 | 4 | |
0x09 | 0x04 | 7 | |
0x09 | 0x05 | 6 | |
0x09 | 0x06 | 3 | |
Commands | |||
0x46 | 0x00 | 0 | |
0x46 | 0x01 | 5 | |
0x46 | 0x02 | 4 | |
0x46 | 0x03 | 6 | |
0x46 | 0x04 | 4 | |
0x46 | 0x05 | 16 | |
0x46 | 0x06 | 30 | |
0x46 | 0x07 | 4 | |
0x46 | 0x08 | 15 | |
0x46 | 0x09 | 29 | |
0x46 | 0x0a | 4 | |
0x46 | 0x0b | 4 | |
0x46 | 0x0c | 4 | |
0x46 | 0x0d | 4 | |
0x46 | 0x0e | 4 | |
0x46 | 0x0f | 2 | |
0x46 | 0x10 | 2 | |
Commands | |||
0x0a | 0x0a | 2 | |
0x0a | 0x0b | 1 | |
0x0a | 0x06 | 3 | |
0x0a | 0x00 | 4 | |
0x0a | 0x01 | 2 | |
0x0a | 0x02 | 5 | |
0x0a | 0x03 | 5 | |
0x0a | 0x04 | 4 | |
0x0a | 0x0f | 4 | |
0x0a | 0x10 | 4 | |
0x0a | 0x11 | 3 | |
0x0a | 0x12 | 3 | |
0x0a | 0x14 | 7 | |
0x0a | 0x08 | 8 | |
0x0a | 0x0c | 4 | |
0x0a | 0x0d | 4 | |
0x0a | 0x0e | 0 | |
0x0a | 0x15 | 1 | |
Events | |||
0x0a | 0x00 | 7 | |
0x0a | 0x01 | 6 | |
0x0a | 0x02 | 7 | |
0x0a | 0x03 | 8 | |
0x0a | 0x04 | 3 | |
0x0a | 0x05 | 1 | |
0x0a | 0x06 | 2 | |
Commands | |||
0x0d | 0x02 | 3 | |
0x0d | 0x03 | 2 | |
0x0d | 0x04 | 2 | |
0x0d | 0x01 | 0 | |
Commands | |||
0x0e | 0x03 | 5 | |
0x0e | 0x04 | 5 | |
0x0e | 0x01 | 2 | |
0x0e | 0x02 | 0 | |
Events | |||
0x0e | 0x00 | 4 | |
Commands | |||
0x0f | 0x01 | 2 | |
0x0f | 0x14 | 1 | |
0x0f | 0x0f | 0 | |
0x0f | 0x13 | 7 | |
0x0f | 0x02 | 2 | |
0x0f | 0x00 | 1 | |
0x0f | 0x10 | 4 | |
0x0f | 0x04 | 1 | |
0x0f | 0x08 | 5 | |
0x0f | 0x09 | 2 | |
0x0f | 0x0e | 2 | |
0x0f | 0x06 | 1 | |
0x0f | 0x07 | 0 | |
0x0f | 0x15 | 4 | |
0x0f | 0x16 | 4 | |
0x0f | 0x17 | 6 | |
0x0f | 0x19 | 17 | |
0x0f | 0x1a | 1 | |
0x0f | 0x1b | 33 | |
Events | |||
0x0f | 0x00 | 5 | |
0x0f | 0x01 | 1 | |
0x0f | 0x02 | 5 | |
0x0f | 0x03 | 3 | |
0x0f | 0x04 | 3 | |
0x0f | 0x09 | 2 | |
Commands | |||
0x5c | 0x00 | 3 | |
Events | |||
0x5c | 0x00 | 2 | |
0x5c | 0x01 | 3 | |
0x5c | 0x02 | 1 | |
Commands | |||
0x5d | 0x00 | 5 | |
0x5d | 0x01 | 24 | |
0x5d | 0x02 | 4 | |
0x5d | 0x03 | 7 | |
0x5d | 0x04 | 0 | |
Commands | |||
0x5e | 0x00 | 4 | |
0x5e | 0x01 | 7 | |
0x5e | 0x02 | 4 | |
0x5e | 0x03 | 7 | |
0x5e | 0x04 | 0 | |
Commands | |||
0x10 | 0x01 | 1 | |
0x10 | 0x02 | 2 | |
0x10 | 0x03 | 4 | |
0x10 | 0x04 | 2 | |
Commands | |||
0x20 | 0x00 | 8 | |
0x20 | 0x02 | 4 | |
0x20 | 0x03 | 1 | |
0x20 | 0x04 | 0 | |
0x20 | 0x01 | 1 | |
Commands | |||
0x59 | 0x00 | 1 | |
0x59 | 0x01 | 5 | |
0x59 | 0x02 | 27 | |
0x59 | 0x03 | 2 | |
0x59 | 0x04 | 10 | |
0x59 | 0x05 | 22 | |
0x59 | 0x06 | 3 | |
0x59 | 0x07 | 1 | |
Events | |||
0x59 | 0x00 | 1 | |
0x59 | 0x01 | 29 | |
0x59 | 0x02 | 20 | |
0x59 | 0x03 | 15 | |
Commands | |||
0x5a | 0x00 | 26 | |
Commands | |||
0x43 | 0x01 | 9 | |
0x43 | 0x02 | 11 | |
0x43 | 0x03 | 4 | |
0x43 | 0x04 | 5 | |
0x43 | 0x05 | 3 | |
Events | |||
0x43 | 0x01 | 13 | |
0x43 | 0x02 | 13 | |
0x43 | 0x03 | 4 | |
0x43 | 0x04 | 5 | |
0x43 | 0x05 | 5 | |
0x43 | 0x06 | 4 | |
Commands | |||
0x44 | 0x04 | 3 | |
0x44 | 0x05 | 0 | |
0x44 | 0x00 | 3 | |
0x44 | 0x01 | 1 | |
0x44 | 0x02 | 5 | |
0x44 | 0x03 | 1 | |
0x44 | 0x06 | 5 | |
0x44 | 0x07 | 1 | |
Commands | |||
0x45 | 0x05 | 4 | |
0x45 | 0x06 | 0 | |
0x45 | 0x09 | 1 | |
0x45 | 0x0a | 7 | |
0x45 | 0x0b | 8 | |
0x45 | 0x01 | 7 | |
0x45 | 0x02 | 1 | |
0x45 | 0x03 | 5 | |
0x45 | 0x04 | 2 | |
0x45 | 0x07 | 3 | |
0x45 | 0x08 | 0 | |
Events | |||
0x45 | 0x02 | 10 | |
0x45 | 0x00 | 12 | |
0x45 | 0x01 | 12 | |
0x45 | 0x03 | 18 | |
Commands | |||
0xff | 0x00 | 1 | |
0xff | 0x01 | 1 | |
0xff | 0x02 | 0 | |
Events | |||
0xff | 0x00 | 1 |