Patch: fix bluetooth for hci usb bluetooth

3,901 views
Skip to first unread message

André Vitor

unread,
Jan 17, 2015, 11:44:39 PM1/17/15
to andro...@googlegroups.com
Hi everyone, the following patches make bluetooth functional to all generic usb bluetooth devices and one more specific (Realtek 8723AU) which my tablet have.

To make this work the bluetooth required permissions to access usb device. (I don't know much about permissions on android. If I did something bad please tell me)

This is needed because our bluetooth is using a module created by broadcom which allow generic usb bluetooth to work as a main bluetooth device for android.
Inside this module it's used libusb to open and read usb devices, that's why usb permissions are needed.

Path to apply.

external/bluetooth/bluedroid
0001-bluedroid-add-new-usb-bluetooth-device

packages/apps/Bluetooth
0001-bluetooth-add-permission-to-access-usb-devices

init.sh
0001-bluetooth-disable-rfkill-for-usb-bluetooth

frameworks/base
0001-permissions-associate-android.permission.USB_ACCESS-
0001-usb-add-new-permission-to-grant-access-to-usb-device

This was tested on android kitkat and lollipop, working on both.

File transfer and my bluetooth keyboard are working perfectly. (This is what I have to test). 

There's a few little bugs:

*To disable bluetooth is needed to turn it off using settings menu and then use command "am force-stop com.android.bluetooth" a few times. (only on kitkat version)
*When you enable bluetooth it may start restarting until something is paired/connected. (both versions)
*For some reason when I try to pair/transfer to my tablet, my phone shows me the name of my bluetooth on windows. (only on lollipop version)
0001-bluedroid-add-new-usb-bluetooth-device.patch
0001-bluetooth-add-permission-to-access-usb-devices.patch
0001-bluetooth-disable-rfkill-for-usb-bluetooth.patch
0001-permissions-associate-android.permission.USB_ACCESS-.patch
0001-usb-add-new-permission-to-grant-access-to-usb-device.patch

Chih-Wei Huang

unread,
Jan 18, 2015, 10:21:39 PM1/18/15
to Android-x86
Thank you for the nice work.
Patches applied.

BTW, do you have any idea to fix 'unable to turn off Bluetooth'
issue properly in kitkat-x86? (except the am force-stop magic).
> --
> You received this message because you are subscribed to the Google Groups
> "Android-x86" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-x86...@googlegroups.com.
> To post to this group, send email to andro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/android-x86.
> For more options, visit https://groups.google.com/d/optout.



--
Chih-Wei
Android-x86 project
http://www.android-x86.org

André Vitor

unread,
Jan 20, 2015, 8:58:12 PM1/20/15
to andro...@googlegroups.com
I don't have the fix yet, but I have a guess about what's the problem. I compared the logs between Kitkat and Lollipop versions and before Bluetooth turn off in Lollipop, it shows those messages:

GKI_LINUX( 6650): gki_task task_id=0 [BTU] terminating
GKI_LINUX( 6650): GKI_exit_task 0 done
GKI_LINUX( 6650): GKI_shutdown(): task [BTU] terminated

and then it turns off:
 
BluetoothAdapterState ( 6650): CURRENT_STATE=PENDING, MESSAGE = DISABLED, isTurningOn=false, isTurningOff=true

Kitkat version doesn't shows this messages, what I can assume that its BTU is not being terminated, causing to happen this:

BluetoothAdapterState ( 3698): CURRENT_STATE=PENDING, MESSAGE = DISABLED_TIMEOUT, isTurningOn=false, isTurningOff=true

Justin G

unread,
Apr 26, 2015, 9:31:01 PM4/26/15
to andro...@googlegroups.com
How do you apply this fix?

Mexus

unread,
Apr 27, 2015, 2:51:49 AM4/27/15
to andro...@googlegroups.com
git apply -v file.patch

Mario Holzinger

unread,
Apr 29, 2015, 1:13:56 AM4/29/15
to andro...@googlegroups.com
Path to apply.

external/bluetooth/bluedroid
0001-bluedroid-add-new-usb-bluetooth-device


This was tested on android kitkat and lollipop, working on both.


Tried to apply all the pathes but in my lollipop repo I do not have an usb.c in 
external/bluetooth/bluedroid/hci/src/

is this a copy of an kernel module or is this only existing in kitkat?

BTW.:
I try to activate my Marvell WiFI/BT USB chip by copy the corresponding kernel module entry in
/kernel/module/Bluetooth.../btusb.c
from the blacklist section into the white list section
but without success

BT is still switching ON/OFF randomly

Also I tried to re-enable btusb & bluetooth kernel modules that was blacklisted in
init.sh & blacklist.sh
but that also have no effect to my Surface Pro 2 USB BT chip

regards
Mario

André Vitor

unread,
Apr 29, 2015, 2:35:07 AM4/29/15
to andro...@googlegroups.com
Those patches were already to the android-x86 source code. There is no needed to apply for your own.

BT is still switching ON/OFF randomly

This is a known issue that I have no idea how to fix.

It probably has something to do with Kernel's Groups Permission. (cgroup)
Or not, I don't know.

Chih-Wei Huang

unread,
Apr 29, 2015, 2:42:20 AM4/29/15
to Android-x86
2015-04-29 14:35 GMT+08:00 André Vitor <andr...@gmail.com>:
> Those patches were already to the android-x86 source code. There is no
> needed to apply for your own.

Oh, due to some reasons the bluetooth patches have not
been applied to the current lollipop-x86 5.1 codebase yet.
(they have been applied to the 5.0 codebase before)

Anyway, thanks for the reminding.
I'll do that later.

Povilas Staniulis

unread,
Apr 29, 2015, 8:57:55 AM4/29/15
to andro...@googlegroups.com
Is there a way to make Bluetooth work with serial HCI, eg. on T100TA ?

Chih-Wei Huang

unread,
Apr 29, 2015, 9:55:48 PM4/29/15
to Android-x86
2015-04-29 20:57 GMT+08:00 Povilas Staniulis <wdmo...@gmail.com>:
> Is there a way to make Bluetooth work with serial HCI, eg. on T100TA ?

This is the question I hope to know.
The original bluedroid should work with serial hci.
But probably I didn't configure it correctly...
What I did is add /system/etc/bluetooth/bt_vendor.conf
with content:

---------------------------
# UART device port where Bluetooth controller is attached
UartPort = /dev/ttyS1

# Firmware patch file location
FwPatchFilePath = /system/lib/firmware/
---------------------------

Is ttyS1 the correct port?
But I've tried all ttyS0 - ttyS3, none works.

If anyone has experience to configure serial hci
bluetooth for lollipop, please share the steps.

Povilas Staniulis

unread,
Apr 29, 2015, 10:52:41 PM4/29/15
to andro...@googlegroups.com
I'm still on KitKat (don't want to switch to Lollipop, due to lack of
ARM support), don't know if matters.

