[蓝牙 Mesh & Zephyr]-[002]-发送 Unprovisioned Device Beacon

本文介绍蓝牙Mesh中UnprovisionedDeviceBeacon格式及其发送过程。该信标包含BeaconType、DeviceUUID等字段,并可通过URIADType携带URIHash。在ZephyrMesh中实现的具体函数详细展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Unprovisioned Device Beacon 格式如下:
Figure 3.45: Unprovisioned device beacon format

FieldSize (octets)Notes
Beacon Type1Unprovisioned Device beacon type(0x00)
Device UUID16Device UUID uniquely identifying this device (see Section 3.10.3)
OOB Information2See Table 3.54
URI Hash4Hash of the associated URI advertised with the URI AD Type (optional field)

Table 3.53: Unprovisioned Device beacon format

BitDescription
0Otehr
1Electronic/URI
22D machine-readable code
3Bar code
4Near Field Communication(NFC)
5Number
6String
7Reserved for Future Use
8Reserved for Future Use
9Reserved for Future Use
10Reserved for Future Use
11On box
12Inside box
13On peice of paper
14Inside manual
15On 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值