1491 views|0 replies

2015

Posts

0

Resources
The OP
 

Bluetooth learning notes: analysis of example broadcast data [Copy link]

The first step of BLE device operation is to broadcast data. The broadcast data contains device-related information. This article mainly talks about the specification of data in BLE broadcast and the analysis of broadcast packets. This is the broadcast data in our project. The actual operation of broadcast data is in the program broadcast initialization function. Define the broadcast type and broadcast data according to your needs.

There are two roles in BLE broadcast mode
: Central and Peripheral. Central devices can actively connect to peripheral devices, and peripheral devices can send broadcasts or be connected by central devices. Peripherals are discovered by central devices through broadcasts, which contain relevant information about the peripheral devices themselves.

There are two types of advertising packets: Advertising Data and Scan Response. Advertising packets are mandatory for each device, while Scan Response packets are optional. The format of the data packet is shown in the figure below (picture from the official Spec): Each packet is 31 bytes, and the data packet is divided into two parts: significant data and non-significant data.

Valid data part: contains several broadcast data units, called AD Structure. As shown in the figure, the composition of AD Structure is: the first byte is the length value Len, indicating that the next Len bytes are the data part. The first byte of the data part indicates the data type AD Type, and the remaining Len - 1 bytes are the actual data AD data. Among them, AD type is very critical, which determines what the data of AD Data represents and how to parse it. This will be explained in detail later;
Invalid data part: because the length of the broadcast packet must be 31 bytes, if the valid data part is less than 31 bytes, the rest will be filled with 0. This part of the data is invalid and can be ignored when interpreting.
Broadcast data format
All AD type definitions are as follows:

Flags: TYPE = 0x01. This data is used to identify the function of the device LE physical connection. DATA is a Flag value of 0 to multiple bytes, and each bit is 0 or 1 to indicate whether it is True. If any bit is not 0 and the advertising packet is connectable, this data must be included. The definition of each bit is as follows:

bit 0: LE limited discovery mode
bit 1: LE general discovery mode
bit 2: BR/EDR is not supported
bit 3: Support both BLE and BR/EDR for Same Device Capable (Controller)
bit 4: Support both BLE and BR/EDR for Same Device Capable (Host)
bit 5..7: Reserved
Special note: Here we find that our broadcast data is 0x06, which is actually the broadcast mode flag designed by our program:
flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
Service UUID: In the broadcast data, the GATT Service supported by the device is generally broadcasted to tell the outside world what services the device supports. There are three types of UUID: 16 bit, 32bit, 128 bit. In the broadcast, each type has two categories: complete and incomplete. So there are 6 AD Types in total.

Incomplete 16 bit UUID list: TYPE = 0x02; Complete 16 bit UUID list: TYPE = 0x03; Incomplete 32 bit UUID list: TYPE = 0x04; Complete 32 bit UUID list: TYPE = 0x05; Incomplete 128 bit UUID list: TYPE = 0x06; Complete 128 bit UUID list: TYPE = 0x07;
Local Name: Device name, DATA is the name string. Local Name can be the full name of the device or the abbreviation of the device name, where the abbreviation must be the first few characters of the full name.

Device full name: TYPE = 0x08 Device short name: TYPE = 0x09
TX Power Level: TYPE = 0x0A, indicating the signal strength of the device sending the advertising packet. The DATA part is one byte, indicating -127 to + 127 dBm.

Security Manager Out of Band: TYPE = 0x11. DATA is also a Flag, and each bit represents a function:

bit 0: OOB Flag, 0 means no OOB data, 1 means yes bit 1: Support LE bit 2: Support BLE and BR/EDR for Same Device Capable (Host) bit 3: Address type, 0 means public address, 1 means random address
Peripheral (Slave) connection interval range: TYPE = 0x12. The maximum and minimum connection intervals of the Slave are defined in the data, and the data contains 4 bytes:

The first 2 bytes: define the minimum connection interval, the value range is: 0x0006 ~ 0x0C80, and 0xFFFF means undefined; the second 2 bytes: define the maximum connection interval, the same as above, but it is necessary to ensure that the maximum connection interval is greater than or equal to the minimum connection interval.
Service search: The peripheral device can ask the central device to provide the corresponding service. Its data definition is similar to the previous Service UUID:

16 bit UUID list: TYPE = 0x14 32 bit UUID list: TYPE = 0x?? 128 bit UUID list: TYPE = 0x15
Service Data: Data corresponding to the Service.

16 bit UUID Service: TYPE = 0x16, the first 2 bytes are UUID, followed by Service data; 32 bit UUID Service: TYPE = 0x??, the first 4 bytes are UUID, followed by Service data; 128 bit UUID Service: TYPE = 0x??, the first 16 bytes are UUID, followed by Service data;
Public target address: TYPE = 0x17, indicating that this broadcast packet is expected to be processed by the specified target device. This device is bound to a public address. DATA is a list of target addresses, each with 6 bytes.

Random target address: TYPE = 0x18, the definition is similar to the previous one, indicating that the broadcast packet is expected to be processed by the specified target device, and this device is bound to a random address. DATA is a list of target addresses, each address is 6 bytes.

Appearance: TYPE = 0x19, DATA indicates the appearance of the device.

Manufacturer-defined data: TYPE = 0xFF. In the manufacturer-defined data, the first two bytes represent the manufacturer ID, and the rest are added by the manufacturer according to their needs. The data content inside is defined by themselves. Our program adds the mac address here.

There are some other data, which are not used much. You can refer to the core manual if you need it.

This post is from Wireless Connectivity
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list