BBBAndroid with USB Bluetooth Adapter Support

Has anyone managed to enable USB Bluetooth Adapter Support in BBBAndroid. I’ve read the Android > 4.2 can support USB bluetooth if built correctly.

This is what I’ve tried so far:

I set the following in “device/ti/beagleboneblack/BoardConfig.mk”
BOARD_HAVE_BLUETOOTH := true

And the following in “kernel/.config”
CONFIG_BT=y
CONFIG_BT_RFCOMM=y
CONFIG_BT_RFCOMM_TTY=y
CONFIG_BT_BNEP=y
CONFIG_BT_BNEP_MC_FILTER=y
CONFIG_BT_BNEP_PROTO_FILTER=y
CONFIG_BT_HIDP=y

Well, Bluetooth being recognized by the kernel and Bluetooth being accessible via the API are two very different animals. Enabling the Bluetooth stack in the kernel, as well as the device drivers, is the first step. Once that portion is done, your Bluetooth device must be registered within the Android HAL to access it from the API. If you take a look in the BBBAndroid source tree in hardware/libhardware/include/hardware/bluetooth.h, you can see the interface functions used to bridge the API to a Bluetooth device. I have not checked into whether you can bypass all of this by using a USB Bluetooth device, though. For example, if you are using a Bluetooth keyboard with a USB/Bluetooth dongle plugged into the BBB, will the BBB see it as a Bluetooth device or a USB keyboard? If you can leverage the USB drivers and have the Bluetooth functionality of your device be “invisible” to Android, then you’re in luck. But, if you want to use the full Bluetooth API to manage your device, BBBAndroid is missing the portion of the HAL needed to make that happen.

What is the nature of the Bluetooth device that you are using?

Hi Andrew,

Thanks for replying.

I have read that. I’m currently compiling BBBAndroid with Android-x86’s bluedroid which appears to have USB BT support.

http://git.android-x86.org/?p=platform/external/bluetooth/bluedroid.git;a=summary

I’d like to use rfcomm and audio, rfcomm is more important though. I’m open to other hardware suggestions too.

My requirements for my little pet project are:

Android
Resistive touch screen
Bluetooth
USB Host
RTC
Audio out

BTW I see your attending SU. Great school, I attended a few courses there and just moved away from the area.

Thanks again,
Keith

Forgot to ask. How do I get my kernel options to stick in the BBBAndroid build process? My manual settings keep getting reverted when I build it.

Keith

If you get bluedroid working and it is a viable approach, let me know and I’ll add it into the manifest as an external repo for BBBAndroid. Right now, I don’t have the cgroups set up properly for audio, so I’m not sure how well audio support is working via HDMI or audio cape. Bluetooth is a question mark right now, but the other pieces work OK. I’ve used the Adafruit DS1307 RTC breakout board via I2C to set the system clock during the kernel boot process, so that will be transparent to Android.

If you take a look at the top-level makefile, you’ll see these lines:

kernel_not_configured := $(wildcard kernel/.config)

ifeq ($(TARGET_PRODUCT), beagleboneblack)
CLEAN_RULE = kernel_clean clean
rowboat: kernel_build
endif

kernel_build: droid
ifeq ($(strip $(kernel_not_configured)),)
$(MAKE) -C kernel ARCH=arm am335x_evm_android_defconfig
endif

That “am335x_evm_android_defconfig” is getting selected because the script isn’t finding your kernel/.config file. I guess this isn’t working properly for you for some reason? Anyway, you can remove that defconfig from that line or backup/modify that defconfig in kernel/arch/arm/configs.

I have been at SU for so long now that I have a mailbox in the EECS department and potential PhD students are brought by my office to ask questions during their campus visits. My usual advice to them is to dress warm and invest in a high-quality snow shovel.

I’ll let you know how it goes with bluedroid. And thanks for the help and information. I may have some questions when I get to adding the RTC.

I spent the first 35 years of my life in the Syracuse area, don’t miss the snow. This fall I moved to Colorado Springs :slight_smile:

It built without errors. I’m having trouble with the kernel though. I made sure kernel/.config and am335x_evm_android_defconfig both had CONFIG_BT=y. I re-ran make in the root of BBBAndroid. As soon as I answered the questions about the USB gadget driver it reverted to CONFIG_BT=m along with the other options I modified. Any ideas Andrew?

Keith

Try configuring the kernel using the “menuconfig” target (like “make menuconfig” in the makefile). I suspect that you are manually setting something in the .config and there are other settings that conflict with it. Normally, these conflicts are managed via the Kconfig or menuconfig interface (i.e. it just takes options away from you or forces some items to be modules). Make sure that the options that you are setting are actually all compatible with each other. If all else fails, you can manually insmod modules in the init.{ro.hardware}.rc file inside of Android during boot.

That was it RFKILL needed to be built in also. Rebuilding.

Getting closer. I have everything built and running bdt, produces a logcat message that there is no supported device. This is with two different adapters. I’ve posted some questions to the android-x86 list including which adapters are supported. I think I’m getting close.

