手机 HCI 日志记录
在VIVO手机中的开发者选项,启用蓝牙 HCI 信息手机日志。
用USB连接电脑后,将 USB连接方式 调整为传输文件。
adb bugreport vivo_btsnoop
会在 /data/user_de/0/com.android.shell/files/
下生成日志,并自动拉取到电脑上。
在 bugreport.zip 下的 \FS\data\misc\bluetooth\logs
中能找到 HCI log:
Knowledge Base
UUID
UUID(Universally Unique Identifier)是一个 128位(16字节) 的唯一标识符,用于标识蓝牙协议中的各种组件 Services Characteristics Descriptors 的类型和功能。
Service
Service 是蓝牙设备提供的 功能集合,每个 Service 包含一个或多个 Characteristic
Service 也分为 Primary Service 和 Secondary Service
Characteristic
Characteristic 是 Service 中的 具体数据点,用于 读取、写入、通知 数据。
每个 Characteristic 包含:
- Value:存储的数据(如温度、心率等)。
- Properties:定义操作权限(
read
、write
、notify
等)。 - Descriptors:额外配置(如通知开关)。
抓包
我已经知道这是一个蓝牙低功耗(BLE)设备,只需找到Attribute Protocol通信:
在安卓设备中,我也找到了一个国产的还挺好用的蓝牙调试工具,E调试。
我们在浏览器环境使用 Web Bluetooth API 来进行蓝牙通信。
// Bluetooth functionality
if (!navigator.bluetooth) {
console.error('Web Bluetooth API 不支持此浏览器');
} else {
async function connectAndWrite() {
try {
console.log("Requesting Bluetooth Device...");
// 扫描并选择设备
const device = await navigator.bluetooth.requestDevice({
// acceptAllDevices: true,
filters: [{ name: 'JEU-Lush139-XT' }],
optionalServices: ['generic_access', '53300001-0023-4bd4-bbd5-a6920e4c5653'] // 指定要访问的服务
});
console.log("Device:", device.name);
// 连接到 GATT 服务器
const server = await device.gatt.connect();
console.log("Connected to GATT Server");
// 获取服务
const service = await server.getPrimaryService("53300001-0023-4bd4-bbd5-a6920e4c5653");
console.log("Service:", service.uuid);
// Notify
const characteristic = await service.getCharacteristic("53300002-0023-4bd4-bbd5-a6920e4c5653");
await characteristic.startNotifications();
characteristic.addEventListener('characteristicvaluechanged', (event) => {
const value = event.target.value;
console.log("Received value:", value);
});
const close_cmd = [0x85, 0x8b, 0x5b, 0x55, 0x67, 0x7a, 0x7b, 0x7c, 0x1a];
const open_cmd = [0x85, 0x8b, 0x5b, 0x55, 0x66, 0x6a, 0x6b, 0x6c, 0x0b];
const characteristic2 = await service.getCharacteristic("53300003-0023-4bd4-bbd5-a6920e4c5653");
characteristic2.writeValue(new Uint8Array(open_cmd));
console.log("Data written successfully!");
// 断开连接
device.gatt.disconnect();
console.log("Disconnected");
} catch (error) {
console.error("Error:", error);
}
}