Android blueZ HCI(二):hcitool hcidump常用方法

来源:互联网 发布:东芝复印机网络店 编辑:程序博客网 时间:2024/06/10 08:57

一、Hcitool
1、这部分代码和hciconfig命令比较相似,不做详细分析
命令对应执行函数、解释数据表:
比如:hci scan命令,对应执行cmd_scan函数Idh.code\external\bluetooth\bluez\tools\hcitool.c

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. static struct {  
  2.     char *cmd;  
  3.     void (*func)(int dev_id, int argc, char **argv);  
  4.     char *doc;  
  5. } command[] = {//命令定义描述  
  6.     { "dev",    cmd_dev,    "Display local devices"                },  
  7.     { "inq",    cmd_inq,    "Inquire remote devices"               },  
  8.     { "scan",   cmd_scan,   "Scan for remote devices"              },  
  9.     { "name",   cmd_name,   "Get name from remote device"          },  
  10.     { "info",   cmd_info,   "Get information from remote device"   },  
  11.     { "spinq",  cmd_spinq,  "Start periodic inquiry"               },  
  12.     { "epinq",  cmd_epinq,  "Exit periodic inquiry"                },  
  13.     { "cmd",    cmd_cmd,    "Submit arbitrary HCI commands"        },  
  14.     { "con",    cmd_con,    "Display active connections"           },  
  15.     { "cc",     cmd_cc,     "Create connection to remote device"   },  
  16.     { "dc",     cmd_dc,     "Disconnect from remote device"        },  
  17.     { "sr",     cmd_sr,     "Switch master/slave role"             },  
  18.     { "cpt",    cmd_cpt,    "Change connection packet type"        },  
  19.     { "rssi",   cmd_rssi,   "Display connection RSSI"              },  
  20.     { "lq",     cmd_lq,     "Display link quality"                 },  
  21.     { "tpl",    cmd_tpl,    "Display transmit power level"         },  
  22.     { "afh",    cmd_afh,    "Display AFH channel map"              },  
  23.     { "lp",     cmd_lp,     "Set/display link policy settings"     },  
  24.     { "lst",    cmd_lst,    "Set/display link supervision timeout" },  
  25.     { "auth",   cmd_auth,   "Request authentication"               },  
  26.     { "enc",    cmd_enc,    "Set connection encryption"            },  
  27.     { "key",    cmd_key,    "Change connection link key"           },  
  28.     { "clkoff", cmd_clkoff, "Read clock offset"                    },  
  29.     { "clock",  cmd_clock,  "Read local or remote clock"           },  
  30.     { "lescan", cmd_lescan, "Start LE scan"                        },  
  31.     { "lecc",   cmd_lecc,   "Create a LE Connection",              },  
  32.     { "ledc",   cmd_ledc,   "Disconnect a LE Connection",          },  
  33.     { "dsn",    cmd_dsn,    "Try to get rid of scatternets",       },  
  34.     { NULL, NULL, 0 }  
  35. };  

2、 hcitool常用方法
(1)、hcitool帮助命令
hcitool –h

(2)、hcitool dev 显示本机MAC地址

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. root@android:/ # hcitool dev  
  2. hcitool dev  
  3. Devices:  
  4.         hci0    00:16:53:96:22:53  

(3)、hcitool inq

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. root@android:/ # hcitool inq  
  2. hcitool inq  
  3. Inquiring ...  
  4.         C4:6A:B7:21:79:C8       clock offset: 0x7e48    class: 0x5a020c  
  5.         1C:66:AA:66:68:2E       clock offset: 0x5e27    class: 0x5a020c  
  6.         AC:72:89:85:90:2A       clock offset: 0x13ec    class: 0x4a0100  
  7.         68:17:29:78:37:4A       clock offset: 0x5185    class: 0xff0104  
  8.         B0:C4:E7:65:A7:3A       clock offset: 0x267e    class: 0x5a020c<strong>  
  9. </strong>  

(4)、hcitool scan扫描周围设备

(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

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. 1|root@android:/ # hcitool clock  
  2. hcitool clock  
  3. Clock:    0x5ba67  
  4. Accuracy: 0.00 msec<strong>  
  5. </strong>  

二、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 

0 0
原创粉丝点击