Bluez相关工具的使用

对于Bluez的使用,有很多辅助工具可以使用,这些工具主要在Bluez-utils/tools 目录下。

 

1        Bccmd
Bccmd是用来和CSR的芯片进行BCCMD(Bluecore command protocol)通讯的一个工具。BCCMD并非蓝牙协议栈的标准,而是CSR芯片的专属协议

NAME
       bccmd - Utility for the CSR BCCMD interface

SYNOPSIS
       bccmd
       bccmd [-t <transport>] [-d <device>] <command> [<args>]
       bccmd [-h --help]

DESCRIPTION
       bccmd  issues  BlueCore commands to Cambridge Silicon Radio devices. If
       run  without  the  <command>  argument,  a  short  help  page  will  be
       displayed.

OPTIONS
       -t <transport>
              Specify the communication transport. Valid options are:

              HCI    Local device with Host Controller Interface (default).

              USB    Direct USB connection.

              BCSP   Blue Core Serial Protocol.

              H4     H4 serial protocol.

              3WIRE  3WIRE protocol (not implemented).

       -d <dev>
              Specify  a  particular  device  to operate on. If not specified,
              default is the first available  HCI  device  or  /dev/ttyS0  for
              serial transports.

COMMANDS
       builddef
              Get build definitions

       keylen <handle>
              Get current crypt key length

       clock  Get local Bluetooth clock

       rand   Get random number

       chiprev
              Get chip revision

       buildname
              Get the full build name

       panicarg
              Get panic code argument

       faultarg
              Get fault code argument

       coldreset
              Perform cold reset

       warmreset
              Perform warm reset

       disabletx
              Disable TX on the device

       enabletx
              Enable TX on the device

       singlechan <channel>
              Lock radio on specific channel

       hoppingon
              Revert to channel hopping

       rttxdata1 <decimal freq MHz> <level>
              TXData1 radio test

       radiotest <decimal freq MHz> <level> <id>
              Run radio tests, tests 4, 6 and 7 are transmit tests

       memtypes
              Get memory types

       psget [-r] [-s <stores>] <key>
              Get value for PS key.  -r sends a warm reset afterwards

       psset [-r] [-s <stores>] <key> <value>
              Set value for PS key.  -r sends a warm reset afterwards

       psclr [-r] [-s <stores>] <key>
              Clear value for PS key.  -r sends a warm reset afterwards

       pslist [-r] [-s <stores>]
              List all PS keys.  -r sends a warm reset afterwards

       psread [-r] [-s <stores>]
              Read all PS keys.  -r sends a warm reset afterwards

       psload [-r] [-s <stores>] <file>
              Load  all  PS  keys  from  PSR  file.   -r  sends  a  warm reset
              afterwards

       pscheck [-r] [-s <stores>] <file>
              Check syntax of PSR file.  -r sends a warm reset afterwards

 

 

查询CSR的BCCMD相关的文档,可以找到具体的含义如下:

0x0000 Default

0x0008 psram

0x0001 psi

0x0002 psf

0x0004 psrom

0x0003 psi then psf

0x0007 psi, psf then psrom

0x0009 psram then psi

0x000b psram, psi then psf

0x000f psram, psi, psf then psrom

 

CSR的蓝牙芯片中,PSKEY可能存储在 rom flash eeprom ram等介质里,这里的数值指明了psset/get命令操作PSKEY时所针对的存储介质及其优先顺序,通常我们会用 –s 0x0 或 –s “default” 来使用该命令,0x0的含义与0xf一样。

  

基本上来说,所修改的都是位于psram中的pskey,此外,pskey修改以后要起作用,还要一并使用 –r参数,或直接用warmreset命令将蓝牙芯片进行warm reset。

 

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

 

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

 

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

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

 

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

 

对于type BCSP来说,它的初始化代码只做了一件事,就是完成BCSP协议的同步操作,它并不对蓝牙芯片做任何的pskey的设置。同步操作的具体流程和规范可以参考CSR的相关文档: BCSP Link Establishment Protocol

 

3         Hcidump
Hcidump不在bluez-utils包里,而是在单独的hcidump包里。主要用来分析捕获和分析HCI数据包,如果使用bluez过程中出了什么问题,用hcidump往往可以发现一些出错的线索,原因。 参数很多,基本上hcidump –X –V 就可以帮你获得详细的经过格式解析的数据包。同时Hcidump可以使用hcidump --save-file=/directory/xxx.cfa命令存成cfa文件,就可以使用Frontline FTS4BT Viewer工具查看相应的蓝牙包

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值