关键词:hciconfig hcitool hcidump
作者:xubin341719(欢迎转载,请注明作者,请尊重版权,谢谢!)
欢迎指正错误,共同学习、共同进步!!
Android blueZ HCI(一):hciconfig实现及常用方法
Android blueZ hci(二):hcitool hcidump常用方法
一、Hcitool
1、这部分代码和hciconfig命令比较相似,不做详细分析
命令对应执行函数、解释数据表:
比如:hci scan命令,对应执行cmd_scan函数Idh.code\external\bluetooth\bluez\tools\hcitool.c
static struct {
char *cmd;
void (*func)(int dev_id, int argc, char **argv);
char *doc;
} command[] = {//命令定义描述
{ "dev", cmd_dev, "Display local devices" },
{ "inq", cmd_inq, "Inquire remote devices" },
{ "scan", cmd_scan, "Scan for remote devices" },
{ "name", cmd_name, "Get name from remote device" },
{ "info", cmd_info, "Get information from remote device" },
{ "spinq", cmd_spinq, "Start periodic inquiry" },
{ "epinq", cmd_epinq, "Exit periodic inquiry" },
{ "cmd", cmd_cmd, "Submit arbitrary HCI commands" },
{ "con", cmd_con, "Display active connections" },
{ "cc", cmd_cc, "Create connection to remote device" },
{ "dc", cmd_dc, "Disconnect from remote device" },
{ "sr", cmd_sr, "Switch master/slave role" },
{ "cpt", cmd_cpt, "Change connection packet type" },
{ "rssi", cmd_rssi, "Display connection RSSI" },
{ "lq", cmd_lq, "Display link quality" },
{ "tpl", cmd_tpl, "Display transmit power level" },
{ "afh", cmd_afh, "Display AFH channel map" },
{ "lp", cmd_lp, "Set/display link policy settings" },
{ "lst", cmd_lst, "Set/display link supervision timeout" },
{ "auth", cmd_auth, "Request authentication" },
{ "enc", cmd_enc, "Set connection encryption" },
{ "key", cmd_key, "Change connection link key" },
{ "clkoff", cmd_clkoff, "Read clock offset" },
{ "clock", cmd_clock, "Read local or remote clock" },
{ "lescan", cmd_lescan, "Start LE scan" },
{ "lecc", cmd_lecc, "Create a LE Connection", },
{ "ledc", cmd_ledc, "Disconnect a LE Connection", },
{ "dsn", cmd_dsn, "Try to get rid of scatternets", },
{ NULL, NULL, 0 }
};
2、 hcitool常用方法
(1)、hcitool帮助命令
hcitool –h
(2)、hcitool dev 显示本机MAC地址
root@android:/ # hcitool dev
hcitool dev
Devices:
hci0 00:16:53:96:22:53
(3)、hcitool inq
root@android:/ # hcitool inq
hcitool inq
Inquiring ...
C4:6A:B7:21:79:C8 clock offset: 0x7e48 class: 0x5a020c
1C:66:AA:66:68:2E clock offset: 0x5e27 class: 0x5a020c
AC:72:89:85:90:2A clock offset: 0x13ec class: 0x4a0100
68:17:29:78:37:4A clock offset: 0x5185 class: 0xff0104
B0:C4:E7:65:A7:3A clock offset: 0x267e class: 0x5a020c
(5)、hcitool name 8C:71:F8:AE:2A:C0(对应要获取名字的BT mac地址)
(6)、hcitool info 8C:71:F8:AE:2A:C0(对应要获取名字的BT mac地址)
(7)、hci clock
1|root@android:/ # hcitool clock
hcitool clock
Clock: 0x5ba67
Accuracy: 0.00 msec
二、hcidump常用方法
1、 hcidump -Xt
终端下显示相应HCI信息。
1、 hcidump –Bw /data/bt1.cfa(android2.3下)/data/bt1.cfa为文件路径
hcidump –w /data/bt1.cfa(android 4.0下)
用capture file viewer打开(frontline comprobe protocol analysis system 13.8)入下图就可以分析相应的协议。
(2)、hcidump -tr bt_0.log
显示bt hci log信息
(3)、hcidump -r bt_0.log
(4)、hcidump –Rtw