Also I found that there is a android-bluez project that is a drop in replacement for bluedroid. I may try that next.

https://01.org/bluez-android

Hi Keith,

I am working on similar project and very interested your progress.

I have a Knivao BTD-400 Bluetooth USB adapter (it uses Broadcom BCM20702A0 chip). My work is based on the TI stock Beaglebone Black android code base (JB 4.2 Kernel 3.2.0). I noticed that the BCM20702A0 is supported by default.

By adding the VID and PID of the USB adapter to the btusb_table in btusb.c and perform an echo in android shell like: echo “0x05ac, 0x21e8” > /sys/bus/usb/driver/btusb/new_id, the hci0 interface will shown up under /sys/class/bluetooth/hci/hci0

Then I can the hciconfig to bring hci0 up / down and use hcitool to do scan and detect other bluetooth devices (hciconfig and hcitool are ported from ICS). It seems that the USB bluetooth device at kernel level is alive. As you know in JB4.2 it seems that the UART interface is the by-default interface between the android and kernel. Basically I am not able to enable the bluetooth from android. The interface is missing. I am trying to figure out how to bridge the gap here.

It seems that you made progress on the android side but couldn’t detect supported device. I wonder if you could share the information on porting and building the bluedroid ( assuming using android-x86).

Thanks,

Lei

Hi,

I’m currently trying two approaches:

  1. Integrating android-x86’s bluedroid

  2. Using android-bluez as a replacement to bluedroid

Neither is functional yet :frowning: I’ll report back when I have something working.

Keith

I think I’m getting close with integrating android-bluez. I have bluetoothd ‘seeing’ my adapter however dies at connecting to IPC. I’ve posed the question to the bluez list.

Here is a logcat with debugging enabled. I’ve googled the errors and have had no luck.

I/bluetoothd( 1072): Bluetooth daemon 5.28

D/bluetoothd( 1072): external/bluetooth/bluez/android/main.c:set_capabilities() Caps: eff: 0x3400, perm: 0x3400, inh: 0x0

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:bt_bluetooth_start() index -1

I/bluetoothd( 1072): Starting SDP server

D/bluetoothd( 1072): external/bluetooth/bluez/android/main.c:main() Entering main loop

I/bluetoothd( 1072): mgmt_if: [0xffff] command 0x0001

I/bluetoothd( 1072): mgmt_if: < 01 00 ff ff 00 00 …??..

I/bluetoothd( 1072): mgmt_if: > 01 00 ff ff 06 00 01 00 00 01 07 00 …??..

I/bluetoothd( 1072): mgmt_if: [0xffff] command 0x0001 complete: 0x00

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:read_version_complete()

I/bluetoothd( 1072): Bluetooth management interface 1.7 initialized

I/bluetoothd( 1072): Kernel connection control will be used

I/bluetoothd( 1072): mgmt_if: [0xffff] command 0x0003

I/bluetoothd( 1072): mgmt_if: < 03 00 ff ff 00 00 …??..

I/bluetoothd( 1072): mgmt_if: > 01 00 ff ff 07 00 03 00 00 01 00 00 00 …??..

I/bluetoothd( 1072): mgmt_if: [0xffff] command 0x0003 complete: 0x00

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:read_index_list_complete()

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:read_index_list_complete() Number of controllers: 1

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0004

I/bluetoothd( 1072): mgmt_if: < 04 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 1b 01 04 00 00 e9 36 36 e7 18 00 03 …?66?..

I/bluetoothd( 1072): mgmt_if: 0f 00 bf 10 00 00 90 00 00 00 00 00 00 42 43 4d …?..BCM

I/bluetoothd( 1072): mgmt_if: 32 30 34 35 42 33 00 00 00 00 00 00 00 00 00 00 2045B3…

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 .

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0004 complete: 0x00

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:read_info_complete()

D/bluetoothd( 1072): external/bluetooth/bluez/src/sdpd-service.c:register_device_id() Adding device id record for 0002:1d6b:0247:051c

D/bluetoothd( 1072): external/bluetooth/bluez/src/sdpd-service.c:add_record_to_server() Adding record with handle 0x10001

D/bluetoothd( 1072): external/bluetooth/bluez/src/sdpd-service.c:add_record_to_server() Record pattern UUID 00001002-0000-1000-8000-00805f9

D/bluetoothd( 1072): external/bluetooth/bluez/src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000113a-0000-1000-8000-00805f9

D/bluetoothd( 1072): external/bluetooth/bluez/src/sdpd-service.c:add_record_to_server() Record pattern UUID 0000113b-0000-1000-8000-00805f9

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:load_ltks() ltks 0

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:load_irks() irks 0

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:load_link_keys() keys 0

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x000e

I/bluetoothd( 1072): mgmt_if: < 0e 00 00 00 02 00 02 0c …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 06 00 0e 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x000e complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0011

I/bluetoothd( 1072): mgmt_if: < 11 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: 00 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 06 00 11 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0011 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0034

