Ble 4.2版本最多可设置31个字节的广播数据。广播数据可以按需求由几段广播数据,每段数据由整体数据长度、数据标志、数据三个部分组成。数据的格式按照length| type|data组成。后面的广播数据也是如此构成。
Figure 9 Advertising and Scan Response data format
广播数据标志可以查找枚举类型gap_ad_type获取。dv type是协议规定好的,下面列了一些adv type,根据不同的需求来选择adv type:
Adv type Description
0x01 Flag
0x02 Use of more than 16 bits UUID
0x03 Complete list of 16 bit UUID
0x04 Use of more than 32 bit UUD
0x05 Complete list of 32 bit UUID
0x06 Use of more than 128 bit UUID
0x07 Complete list of 128 bit UUID
0x08 Shortened device name
0x09 Complete device name
0x0A Transmit power
0x0D Class of device
0x0E Simple Pairing Hash C
0x0F Simple Pairing Randomizer
0x10 Temporary key value
0x11 Out of Band Flag
0x12 Slave connection interval range
0x14 Require 16 bit service UUID
0x1F Require 32 bit service UUID
0x15 Require 128 bit service UUID
0x16 Service data 16-bit UUID
0x20 Service data 32-bit UUID
0x21 Service data 128-bit UUID
0x17 Public Target Address
0x18 Random Target Address
0x19 Appearance
0x1A Advertising Interval
0x1B LE Bluetooth Device Address
0x1C LE Role
0x1D Simple Pairing Hash C-256
0x1E Simple Pairing Randomizer R-256
0x3D 3D Information Data
0xFF Manufacturer specific data
Table 15 Advertising Flags
针对每个adv type后面的data部分都有相应的标准格式,可以参考蓝牙协议规范,如果要自定义一些数据就要加在adv type为0xFF的数据里。