-
Notifications
You must be signed in to change notification settings - Fork 0
Link Layer Packet Format
The Link Layer has only one packet format used for both advertising channel packets and data channel packets. Every BLE packet therefore always consists of four fields:
- Preamble
- Access Address
- PDU
- CRC
The advertising channel packet preamble is: 0xAA
The data channel packet preamble is either: 0xAA or 0x55
If the LSB of the Access Address is 1, the preamble shall be: 0x55
If the LSB of the Access Address is 0, the preamble shall be: 0xAA
The Access Address for all advertising channel packets is: 0x8E89BED6
The Access Address in data channel packets shall be different for each Link Layer connection between any two devices with certain restrictions as defined below.
The Access Address shall be a random 32-bit value, generated by the device in the Initiating State and sent in a connection request. The initiator shall ensure that the Access Address meets the following requirements:
- It shall have no more than six consecutive zeros or ones
- It shall not be the advertising channel packets’ Access Address
- It shall not be a sequence that differs from the advertising channel packet Access Address by only one bit
- It shall not have all four octets equal
- It shall have no more than 24 transitions
- It shall have a minimum of two transitions in the most significant six bits
The Access Address is configured inside the blemin_ini() function inside the blemin.c source file.
NRF_RADIO->PREFIX0 = ((_access_addr >> 24) & 0x000000FF);
NRF_RADIO->BASE0 = ((_access_addr << 8) & 0xFFFFFF00);
When a packet is transmitted in an advertising physical channel, the PDU shall be the Advertising Channel PDU. When a packet is transmitted in a data physical channel, the PDU shall be the Data Channel PDU.
The advertising channel PDU has a 16-bit header and a variable size payload.
PDU Type: Indicates the PDU type of the advertising channel packet
TxAdd: Used as information flag specific to the corresponding PDU type
RxAdd: Used as information flag specific to the corresponding PDU type
RFU: Reserved for future use
Length: Indicates the length of the payload field in octets. The valid range of the Length field shall be 6 to 37 octets.
The advertising channel PDU header is defined as PDU_header type inside the ng_ble.h header file.
typedef struct __attribute__((packed))
{
uint8_t pdu_type: 4; /**< PDU type */
uint8_t RFU1: 2; /**< Reserved for future use (1) */
uint8_t tx_add: 1; /**< TXAdd field */
uint8_t rx_add: 1; /**< TXAdd field */
uint8_t length: 6; /**< Payload length */
uint8_t RFU2: 2; /**< Reserved for future use (2) */
} PDU_header;
Connection request packets are sent from a device which wishes to initiate a connection with an advertising device.
InitA: Initiators public or random device address
AdvA: Advertising devices public or random device address
LLData
- AA: The link layer connection's access address
- CRCInit: Initialization value for the CRC calculation
- WinSize: The transmitWindowSize value
- WinOffset: The transmitWindowOffset value
- Interval: Connection interval of data connection
- Latency: The connSlaveLatency value
- Timeout: The connSupervisionTimeout value
- ChM: Channel map which indicates Used and Unused data channels. LSB represents data channel index 0. A bit value of 0 indicates that the channel is Unused and a bit value of 1 indicates that the channel is Used.
- Hop: hopIncrement used in the data channel selection algorithm. Random value in the range of 5 to 16.
- SCA: used to determine the worst case Master's sleep clock accuracy.
The Data Channel PDU has a 16 bit header, a variable size payload, and may include a Message Integrity Check (MIC) field.
LLID: Indicates whether the packet is an LL Data PDU or an LL Control PDU
NESN: Next expected Sequence Number
SN: Sequence Number
MD: More data
RFU: Reserved for future use
Length: Indicates the length of the payload and MIC (if included) in octets