如何将蓝牙 16 位服务 UUID 转换为 128 位 UUID?

How can I convert a Bluetooth 16 bit service UUID into a 128 bit UUID?

所有 assigned services 仅声明 16 位 UUID。如果必须以该格式指定服务,我如何确定对应的 128 位?

来自 Service Discovery Protocol Overview 我知道 128 位 UUID 是基于所谓的 "BASE UUID" 的,它也在那里说明:

00000000-0000-1000-8000-00805F9B34FB

但是如何从对应的 16 位 UUID 创建 128 位 UUID?可能必须替换某些 0 数字,但是替换哪个数字以及如何替换?

这可以在蓝牙 4.0 核心规范 Vol. 3 - 核心系统。参见 the list of adopted specs

B 部分,涵盖 服务发现协议 (SDP) 第 2.5.1 章 "Searching for Services / UUID"将解释如何计算UUID。

The full 128-bit value of a 16-bit or 32-bit UUID may be computed by a simple arithmetic operation.

128_bit_value = 16_bit_value * 2^96 + Bluetooth_Base_UUID
128_bit_value = 32_bit_value * 2^96 + Bluetooth_Base_UUID

A 16-bit UUID may be converted to 32-bit UUID format by zero-extending the 16-bit value to 32-bits. An equivalent method is to add the 16-bit UUID value to a zero-valued 32-bit UUID.

请注意,在另一部分中,有一个方便的助记符:

Or, to put it more simply, the 16-bit Attribute UUID replaces the x’s in the follow- ing:

0000xxxx-0000-1000-8000-00805F9B34FB

In addition, the 32-bit Attribute UUID replaces the x's in the following:

xxxxxxxx-0000-1000-8000-00805F9B34FB

相同的方程式适用于属性 UUID。请参阅F 部分,涵盖第 3.2.1 章属性协议 (ATT)"Protocol Requirements / Basic Concepts". 32 位属性 UUID 首次在蓝牙核心 4.1 规范中指定。