【总结蓝牙hci工具集的使用】

本篇总结复习下常用的蓝牙hci工具集的使用,具体像bluez协议栈上就有使用

Hciattach

Hciattach主要用来初始化蓝牙设备,它的命令格式如下:

# hciattach [-n] [-p] [-b] [-t timeout] [-s initial_speed] <tty> <type | id> [speed] [flow|noflow] [bdaddr]

其中最重要的参数就是 type和speed,type决定了要初始化的设备的型号,可以使用 hciattach –l 来列出所支持的设备型号。

# hciattach -l
any 0x0000,0x0000
ericsson 0x0000,0x0000
digi 0x0000,0x0000
bcsp 0x0000,0x0000
xircom 0x0105,0x080a
csr 0x0000,0x0000
bboxes 0x0160,0x0002
swave 0x0000,0x0000
texas 0x0000,0x0000
texasalt 0x0000,0x0000
st 0x0000,0x0000
stlc2500 0x0000,0x0000
philips 0x0000,0x0000
bgb2xx 0x0000,0x0000
picocard 0x025e,0x1000
inventel 0x0000,0x0000
comone 0xffff,0x0101
tdk 0x0105,0x4254
socket 0x0104,0x0096
3com 0x0101,0x0041
bt2000c 0x022d,0x2000
zoom 0x0279,0x950b
sitecom 0x0279,0x950b
billionton0x0279,0x950b
bcm2035 0x0a5c,0x2035
bcm43xx 0x0000,0x0000
ath3k 0x0000,0x0000
qca 0x0000,0x0000
qualcomm 0x0000,0x0000
intel 0x0000,0x0000
3wire 0x0000,0x0000
amp 0x0000,0x0000

并不是所有的参数对所有的设备都是适用的,有些设备会忽略一些参数设置,例如:查看hciattach的代码就可以看到,多数设备都忽略bdaddr参数。

hciattach命令内部的工作步骤是:首先打开制定的tty设备,然后做一些通用的设置,如flow等,然后设置波特率为 initial_speed,然后根据type调用各自的初始化代码,最后将波特率重新设置为speed。所以调用hciattach时,要根据你的实际情况,设置好initial_speed和speed。

Hcidump

Hcidump 主要用来分析捕获和分析HCI数据包,如果使用bluez过程中出了什么问题,用hcidump往往可以发现一些出错的线索,原因。 参数很多,基本上hcidump –X –V 就可以帮你获得详细的经过格式解析的数据包。
hcidump -i hci0 -w bt_debug

导出的文件需要用wireshark软件去打开看

Hcitool

Hcitool主要用来scan远端的设备,显示设备地址,名称,连接状态等。不适合连接外部蓝牙
例如:hcitool dev ,hcitool scan, hcitool inq , hcitool con

# hcitool dev 显示本地设备和MAC
Devices:
hci0 00:0B:82:00:00:02

# hcitool scan 扫描附件蓝牙设备
Scanning ...
C0:74:AD:1C:D4:7E GSC3516_1c:d4:7e
0C:93:8F:DA:10:DE OPPO A55 5G
E0:9D:31:EC:D3:11 MRC-WX0

# hcitool inq 获取远程设备mac地址clock offset以及class.
Inquiring ...
00:0B:82:00:00:02 clock offset: 0x42e5 class: 0x5a020c
C0:74:AD:1C:D4:7E clock offset: 0x296e class: 0x6c0100
E0:9D:31:EC:D3:11 clock offset: 0x5f24 class: 0x2a010c

# hcitool sr 0C:93:8F:DA:10:DE m切换主机master模式

hciconfig

命令格式上很类似于ifconfig,用来设置HCI设备的参数
例如:hciconfig -a , hciconfig hci0 up , hciconfig hci0 iscan (使能位于hci0接口的蓝牙芯片的inquery scan模式(使得设备能被其它蓝牙设备发现))