I/bluetoothd( 1072): mgmt_if: < 34 00 00 00 07 00 00 00 00 00 00 00 00 4…

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 0a 00 34 00 00 00 00 00 00 00 00 00 …4…

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0034 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0018

I/bluetoothd( 1072): mgmt_if: < 18 00 00 00 01 00 01 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 03 00 18 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0018 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0028

I/bluetoothd( 1072): mgmt_if: < 28 00 00 00 08 00 02 00 6b 1d 47 02 1c 05 (…k.G…

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 03 00 28 00 00 …(…

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0028 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0010

I/bluetoothd( 1072): mgmt_if: < 10 00 00 00 11 00 fb 34 9b 5f 80 00 00 80 00 10 …?4._…

I/bluetoothd( 1072): mgmt_if: 00 00 00 12 00 00 00 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 06 00 10 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0010 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0010

I/bluetoothd( 1072): mgmt_if: < 10 00 00 00 11 00 fb 34 9b 5f 80 00 00 80 00 10 …?4._…

I/bluetoothd( 1072): mgmt_if: 00 00 3b 11 00 00 00 …;…

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 06 00 10 00 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0010 complete: 0x00

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0013

I/bluetoothd( 1072): mgmt_if: < 13 00 00 00 02 00 00 00 …

I/bluetoothd( 1072): mgmt_if: > 02 00 00 00 03 00 13 00 0c …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x13 status: 0x0c

I/bluetoothd( 1072): Failed to load LTKs: Not Supported (0x0c)

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0030

I/bluetoothd( 1072): mgmt_if: < 30 00 00 00 02 00 00 00 0…

I/bluetoothd( 1072): mgmt_if: > 02 00 00 00 03 00 30 00 0c …0…

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x30 status: 0x0c

I/bluetoothd( 1072): Failed to load IRKs: Not Supported (0x0c)

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0012

I/bluetoothd( 1072): mgmt_if: < 12 00 00 00 03 00 00 00 00 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 03 00 12 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0012 complete: 0x00

D/bluetoothd( 1072): external/bluetooth/bluez/android/bluetooth.c:load_link_keys_complete() status 0

I/bluetoothd( 1072): Adapter initialized

D/bluetoothd( 1072): external/bluetooth/bluez/android/ipc.c:cmd_connect_cb()

E/bluetoothd( 1072): IPC: command socket connect failed

I/bluetoothd( 1072): Switching controller off

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0005

I/bluetoothd( 1072): mgmt_if: < 05 00 00 00 01 00 00 …

I/bluetoothd( 1072): mgmt_if: > 01 00 00 00 07 00 05 00 00 90 00 00 00 …

I/bluetoothd( 1072): mgmt_if: [0x0000] command 0x0005 complete: 0x00

D/bluetoothd( 1072): external/bluetooth/bluez/android/main.c:cleanup_services()

I/bluetoothd( 1072): Stopping SDP server

I/bluetoothd( 1072): Exit

OK, this is the place to start. A socket isn’t being created properly. That means that either the permissions aren’t correct or the call used to create/interact with the socket is not supported. The Bionic libc replacement does not implement a number of Linux kernel system calls because those system calls are not used under Android. For example, shared memory or message queue syscalls aren’t implemented because all IPC should be routed through Binder. My guess is that you are running into something like this (section 1.2):

http://forum.xda-developers.com/showthread.php?t=2640723

The epoll_create1 syscall is not implemented by default in Bionic, so making an epoll_create1() call in Bionic results in an immediate failure. Try dumping out logcat info at that error point with the errno value after the failed function call in cmd_connect_cb(). I bet that it is calling a Bionic function that doesn’t generate the appropriate syscall to the kernel.

Hi Andrew,

I did hand patch epoll_create1() into bionic. The above was a logcat,
how do I get the errno value?

Thanks,
Keith

Immediately after any failed POSIX call, the errno global variable (an integer) is set. Just include the errno.h header in the file making the failed call to get access to the errno variable. You can see how the logcat message is being generated in that same file (usually via a system() call to "logcat" or a C++ stream to LOG(INFO) or whatever.

Andrew

Oh ok I see. I'll give it a try.

Thanks,
Keith

Ok, apparently my problem may be because I’m running bluetoothd by hand and the socket isn’t created.

However I did get 111, connection refused.

Here is a complete logcat and my init files.

init-current.zip (47.6 KB)

I’ve made a lot of progress with the help of the bluez team. It looks like my problem is that Android thinks its running in an emulator.

Using haltest from bluez everything works. haltest actually goes through Android bluetooth HAL.

Andrew any idea on why it would think your kernel is for an emulator?

Thanks,
Keith

Yes, there is a kernel command line option that is passed to the kernel in the uEnv.txt file that says so (qemu=1, I think?). It has been a while, but I believe this is necessary to emulate the OpenGL ES calls. Otherwise, it all crashes constantly because there isn't OpenGL ES support. You can try removing that option, though, and see how it works for you. I originally added that in for the 4.2.2 JellyBean build from Rowboat, though we might get lucky and have it work without it from the 4.4.4 KitKat build from AOSP.

Andrew