当前位置:网站首页>Ble link layer air packet format

Ble link layer air packet format

2022-06-09 21:54:00 jim0506

Air package format

BLE The air packet format of link layer is very simple , All its air packages follow the format shown in the figure below :

The picture above shows ,BLE Air bag by 4 Component composition , They are :

  • Lead code (Preamble)
  • Access address (Access Address)
  • Protocol data unit (Protocol Data Unit)
  • CRC

The preamble occupies 1 Bytes , The visiting address accounts for 4 Bytes ,PDU Occupy 2 To 257 Bytes ,CRC Occupy 3 Bytes , The size of a complete air bag is 10 Byte to 265 Between bytes

LSB(The Least Significant) Represents the least significant bit ;MSB(The Most Significant) Represents the most significant bit . The least significant bit is first sent to the air by the link layer , The most significant bit is sent last . In other words, the preamble is sent out first , The second is the access address , Again PDU, The last is CRC

Lead code (Preamble)

The preamble occupies 8 A bit , In all broadcast channels , The preamble of the air bag is 10101010b; In the data channel , The preamble of the air package is 10101010b Or is it 01010101

If you look at the level , The preamble is actually a high-low rectangular wave , The receiver can synchronize the frequency of the receiving circuit to the frequency of the rectangular wave , This is the so-called receiver frequency synchronization mechanism . In layman's terms , The receiver can estimate the starting position of a bit and the width of a bit , Thus, each significant bit can be received accurately .

meanwhile , The preamble marks the beginning of a valid air packet , Avoid the interference of invalid data in the air .

Access address (Access Address)

The access address in the broadcast channel is different from that in the data channel . The access address of broadcast channel is fixed as 0x8E89BED6; The access address of the data channel is determined by the initiator . So the simple understanding is , From the access address, we can first distinguish , Is the air packet a broadcast packet or a connected packet .

As mentioned above, the preamble of the data channel is 10101010b Or is it 01010101b, Actually, it depends on the least significant bit of the access address in the data channel 0 still 1, If it is 1, Then the preamble is 01010101b, It is 10101010b

When the initiator makes a connection request to the broadcaster , It puts the value of the access address into the corresponding field of the connection request , When the link layer connection is successfully established , Both sides are in the connected state , Later, both sides of the air package use this access address for communication .

thus it can be seen , The access address is also bound to a specific link layer connection . for example , A link layer connection is established between a device and multiple devices , In other words, a device maintains multiple links at the same time , When the device receives an air bag , It only needs to access the address to know which connection the air package is .

Protocol data unit (Protocol Data Unit)

The protocol data unit is the payload part of the air package , Different types of air bags , its PDU Are different , It can be roughly divided into broadcast channels PDU And data channel PDU

BLE Using frequency hopping mechanism , The link layer has 40 Channels , among 3 The first channel is the broadcast channel , in addition 37 The first channel is the data channel

When the device is in broadcasting or initiating state , The device sends or receives a broadcast channel PDU; When a device establishes a link layer connection with another device , Both sides are in the connected state , They send or receive data from the channel PDU

Broadcast channel PDU

Broadcast channel PDU Its structure consists of two parts , Namely Header and Payload, As shown in the figure below :

It can be seen from the above figure ,Header The size is 16bits, That is to say 2 Bytes ,Payload Length from Header Medium Length Field decision , So first look at Header The composition of the fields , As shown in the figure below :

Header The field consists of the following 6 Component composition :

  • PDU type : The type of broadcast packet
  • RFU(Reserve For Future): Reserved for future use
  • TxAdd: The address type of the sender
  • RxAdd: Recipient address type
  • Length:Payload Length of part
  • RFU(Reserve For Future): Reserved for future use

The types of broadcast packets are shown in the following table :

PDU TypePacket Name
0000 Can be connected to non directional broadcast (ADV_IND)
0001 Can be connected to directional broadcast (ADV_DIRECT_IND)
0010 Can't connect to broadcast (ADV_NONCONN_IND)
0011 Scan request (SCAN_REQ)
0100 Scan response (SCAN_RSP)
0101 Connection request (CONNECT_REQ)
0110 Scannable indication (ADV_SCAN_IND)
0111-1111 Retain (Reserved)

I will not introduce the types of each package , There will be a detailed introduction in the future blog
 

Data channels PDU

Data channels PDU contain 16 Bit head and a ⻓ Variable degrees payload, And maybe there's also a
MIC(Message Itegrity Check: Message integrity check ), Data channels PDU The format is shown in the figure below :

among Header The structure of is shown in the figure below :

Header Include 6 Parts of :

LLID

2 Bytes , This bag is LL Data PDU( Link layer packets ) still LL Control PDU( Link layer control packet ), Its possible values are as follows :

  • 00b: Retain
  • 01b:LL Data PDU( Link layer packets ) Or a Empty PDU( Empty bag ). If it's a link layer packet , Because of a long L2CAP Packets will be divided into multiple packets and sent separately , This package is not the first one after it is partitioned
  • 10b:LL Data PDU( Link layer packets ), It represents a complete packet that is not fragmented , Or the first partition package after partition .
  • 11b: yes LL Control PDU( Link layer control packet )

NESN

The serial number of the next package

SN

The serial number of the air bag

MD

More Data It means , because BLE It's low power Bluetooth , It's essentially a sleep wake-up mechanism , Sending and receiving air packets while awake , If MD Field set to 1, It means that the sender has more air packets to send in the future , To inform the recipient not to go to sleep , Keep the data going ; If the field is set to 0, The sender has no more data to send , It's time to go to sleep .

CRC

CRC It's about PDU Partial data integrity verification

原网站

版权声明
本文为[jim0506]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206092113553244.html