On traditional distros, T100's Bluetooth serial port is initialized with
command:
hciattach /dev/ttyS4 bcm2035 921600 flow
(Source code of hciattach with bcm2035 init code:
http://code.metager.de/source/xref/linux/bluetooth/bluez/tools/hciattach.c)

But this command comes from BlueZ stack and there's a device specific
init routine for bcm2035 in hciattach utility (see link above).
BlueZ does support Android and I've found some instructions in XDA forum
on how replace bluedroid with bluez.
(Link: http://forum.xda-developers.com/showthread.php?t=2640723 if
anyone is interested)

Although I wish it could be doable with existing code.

I will need to look into the code when I have time.

Chih-Wei Huang

unread,
Apr 29, 2015, 11:07:11 PM4/29/15
to Android-x86
I assume hciattach is only used by bluez stack.
But instead of revert back to use bluez,
we should follow AOSP to use bluedroid now.

Any guideline for bluedroid porting?

Povilas Staniulis

unread,
Apr 29, 2015, 11:31:20 PM4/29/15
to andro...@googlegroups.com
I'm not suggesting to revert, but I'll probably try to build bluez
myself anyway (just as a challenge).

> Any guideline for bluedroid porting?
>
Well, there is some device specific init code in hciattach.

Unfortunately, I have limited experience in working with Android
userspace code. I'll have a look at bluedroid code, but I'm not sure if
I will be able to make out anything.

chen wade

unread,
May 11, 2015, 4:40:40 AM5/11/15
to andro...@googlegroups.com
I manually start com.android.bluetooth/.pbap.BluetoothPbapService will let bluetooth work after turn off it.
My steps are:
1. turn on bluetooth: it works after startup system.
2. turn off bluetooth: it will failed ....always retry restart bluetooth....
3. ctrl-alt-F1 to command mod, and then...
4. # am startservice com.android.bluetooth/.pbap.BluetoothPbapService
5. ctrl-alt-F7 switch to system UI, and will popup a message box: "Unfortunately, Bluetooth Share has stopped".
    ==> click ok to skip this message.
6. wait...or turn on bluetooth again....: it works!

But I don't know how to patch the code.

Povilas Staniulis於 2015年4月30日星期四 UTC+8上午11時31分20秒寫道:

Justin G

unread,
May 11, 2015, 5:43:16 PM5/11/15
to andro...@googlegroups.com
this allows bluetooth to function?

--
You received this message because you are subscribed to a topic in the Google Groups "Android-x86" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-x86/tciLJN5q13w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-x86...@googlegroups.com.

chen wade

unread,
May 12, 2015, 5:08:02 AM5/12/15
to andro...@googlegroups.com
Please patch packages/apps/Bluetooth/

diff --git a/src/com/android/bluetooth/btservice/AdapterState.java b/src/com/android/bluetooth/btservice/AdapterState.java
index 5f9c30b..037d973 100755
--- a/src/com/android/bluetooth/btservice/AdapterState.java
+++ b/src/com/android/bluetooth/btservice/AdapterState.java
@@ -344,7 +344,7 @@ final class AdapterState extends StateMachine {
                     if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = DISABLE_TIMEOUT, isTurningOn=" + isTurningOn + ", isTurningOff=" + isTurningOff);
                     errorLog("Error disabling Bluetooth");
                     mPendingCommandState.setTurningOff(false);
-                    transitionTo(mOnState);
+                    transitionTo(mOffState);
                     notifyAdapterStateChange(BluetoothAdapter.STATE_ON);
                     break;
                 default:



chen wade於 2015年5月11日星期一 UTC+8下午4時40分40秒寫道:

Chih-Wei Huang

unread,
May 12, 2015, 5:17:33 AM5/12/15
to Android-x86
2015-05-12 17:08 GMT+08:00 chen wade <wad...@gmail.com>:
> Please patch packages/apps/Bluetooth/
>
> diff --git a/src/com/android/bluetooth/btservice/AdapterState.java
> b/src/com/android/bluetooth/btservice/AdapterState.java
> index 5f9c30b..037d973 100755
> --- a/src/com/android/bluetooth/btservice/AdapterState.java
> +++ b/src/com/android/bluetooth/btservice/AdapterState.java
> @@ -344,7 +344,7 @@ final class AdapterState extends StateMachine {
> if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE =
> DISABLE_TIMEOUT, isTurningOn=" + isTurningOn + ", isTurningOff=" +
> isTurningOff);
> errorLog("Error disabling Bluetooth");
> mPendingCommandState.setTurningOff(false);
> - transitionTo(mOnState);
> + transitionTo(mOffState);
> notifyAdapterStateChange(BluetoothAdapter.STATE_ON);
> break;
> default:

Please explain the rationale of the patch.
What's the symptom, root cause, ...?

Justin G

unread,
May 12, 2015, 9:10:17 AM5/12/15
to andro...@googlegroups.com
How exactly is this patch applied? Do you type something? Or is there a download?

Also will still stop the bluetooth service from being disabled upon the emulator starting up?


--
- Justin Gray
Sent from my iPhone

chen wade

unread,
May 12, 2015, 10:29:03 PM5/12/15
to andro...@googlegroups.com
Disable timeout should switch to off state but not on state.

Chih-Wei Huang於 2015年5月12日星期二 UTC+8下午5時17分33秒寫道:

Bernard

unread,
May 21, 2015, 5:46:58 PM5/21/15
to andro...@googlegroups.com
Does this patch fix bluetooth or have any efficacy?
Reply all
Reply to author
Forward
0 new messages