Sunday, December 27, 2009

Android Bluetooth in Eclair


If you noticed the source code in Eclair branch, you will find few differences in Bluetooth function. There are three new git repositories for bluetooth. "bluez", "glib" and "hcidump", all of them are located in /external/bluetooth folder, not /external/bluez anymore.

bluez
android source: git://android.git.kernel.org/platform/external/bluetooth/bluez.git
Eclair is using bluez version 4.47 and the big difference would be bluez API. Since it has a lot of changes between bluez3 (android 1.6) and bluez4 (Android 2.0), we can tell from the documents in doc folder. Or we can use dbus-send to get the detailed information.



# dbus-send --system --type=method_call --print-reply --dest=org.bluez / org.bluez.Manager.DefaultAdapter
method return sender=:1.2 -> dest=:1.3
object path "/org/bluez/932/hci0"

# dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/932/hci0 org.freedesktop.DBus.Introspectable.Introspect


Also, bluetooth service name is changed in Eclair. It's "bluetoothd" now. Check init.rc in /system/core/rootdir.


service bluetoothd /system/bin/bluetoothd -d -n
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
# init.rc does not yet support applying capabilities, so run as root and
# let bluetoothd drop uid to bluetooth with the right linux capabilities
group bluetooth net_bt_admin misc
disabled

glib
android source: git://android.git.kernel.org/platform/external/bluetooth/glib.git
When we build bluez library, it would build glib as a static library.
GLib provides the core application building blocks for libraries and applications written in C. It provides the core object system used in GNOME, the main loop implementation, and a large set of utility functions for strings and common data structures. If you are interested in how bluez use glib, you can trace bluez source code.

new Bluetooth API
http://developer.android.com/guide/topics/wireless/bluetooth.html
About Bluetooth, Android website has a very good document. It lists the functions and example code.


Bluetooth
* Turn on/off Bluetooth
* Device and service discovery
* Connect to a remote device using RFCOMM and send/receive data
* Advertise RFCOMM services and listen for incoming RFCOMM connection


Bluetooth Chat application
What I am curious? It's related to using RFCOMM and send/receive data. In the beginning, I am not quite understand and I thought it's OBEX. After running Bluetooth Chat application, I know what it means now. I installed 0xlab experimental eclair image in Beagle board and installed Bluetooth chat example from Android. I also run a python script in my ubuntu machine and it's from pybluez. Then, I can chat between Beagle board and my laptop via Bluetooth. When we start to run Bluetooth Chat application, it would create a RFCOMM socket and set it to listen mode. We can retrieve the information from sdptool. Then other BT devices can connect to Android using RFCOMM protocol and set channel to the same one.


# sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Name: BluetoothChat
Service RecHandle: 0x10005
Service Class ID List:
UUID 128: fa87c0d0-afac-11de-8a39-0800200c9a66
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 30


From Collages

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.