Minisky

好记性不如个烂笔头,记一些有用的东西!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

【译】Android Bluetooth

Posted on 2010-08-31 01:17  Minisky  阅读(3381)  评论(0编辑  收藏  举报

蓝牙

Android蓝牙协议栈使用的是BlueZ,支持GAP, SDP, and RFCOMM规范,是一个SIG认证的蓝牙协议栈。

Bluez 是GPL许可的,因此Android的框架内与用户空间的bluez代码通过D-BUS进程通讯进行交互,以避免专有代码。

Headset和Handsfree(v1.5)规范就在Android框架中实现的,它是跟Phone App紧密耦合的。这些规范也是SIG认证的。

 

下面的图表提供了一个以库为导向的蓝牙栈视图。

实线框的是Android模块,红色虚线部分为合作伙伴指定模块(译者注:芯片商提供)。

 

下面的图表是以进程为导向视图:

 

移植

BlueZ是兼容蓝牙2.1的,可以工作在任何2.1芯片以及向后兼容的旧的蓝牙版本。有要有两个方面:

  • 串口驱动 UART driver
  • 蓝牙电源开/关 Bluetooth Power On/Off

串口驱动

BlueZ核心子系统使用hciattach守护进程添加你的指定硬件串口驱动。

例如,MSM7201A,这个文件是在drivers/serial/msm_serial.c。你还需要通过修改init.rc为hciattach来编辑命令行选项。

蓝牙电源开/关

蓝牙芯片的电源开关方法1.0和Post 1.0是不同的,具体如下:

  • 1.0:Android框架写0或1到/sys/modules/board_[PLATFORM]/parameters/bluetooth_power_on
  • Post 1.0:Android框架使用linux rfkill API,参考 arch/arm/mach-msm/board-trout-rfkill.c例子。

编译

编译Android打开蓝牙支持,添加下面这行内容到BoardConfig.mk。

    BOARD_HAVE_BLUETOOTH :=true

 

解决问题

调试

调试你的蓝牙实现,可以通过读跟蓝牙相关的logs(adb logcat)和查找ERROR和警告消息。Android使用Bluez,同时会带来一些有用的调式工具。下面的片段为了提供一个建议的例子: 

hciconfig -a  			# print BT chipset address and features. Useful to check if you can communicate with your BT chipset.
hcidump -XVt  			# print live HCI UART traffic.
hcitool scan  			# scan for local devices. Useful to check if RX/TX works.
l2ping ADDRESS  		# ping another BT device. Useful to check if RX/TX works.
sdptool records ADDRESS # request the SDP records of another BT device.

 

守护进程日志

hcid(STDOUT)和hciattach(STDERR)的守护进程日志缺省是被写到/dev/null。编辑init.rc和init.PLATFORM.rc在logwrapper下运行这些守护进程,把它们输出到logcat。

 

hciconfig -a 和 hcitool

如果你编译你自己的system.img,除了hcitool扫描不行,hciconfig -a是可以工作的,尝试安装固件到蓝牙芯片。XXX TBD

 

工具

BlueZ为调试和与蓝牙子系统通信提供很多设置命令行工具,包含下面这些:

hciconfig

hcitool

hcidump

sdptool

dbus-send

dbus-monitor

 

特性支持

这一部分提供在每个android版本中的蓝牙的一些变化,主要是一些性能参数上的东西,就不翻译了。

Android 1.0 release

Platform features
  • Based on Bluez 3.36 and Linux Kernel 2.6.25
  • Bluetooth 2.0+EDR host stack
  • Headset Profile 1.0 in Audio Gateway role
  • Handsfree Profile 1.5 in Audio Gateway role
    • Three-way calling
    • Phonebook over AT commands
Qualifications
  • QDID B014524: Host stack (SDP, L2CAP, GAP, RFCOMM, SPP)
  • QDID B014624: EPL for HTC Dream (HSP, HFP)
Example products
  • HTC Dream / T-Mobile G1

 

Android 1.1 release

No Bluetooth changes since 1.0

 

Android 1.5 release (cupcake)

Platform features

  • Based on Bluez 3.36 with Linux Kernel 2.6.27
  • Bluetooth 2.0+EDR host stack
    • Support for auto-pairing with '0000' devices
  • Headset Profile 1.1 in Audio Gateway role
  • Handsfree Profile 1.5 in Audio Gateway role
    • Three-way calling
    • Phonebook over AT commands
    • Volume synchronization
    • eSCO
    • Extensive bug fixes and compatibility improvements
  • Stereo Bluetooth (A2DP 1.2) in Source role
    • AVDTP 1.2 in Acceptor and Initiator roles
    • GAVDTP 1.0 in Acceptor and Initiator roles
    • 44.1 khz, stereo, software SBC codec
  • Remote Control (AVRCP 1.0) in Target role
    • AVCTP 1.3 in Target role
    • play/pause/stop/prev/next

Qualifications

  • QDID B015261: Host stack (SDP, L2CAP, GAP, RFCOMM, SPP, AVCTP, AVRCP, GAVDP, AVDTP, A2DP)
  • QDID B015262: EPL for HTC Sapphire (HSP, HFP)

Android 2.0/2.1 release (eclair)

Platform features

  • Based on Bluez 4.47 with Linux Kernel 2.6.29
  • Bluetooth 2.1+EDR host stack
    • Support for auto-pairing with '0000' devices
    • Support for Simple Secure Pairing
  • Headset Profile 1.1 in Audio Gateway role
  • Handsfree Profile 1.5 in Audio Gateway role
    • Three-way calling
    • Phonebook over AT commands
    • Volume synchronization
    • eSCO
    • Extensive bug fixes and compatibility improvements
  • Stereo Bluetooth (A2DP 1.2) in Source role
    • AVDTP 1.2 in Acceptor and Initiator roles
    • GAVDTP 1.0 in Acceptor and Initiator roles
    • 44.1 khz, stereo, software SBC codec
  • Remote Control (AVRCP 1.0) in Target role
    • AVCTP 1.3 in Target role
    • play/pause/stop/prev/next
  • Object Push Profile version 1.1
    • Adds ability to transfer pictures, videos
    • Transfer of contacts using vCard is not supported in this release.
  • Phone Book Address Profile version 1.0
    • Phone Book Server Equipment (PSE) role supported
  • Using Java Bluetooth APIs, an Android application can peform the following:
    • Scan for other Bluetooth devices
    • Query the local Bluetooth adapter for paired Bluetooth devices
    • Establish RFCOMM channels
    • Connect to other devices through service discovery
    • Transfer data to and from other devices
    • Manage multiple connections
  • Support for Bluetooth enabled car and desk docks
    • Framework support for routing Phone Call Audio and A2DP streaming using car and desk docks.

Android 2.2 release (Froyo)

Platform features

  • Based on Bluez 4.47 with Linux Kernel 2.6.32
  • No new profiles added.
  • Added ability to share contacts using vCard
  • Added ability to export all contacts - useful to transfer contacts to car kits
  • Improved compatibility with headsets and car kits.
 

Future releases

This section offers a rough guide of which features the team is developing for the next release. This feature list may change without notice. It isn't possible to post scheduling advice to the mailing lists.

  • More profiles...
  • Improved compatibility with headsets and car kits
  • Bluetooth emulator support
  • Bluetooth Low Energy

译者注: 这里请大家注意一下红色部分,难道将来模拟器可以使用BT?

 

开发须知

HID支持

Tethering - DUN and PAN 支持

 

最后把官方链接附上:

http://source.android.com/porting/bluetooth.html