# hciconfig -a 查看hci控制器下的所有信息
hci0: Type: BR/EDR Bus: UART
BD Address: 00:0B:82:00:00:02 ACL MTU: 1024:7 SCO MTU: 60:8
UP RUNNING PSCAN ISCAN
RX bytes:4696 acl:0 sco:0 events:115 errors:0
TX bytes:3313 acl:0 sco:0 commands:99 errors:0
Features: 0xff 0xfe 0x8f 0xfe 0xd8 0x2f 0x5b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF
Link mode: SLAVE ACCEPT
Name: 'GSC3516_00:00:02'
Class: 0x6c0100
Service Classes: Rendering, Capturing, Audio, Telephony
Device Class: Computer, Uncategorized
HCI Version: (0x9) Revision: 0x0
LMP Version: (0x9) Subversion: 0x25a
Manufacturer: Qualcomm (29)
使能hci0控制器
# hciconfig hci0 up
更改hci0 名字
# hciconfig hci0 name xxx
使能hci0 sspmode模式
# hciconfig hci0 sspmode 1
失能hci0 sspmode模式,也就是用传统pincode模式
# hciconfig hci0 sspmode 0
可使设备既可见,又可连接

hciconfig hci0 piscan

测试网络联通性

用 l2ping 命令可测试蓝牙网络状况,使用方法类似于 ping 命令, 即 l2ping + bd_addr,bd_addr 地址可用扫描命令获得

bluetoothctl

bluetoothctl是蓝牙工具集用来模拟人机交互蓝牙设备的工具

