拓十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

蓝牙学习之设备信息

蓝牙学习之设备信息 前言蓝牙学习之Linux命令介绍了一些基本命令。本章收集获取蓝牙信息的方法。以下是AI介绍Linux可获取的蓝牙信息汇总。获取MAC地址参考蓝牙学习之Linux命令获取MAC地址。参考蓝牙地址BD_ADDR组成获取OUI厂商信息以及地址类型。获取CoDCoDCoD 共 24 bit由四段组成最低 2 位固定为 0b00即 format type23131287210┌────────────────┬────────────┬───────────┬────┐ │ Major Service │ Major │ Minor │0b00│ │ Classes(11bit)│Device(5bit)│Device(6b)│ │ └────────────────┴────────────┴───────────┴────┘bit 13–23Major Service Classbit 13–23位域可多位同时置1Bit值(hex)Service Class130x002000Limited Discoverable Mode140x004000LE Audio2025 版新增做 LE Audio / Auracast 音箱要置位150x008000Reserved160x010000Positioning定位170x020000NetworkingLAN、Ad hoc180x040000Rendering渲染音箱/打印机190x080000Capturing采集麦克风/扫描仪200x100000Object Transfer210x200000Audio音箱、麦克风、Headset 服务220x400000Telephony230x800000Informationbit 8–12Major Device Class目前共11个有效值。值二进制Major Device000000Miscellaneous100001Computer台式/笔记本/PDA200010Phone蜂窝/无绳/调制解调器300011LAN / Network Access Point400100Audio/Video耳机、音箱、立体声、视频显示、VCR500101Peripheral鼠标、摇杆、键盘600110Imaging打印、扫描、相机、显示700111Wearable801000Toy901001Health3111111Uncategorized未指定设备码bit 2–7Minor Device ClassMajorDevice4: Audio/Video值Minor Device说明0Uncategorized未分类1Wearable Headset Device可穿戴耳机早期单声道 Headset2Hands-free Device免提设备3(Reserved)保留不要用4Microphone麦克风5Loudspeaker音箱 ← 你的设备6Headphones头戴/入耳式耳机7Portable Audio便携音频播放器8Car Audio车载音频9Set-top Box机顶盒10HiFi Audio Device高保真音响11VCR录像机12Video Camera摄像机13Camcorder便携式摄录一体机14Video Monitor视频监视器15Video Display and Loudspeaker带音箱的显示设备电视/回音壁常用16Video Conferencing视频会议终端17(Reserved)保留不要用18Gaming/Toy游戏/玩具仅限通过蓝牙暴露 A/V 能力的玩具类设备MajorDevice5: Peripheral字段0x000x400x800xC0bit7-6非键盘 / 非指向设备键盘指向设备键盘 指向设备复合bit5-20123456789含义未分类摇杆游戏手柄遥控器传感设备数字化仪读卡器数码笔手持扫码器手持手势输入MajorDevice6: Imaging位bit4bit5bit6bit7值0x040x080x100x20能力DisplayCameraScannerPrinter其他Major012345678910111213Computer (1)未分类台式工作站服务器笔记本翻盖手持 PDA掌上 PDA手表式可穿戴电脑平板——————Phone (2)未分类蜂窝无绳智能手机有线调制解调器或语音网关普通 ISDN 接入————————Wearable (7)未分类腕表寻呼机夹克头盔眼镜————————Toy (8)未分类机器人车辆玩偶 / 动作人偶控制器游戏————————Health (9)未分类血压计体温计体重秤血糖仪血氧仪心率监测健康数据显示计步器体成分分析仪峰值流速仪用药监测膝关节假体踝关节假体脚本编写get_CoD.sh脚本CoD: Class of Device。内容如下#!/usr/bin/env bash# get_CoD.sh MAC [hciN]# 用法:# ./get_CoD.sh B0:82:E2:67:46:DB# ./get_CoD.sh B0:82:E2:67:46:DB hci1# 依赖: bluez (bluetoothctl dbus-send hcitool hciconfig hciattach), pipewire/pulseaudio (pactl),# python3 (仅用标准库用于解析与解码)set-uopipefailMAC${1:-}HCI${2:-hci0}if[[-z$MAC]];thenechousage:$0MAC [hci0]2exit1fiMACUP${MAC^^}DEVPATH/org/bluez/${HCI}/dev_${MACUP//:/_}CARDbluez_card.${MACUP//:/_}ADAPTER_MAC$(hciconfig$HCI2/dev/null|awk/BD Address/{print $3})COD$(dbus-send--system--print-reply--destorg.bluez$DEVPATH\org.freedesktop.DBus.Properties.Get string:org.bluez.Device1 string:Class2/dev/null\|awk/uint32/{print $3})python3 -${COD:-0}${MOD:-}PY import sys, re cod int(sys.argv[1] or 0) modalias sys.argv[2] if len(sys.argv) 2 else if cod: SVC [(0x2000, Limited Discoverable), (0x10000, Positioning), (0x20000, Networking), (0x40000, Rendering), (0x80000, Capturing), (0x100000, Object Transfer), (0x200000, Audio), (0x400000, Telephony), (0x800000, Information)] MAJOR {0: Miscellaneous, 1: Computer, 2: Phone, 3: LAN/Network AP, 4: Audio/Video, 5: Peripheral, 6: Imaging, 7: Wearable, 8: Toy, 9: Health} MINOR_AV {1: Wearable Headset, 2: Hands-free, 4: Microphone, 5: Loudspeaker, 6: Headphones, 7: Portable Audio, 8: Car audio, 9: Set-top box, 10: HiFi Audio Device, 11: VCR, 12: Video Camera, 13: Camcorder, 14: Video Monitor, 15: Video Display and Loudspeaker, 16: Video Conferencing, 18: Gaming/Toy} print(fCoD raw : 0x{cod:06X} ({cod})) print(f service class: {, .join(n for b, n in SVC if cod b) or (none)}) maj (cod 8) 0x1F minor (cod 2) 0x3F print(f major class : {maj} {MAJOR.get(maj, Unknown)}) if maj 4: print(f minor class : {minor} {MINOR_AV.get(minor, Unknown)}) else: print(f minor class : {minor}) print(f format type : {cod 0x3}) else: print(CoD : (未取得)) PY实测ethanG5000:~$ ./get_CoD.sh B0:82:E2:67:46:DB CoD raw:0x240414(2360340)serviceclass: Rendering, Audio major class:4Audio/Video minor class:5Loudspeakerformattype:0命令ethanG5000:~$ bluetoothctl info B0:82:E2:67:46:DB Device B0:82:E2:67:46:DB(public)Class: 0x00240414(2360340)Modalias: bluetooth:v0B05p1CB0d0100可以获取CoD的hex值获取modalias脚本#!/usr/bin/env bash# get_modalias.sh MAC [hciN]# 用法:# ./get_CoD.sh B0:82:E2:67:46:DB# ./get_CoD.sh B0:82:E2:67:46:DB hci1# 依赖: bluez (bluetoothctl dbus-send hcitool hciconfig hciattach), pipewire/pulseaudio (pactl),# python3 (仅用标准库用于解析与解码)set-uopipefailMAC${1:-}HCI${2:-hci0}if[[-z$MAC]];thenechousage:$0MAC [hci0]2exit1fiMACUP${MAC^^}DEVPATH/org/bluez/${HCI}/dev_${MACUP//:/_}CARDbluez_card.${MACUP//:/_}ADAPTER_MAC$(hciconfig$HCI2/dev/null|awk/BD Address/{print $3})COD$(dbus-send--system--print-reply--destorg.bluez$DEVPATH\org.freedesktop.DBus.Properties.Get string:org.bluez.Device1 string:Class2/dev/null\|awk/uint32/{print $3})MOD$(dbus-send --system --print-reply --destorg.bluez $DEVPATH \ org.freedesktop.DBus.Properties.Get string:org.bluez.Device1 string:Modalias 2/dev/null \ | sed -n s/.*\(bluetooth:[^]*\).*/\1/p) python3 - ${COD:-0} ${MOD:-} PYimportsys, re codint(sys.argv[1]or0)modaliassys.argv[2]iflen(sys.argv)2elseifmodalias: print(fModalias raw : {modalias})gre.match(rbluetooth:v([0-9A-Fa-f]{4})p([0-9A-Fa-f]{4})d([0-9A-Fa-f]{4}), modalias)ifg: print(f vendor : 0x{g.group(1)})print(f product : 0x{g.group(2)})print(f devversion : 0x{g.group(3)})else: print(Modalias : (设备未提供))PY实测ethanG5000:~$ ./get_CoD.sh B0:82:E2:67:46:DB Modalias raw:bluetooth:v0B05p1CB0d0100 vendor:0x0B05 product:0x1CB0 devversion:0x0100命令ethanG5000:~$ bluetoothctl info B0:82:E2:67:46:DB Device B0:82:E2:67:46:DB(public)Class: 0x00240414(2360340)Modalias: bluetooth:v0B05p1CB0d0100可以获取modalias的hex值UUIDUniversally Unique IdentifierUUIDUniversally Unique Identifier来自 ITU-T X.667 / ISO/IEC 11578​ 的实现规范。本质是一个 128 bit16 字节​ 的数字用 36 个字符32 hex 4 个连字符写成 8-4-4-4-12。UUID没有协调者不需要注册。但蓝牙使用特定Base UUID。蓝牙技术范围内需要向蓝牙SIG申请。xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx │ │ │ └─ N: 变体位8/9/a/bRFC4122 └────── M: 版本号v1 时间MAC / v3 MD5 / v4 随机 / v5 SHA-116-bit: 0000XXXX-0000-1000-8000-00805F9B34FB32-bit: XXXXXXXX-0000-1000-8000-00805F9B34FB蓝牙Base UUID为00000000-0000-1000-8000-00805F9B34FB。内部可缩写成16位使用或者32bit使用。截取0000XXXX-0000-1000-8000-00805F9B34FB的XXXX一共16位或者XXXXXXXX-0000-1000-8000-00805F9B34FB的XXXXXXXX一共32位。蓝牙UUID包含六种角色角色UUID 范围例子命名的是什么属性类型0x2800–0x28FF0x2800 首要服务、0x2803 特征声明GATT 表的结构服务0x1800–0x26FF0x180F 电池、0x180D 心率一组功能的集合特征0x2A00–0x7FFF0x2A19 电量、0x2A37 心率测量具体可读写的数据点描述符0x2900–0x29FF0x2902 CCCD、0x2901 用户描述特征的附加说明计量单位0x2700–0x27FF各种单位编码数值的物理量纲协议/服务类SDP0x0001–0x17FF0x0019 AVDTP、0x110B AudioSink经典蓝牙的传输协议与 profile已知已分配的厂商 16-bit可查询Assigned_Numbers链接文档。例如UUID归属0xFEE7腾讯控股SIG 于 2014-04-24 分配0xFE95小米0xFFF6Matter / CSA 配网服务BLE commissioning非 SIG 分配但被 CSA 规范硬编码引用高危 / 禁用清单UUID现状建议0xFFE0 / 0xFFE1HM-10济南华茂串口透传非 SIG 分配因海量山寨模块成事实标准演示可用量产勿用0xFFF0–0xFFF5TI CC254x SDK SimpleProfile 例程被国产 SDK 大量照抄⚠️从 SDK 例程移植前务必改掉0x180D 等标准号有强制语义义务暴露即承诺遵守整套规范获取版本主版本在蓝牙技术中LMP 值通常指 LMP Version是用来唯一标识蓝牙核心规范版本如蓝牙 4.2、5.0、5.2 等的底层数字代号。LMP 是 Link Manager Protocol链路管理器协议 的缩写。LMP对照表LMP 值 (十六进制)LMP 值 (十进制)对应的蓝牙核心规范版本 (Bluetooth Version)发布年份 / 核心特性0x00Bluetooth 1.0b1999 (初代蓝牙标准)0x11Bluetooth 1.12001 (成为 IEEE 802.15.1 标准)0x22Bluetooth 1.22003 (引入快速连接和 AFH 调频)0x33Bluetooth 2.0 EDR2004 (引入 EDR速率提升至 3 Mbps)0x44Bluetooth 2.1 EDR2007 (引入 SSP 简易安全配对)0x55Bluetooth 3.0 HS2009 (引入高速传输借助 Wi-Fi 传输大文件)0x66Bluetooth 4.02010 (⚠️里程碑正式引入低功耗蓝牙 BLE)0x77Bluetooth 4.12013 (优化与 4G/LTE 信号的共存)0x88Bluetooth 4.22014 (提升 BLE 传输速率和隐私安全性)0x99Bluetooth 5.02016 (BLE 速度翻倍距离变远 4 倍)0xA10Bluetooth 5.12019 (引入寻向功能支持厘米级定位)0xB11Bluetooth 5.22020 (⚠️音频重构引入 LE Audio 和 LC3 编码)0xC12Bluetooth 5.32021 (优化连接稳定性、降低功耗与延迟)0xD13Bluetooth 5.42023 (引入带加密功能的周期性广播 PAwR)0xE14Bluetooth 6.02024 (引入信道探测 Channel Sounding 极速测距)主机版本ethanG5000:~$sudobtmgmt info Index list with1item hci0: Primary controller addr D0:39:57:05:7F:08 version11manufacturer93class 0x6c010c supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr le advertising secure-conn debug-keys privacy static-addr phy-configuration wide-band-speech cis-central cis-peripheral current settings: powered ssp br/edr le secure-conn wide-band-speech cis-central cis-peripheral name G5000 short name上述version 11代表本机G5000的蓝牙版本为V5.2。题外可以根据manufacturer 93在Assigned_Numbers链接文档查询芯片公司。设备版本ethanG5000:~$ hcitool info B0:82:E2:67:46:DB Requesting information... BD Address: B0:82:E2:67:46:DB OUI Company: ASUSTek COMPUTER INC.(B0-82-E2)Device Name: XXXXXX LMP Version:5.4(0xd)LMP Subversion: 0x1450 Manufacturer: Actions(Zhuhai)Technology Co., Limited(992)LMP Version: 5.4 (0xd) LMP Subversion: 0x1450代表蓝牙版本V5.4。hcitool命令即将被丢弃可以用bluetoothctl和btmon代替。参照蓝牙学习之Linux命令的bluetoothctl说明。ethanG5000:~$printfhci.open 0 raw\nhci.cmd 0x041D 0x01 0x00\n|bluetoothctl--timeout10btmon窗口可以看到HCI Event: Read Remote Version Complete(0x0c)plen8#3 [hci0] 4.472162Status: Success(0x00)Handle:1LMP version: Bluetooth5.4(0x0d)- Subversion5200(0x1450)Manufacturer: Actions(Zhuhai)Technology Co., Limited(992)
返回列表