Unprovisioned Device Beacon 格式如下:
Field | Size (octets) | Notes |
---|---|---|
Beacon Type | 1 | Unprovisioned Device beacon type(0x00) |
Device UUID | 16 | Device UUID uniquely identifying this device (see Section 3.10.3) |
OOB Information | 2 | See Table 3.54 |
URI Hash | 4 | Hash of the associated URI advertised with the URI AD Type (optional field) |
Table 3.53: Unprovisioned Device beacon format
Bit | Description |
---|---|
0 | Otehr |
1 | Electronic/URI |
2 | 2D machine-readable code |
3 | Bar code |
4 | Near Field Communication(NFC) |
5 | Number |
6 | String |
7 | Reserved for Future Use |
8 | Reserved for Future Use |
9 | Reserved for Future Use |
10 | Reserved for Future Use |
11 | On box |
12 | Inside box |
13 | On peice of paper |
14 | Inside manual |
15 | On device |
Table 3.54: OOB Information field
URI Hash:URI(Uniform Resource Identifier) 的哈希值。
在 Zephyr Mesh 中,发送 Unprovisioned Device Beacon 的函数如下:
hci.h
#define BT_DATA_URI 0x24 /* URI */
#define BT_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */
#define BT_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */
#define BT_DATA_MESH_BEACON 0x2b /* Mesh Beacon */
beacon.c
static int unprovisioned_beacon_send(void)
{
#if defined(CONFIG_BT_MESH_PB_ADV)
const struct bt_mesh_prov *prov;
u8_t uri_hash[16] = { 0 };
struct net_buf *buf;
u16_t oob_info;
BT_DBG("");
//BT_DATA_MESH_BEACON = 0x2b
//最终通过adv_type[BT_MESH_ADV_BEACON] 获取 BT_DATA_MESH_BEACON,
buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, UNPROV_XMIT, K_NO_WAIT);
if (!buf) {
BT_ERR("Unable to allocate beacon buffer");
return -ENOBUFS;
}
/获取通过 bt_mesh_prov_init(const struct bt_mesh_prov *prov_info)配置的数据
prov = bt_mesh_prov_get();
net_buf_add_u8(buf, BEACON_TYPE_UNPROVISIONED);
net_buf_add_mem(buf, prov->uuid, 16);
//计算 URI Hash
if (prov->uri && bt_mesh_s1(prov->uri, uri_hash) == 0) {
oob_info = prov->oob_info | BT_MESH_PROV_OOB_URI;
} else {
oob_info = prov->oob_info;
}
net_buf_add_be16(buf, oob_info);
net_buf_add_mem(buf, uri_hash, 4);
//发送 buf
bt_mesh_adv_send(buf, NULL, NULL);
//buf引用计数减1,减到0时放回池中
net_buf_unref(buf);
//URI,是通过AD Type = BT_DATA_URI(0x24)发出的
if (prov->uri) {
size_t len;
buf = bt_mesh_adv_create(BT_MESH_ADV_URI, UNPROV_XMIT,
K_NO_WAIT);
if (!buf) {
BT_ERR("Unable to allocate URI buffer");
return -ENOBUFS;
}
len = strlen(prov->uri);
if (net_buf_tailroom(buf) < len) {
BT_WARN("Too long URI to fit advertising data");
} else {
net_buf_add_mem(buf, prov->uri, len);
bt_mesh_adv_send(buf, NULL, NULL);
}
net_buf_unref(buf);
}
#endif /* CONFIG_BT_MESH_PB_ADV */
return 0;
}