# bluetoothctl
[bluetooth]# [NEW] Controller 00:0B:82:00:00:02 GSC3516_00:00:02 [default]
[bluetooth]# help
Available commands:
list List available controllers
show [ctrl] Controller information
select <ctrl> Select default controller
devices List available devices
paired-devices List paired devices
power <on/off> Set controller power
pairable <on/off> Set controller pairable mode
discoverable <on/off> Set controller discoverable mode
agent <on/off/capability> Enable/disable agent with given capability
default-agent Set agent as the default one
scan <on/off> Scan for devices
info <dev> Device information
pair <dev> Pair with device
trust <dev> Trust device
untrust <dev> Untrust device
block <dev> Block device
unblock <dev> Unblock device
remove <dev> Remove device
connect <dev> Connect device
disconnect <dev> Disconnect device
version Display version
quit Quit program
[bluetooth]# agent on //注册代理
[bluetooth]# Agent registered
[bluetooth]# scan on //打开扫描
[bluetooth]# Discovery started
[bluetooth]# [CHG] Controller 00:0B:82:00:00:02 Discovering: yes
[bluetooth]# [NEW] Device 43:1E:EE:46:BB:EF 43-1E-EE-46-BB-EF
[bluetooth]# [NEW] Device 0C:26:00:4B:C5:C0 HB3110019397
[bluetooth]# [CHG] Device 43:1E:EE:46:BB:EF Trusted: yes
[bluetooth]# [NEW] Device 00:1B:10:90:3E:57 200359
[bluetooth]# [CHG] Device 0C:26:00:4B:C5:C0 Trusted: yes
[bluetooth]# [CHG] Device 00:1B:10:90:3E:57 Trusted: yes
[bluetooth]# [NEW] Device 42:EB:32:90:9F:92 42-EB-32-90-9F-92
[bluetooth]# [CHG] Device 42:EB:32:90:9F:92 Trusted: yes
[bluetooth]# [NEW] Device 82:E8:2C:5C:42:8D 82-E8-2C-5C-42-8D
[bluetooth]# [CHG] Device 82:E8:2C:5C:42:8D Trusted: yes
[bluetooth]# [NEW] Device E4:E1:12:A9:4D:6A E4-E1-12-A9-4D-6A
[bluetooth]# [CHG] Device E4:E1:12:A9:4D:6A Trusted: yes
[bluetooth]# [NEW] Device 51:1D:8A:34:D8:6D 51-1D-8A-34-D8-6D
[bluetooth]# [CHG] Device 51:1D:8A:34:D8:6D Trusted: yes
[bluetooth]# [NEW] Device 04:52:C7:FD:77:B5 04-52-C7-FD-77-B5
[bluetooth]# [CHG] Device 04:52:C7:FD:77:B5 Trusted: yes
[bluetooth]# [NEW] Device 40:0F:8D:13:47:87 40-0F-8D-13-47-87
[bluetooth]# [CHG] Device 40:0F:8D:13:47:87 Trusted: yes
[bluetooth]# [NEW] Device F0:B0:40:C6:C5:26 F0-B0-40-C6-C5-26
[bluetooth]# [CHG] Device F0:B0:40:C6:C5:26 Trusted: yes
[bluetooth]# [NEW] Device 5D:32:CD:4B:02:2B 5D-32-CD-4B-02-2B
[bluetooth]# [CHG] Device 5D:32:CD:4B:02:2B Trusted: yes
[bluetooth]# [NEW] Device 0C:93:8F:DA:10:DE OPPO A55 5G
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE Trusted: yes
[bluetooth]# [NEW] Device E0:9D:31:EC:D3:11 MRC-WX0
[bluetooth]# [CHG] Device E0:9D:31:EC:D3:11 Trusted: yes
[bluetooth]# trust 0C:93:8F:DA:10:DE //添加为信任
[bluetooth]# Changing 0C:93:8F:DA:10:DE trust succeeded
[bluetooth]# pair 0C:93:8F:DA:10:DE //配对此设备
Attempting to pair with 0C:93:8F:DA:10:DE
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE Connected: yes
[bluetooth]# Request confirmation
[bluetooth]# [agent] Confirm passkey 050529 (yes/no): yes
[bluetooth]# bluetoothd[477]: GAP and GATT are mandatory
bluetoothd[477]: gap-gatt-profile profile probe failed for 0C:93:8F:DA:10:DE
[CHG] Device 0C:93:8F:DA:10:DE Modalias: bluetooth:v0046p1200d1436
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE UUIDs:
[bluetooth]# 00001105-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000110a-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000110c-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000110e-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001112-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001115-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001116-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000111f-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000112f-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001132-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001200-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001800-0000-1000-8000-00805f9b34fb
[bluetooth]# 00001801-0000-1000-8000-00805f9b34fb
[bluetooth]# 0000aa15-0000-1000-8000-00805f9b34fb
[bluetooth]# a49eaa15-cb06-495c-9f4f-bb80a90cdf00
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE Paired: yes
[bluetooth]# Pairing successful
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE Connected: no
[bluetooth]# connect 0C:93:8F:DA:10:DE
Attempting to connect to 0C:93:8F:DA:10:DE
[bluetooth]# [CHG] Device 0C:93:8F:DA:10:DE Connected: yes
[bluetooth]# bluetoothd[477]: Endpoint registered: sender=:1.1 path=/org/bluez/hci0/A2DP/SBC/sink/3
Connection successful
[bluetooth]# bluetoothd[477]: Can't open input device: No such file or directory (2)
bluetoothd[477]: AVRCP: failed to init uinput for 0C:93:8F:DA:10:DE
bluetoothd[477]: D-Bus failed to register /org/bluez/hci0/dev_0C_93_8F_DA_10_DE/player0 path
[bluetooth]# info 0C:93:8F:DA:10:DE
Device 0C:93:8F:DA:10:DE
Name: OPPO A55 5G
Alias: OPPO A55 5G
Class: 0x5a020c
Icon: phone
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: OBEX Object Push (00001105-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: PANU (00001115-0000-1000-8000-00805f9b34fb)
UUID: NAP (00001116-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
UUID: Phonebook Access Server (0000112f-0000-1000-8000-00805f9b34fb)
UUID: Message Access Server (00001132-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000aa15-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (a49eaa15-cb06-495c-9f4f-bb80a90cdf00)
Modalias: bluetooth:v0046p1200d1436
[bluetooth]# quit

bluetoothd

bluetoothd是bluetooth中核心进程,主要是用来接收手机或者bluealsa发来的dbus然后去做处理

命令选项是 :

-n 后台运行

-d 加下调试信息

bluetoothd -n -d &

参考博客:蓝牙使用 (zlg.cn)

至此,上面是Bluetooth调试所需要的一些工具的简单介绍,大家可以进行尝试!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值