• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE] How to port Bluez to Kitkat, Lollipop & Marshmallow

Search This thread

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,342
Hong Kong
Ok, Managed to learn through my failures. I now have working backported drivers however something weird is going on. My process is as follows:

Code:
modprobe hci_uart
modprobe Bluetooth
echo "1" > /sys/class/rfkill/frkill0/state
hciattach /dev/ttySAC0 bcm43xx 4000000
hciconfig hci0 up

But here is the weird part. If I do a hciconfig -a hci0 I get this

Code:
hciconfig -a hci0
hci0:   Type: BR/EDR  Bus: UART
        BD Address: 43:34:B0:00:00:00  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:7419 acl:37 sco:0 events:151 errors:0
        TX bytes:2834 acl:36 sco:0 commands:75 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'BCM4334B0 37.4MHz Class1.5 Samsung D2'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 4.0 (0x6)  Revision: 0x40f
        LMP Version: 4.0 (0x6)  Subversion: 0x410d
        Manufacturer: Broadcom Corporation (15)
Look at the BD address, its a default value. If I go any further to start bluez I get a Bluetooth address mismatch

I have no idea what is wrong with it, I am able to scan with the hcitool and get devices back and ping them with l2ping so the chip is working. Anyone have any ideas? Ive tried to set the address with hciattach with no luck

Boardcom chips have bluedroid support. I assume you are trying to test bluez. I didn't try other chips before. Other than the material already posted, there would be little to help.I suppose you had followed the bluetooth.c in your device tree. The sequence should init your chip properly.
The example from Bluez for Nexus4 might be a place for you to look into.
I remember, there is the program (something like bdAddrLoader) starting in init.mako.rc. I think it read a file in /efs (or similar partition) for the bdadress. Most of the devices share the same mac address from WiFi.
Take a look at your old device tree's init.<>.rc. See if there is similar code.

Good luck!
 

reekotubbs

Senior Member
Nov 17, 2008
838
264
Boardcom chips have bluedroid support. I assume you are trying to test bluez. I didn't try other chips before. Other than the material already posted, there would be little to help.I suppose you had followed the bluetooth.c in your device tree. The sequence should init your chip properly.
The example from Bluez for Nexus4 might be a place for you to look into.
I remember, there is the program (something like bdAddrLoader) starting in init.mako.rc. I think it read a file in /efs (or similar partition) for the bdadress. Most of the devices share the same mac address from WiFi.
Take a look at your old device tree's init.<>.rc. See if there is similar code.

Good luck!

Hello daniel_hk, I hope you are still working on this. Can we just flash this via cwm?
 

Shrukul

Senior Member
Mar 2, 2014
178
399
26
Hubli
@daniel_hk Hi! I am trying to port bluez to cm11 for my Samsung Galaxy Grand Quattro (msm7x27a)... I did follow all your steps except a few...

1. Whenever i include your Android.mk file in external/bluez/tools i get an error while compiling ( module XXXX already defined in external/bluez).. Is it necessary to include the Android.mk file or is it fine NOT to include it...

2. I am a newbie and i dont have much knowledge in kernels (Actually i have never really touched kernel sources,just device trees and all), So as far as i know, it seems that backporting kernel is necessary to get bluetooth to work ( Since my kernel version is 3.4), Can you please explain how exactly to backport.....??
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,342
Hong Kong
@daniel_hk Hi! I am trying to port bluez to cm11 for my Samsung Galaxy Grand Quattro (msm7x27a)... I did follow all your steps except a few...

1. Whenever i include your Android.mk file in external/bluez/tools i get an error while compiling ( module XXXX already defined in external/bluez).. Is it necessary to include the Android.mk file or is it fine NOT to include it...

2. I am a newbie and i dont have much knowledge in kernels (Actually i have never really touched kernel sources,just device trees and all), So as far as i know, it seems that backporting kernel is necessary to get bluetooth to work ( Since my kernel version is 3.4), Can you please explain how exactly to backport.....??
1. Bluez has updated a lot. Some of the tools already included in android/Android.mk. You need to remove the one in my tools/Android.mk

2. Without the kernel backport, Bluez won't work. So you must back port the kernel first.

Good luck!
 
  • Like
Reactions: Shrukul

Shrukul

Senior Member
Mar 2, 2014
178
399
26
Hubli
1. Bluez has updated a lot. Some of the tools already included in android/Android.mk. You need to remove the one in my tools/Android.mk

2. Without the kernel backport, Bluez won't work. So you must back port the kernel first.

Good luck!

Thanks a lot! I am gonna try and see if that works!

Last Question :- Do we need to make any changes in android_packages_apps_bluetooth??? If so, will it be fine if i use your bluetooth package from your github??
 

johnvuong1999

Member
Feb 11, 2015
39
1
San Francisco
my LG G Watch linux kernel is:

cat /proc/version
Linux version 3.10.0-ge0ae071 ([email protected]) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Tue Nov 25 23:35:07 UTC 2014

so it is possible upgrade too?
I think we need compile the bluetooth app diriectory with java code too.

since bluetooth support with bluedroid in CM11 /CM12 is better than AOSP, so can we only update those part of code for better support for Avrcp 1.4/1.5?

I am considering working on it, but since Android wear lake many part of codes, so I think upgrade bluedorid maybe easier, though it is not mature.
 
Last edited:

m4jonez

Senior Member
Oct 29, 2012
96
388
Budapest
oandras.hu
Hi Daniel,

I want to use the CSR7820 chip in my S7562, so I backported my kernel with your files and repatched drivers with CSR7820 specific things.
I can set up hci0 and search for devices with hcitool (it can find my computer).

But when I want to start the bluez bluetoothd daemon, it fails with "IPC: command socket connect failed" ( ipc.c : cmd_connect_cb ).
cond=20, so 20&G_IO_HUP is >0.

Bluez 5.28, cyanogenmod 4.4.4

Do you have an idea what is the issue?

Thx for your response.
 
Last edited:

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,342
Hong Kong
Hi Daniel,

I want to use the CSR7820 chip in my S7562, so I backported my kernel with your files and repatched drivers with CSR7820 specific things.
I can set up hci0 and search for devices with hcitool (it can find my computer).

But when I want to start the bluez bluetoothd daemon, it fails with "IPC: command socket connect failed" ( ipc.c : cmd_connect_cb ).
cond=20, so 20&G_IO_HUP is >0.

Bluez 5.28, cyanogenmod 4.4.4

Do you have an idea what is the issue?

Thx for your response.

I remember I needed to fix a bug in 5.2x.
Try an earlier bluez version (say 5.1x) first. If yes, I'll find my fix for you.

Otherwise, it would be the kernel backport.

Good luck.
 
  • Like
Reactions: Anas Satria

m4jonez

Senior Member
Oct 29, 2012
96
388
Budapest
oandras.hu
I remember I needed to fix a bug in 5.2x.
Try an earlier bluez version (say 5.1x) first. If yes, I'll find my fix for you.

Otherwise, it would be the kernel backport.

Good luck.

I solved it :)
The bluetoothd can start, when both upper (hci attached) and lower layers (bluetooth HAL) started.
So bluetoothd can start when the HAL starts it, because the HAL creates the socket, what bluetoothd using.

I think this is a bad logic.
 
  • Like
Reactions: ansanar

shumash

Senior Member
Jun 1, 2008
1,782
2,811
Google Pixel 3
I've successfully compiled all the kernel objects, but I'm getting "undefined reference to" backport_alloc_workqueue during linking. The backport_alloc_workqueue function is referenced in workqueue.h, but not defined. The definition is in compat-3.3.c, but I don't use the backports. Any help would be appreciated.

EDIT: nvm
 
Last edited:

shumash

Senior Member
Jun 1, 2008
1,782
2,811
Google Pixel 3
I figured it out.

Now Im stuck with the kernel and backporting. I cherry picked the code and have compat files in the kernel but Im stuck trying to link them. IE I am getting an error that it can not find backport_alloc_workqueue which was defigned in the workqueue.h. I know backport_alloc_workqueue is defigned in compat-3.3 but it does not find it.

Thanks
I'm at the same point. How'd you fix it?

EDIT: nvm
 
Last edited:

Alonso1398

Senior Member
Jun 23, 2013
240
262
First I want to thanks this thread. I'm trying to port bluez but having some issues so i'll ask for help. Sorry if I do too many quotes
Ok, Managed to learn through my failures. I now have working backported drivers however something weird is going on. My process is as follows:

Code:
modprobe hci_uart
modprobe Bluetooth
echo "1" > /sys/class/rfkill/frkill0/state
hciattach /dev/ttySAC0 bcm43xx 4000000
hciconfig hci0 up

But here is the weird part. If I do a hciconfig -a hci0 I get this

Code:
hciconfig -a hci0
hci0:   Type: BR/EDR  Bus: UART
        BD Address: 43:34:B0:00:00:00  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:7419 acl:37 sco:0 events:151 errors:0
        TX bytes:2834 acl:36 sco:0 commands:75 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'BCM4334B0 37.4MHz Class1.5 Samsung D2'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 4.0 (0x6)  Revision: 0x40f
        LMP Version: 4.0 (0x6)  Subversion: 0x410d
        Manufacturer: Broadcom Corporation (15)
Look at the BD address, its a default value. If I go any further to start bluez I get a Bluetooth address mismatch

I have no idea what is wrong with it, I am able to scan with the hcitool and get devices back and ping them with l2ping so the chip is working. Anyone have any ideas? Ive tried to set the address with hciattach with no luck
Hello, I'm building for a broadcom chip too. Did you managed to fix your problems?
Also I have doubts if the kernel needs:

Code:
CONFIG_BT_HCIUART_BRCM
CONFIG_BCM_BZHW
because the replacement of some folders in the kernel source will make me to remove those lines...
@daniel_hkDo you know something about it?

I figured it out.

Now Im stuck with the kernel and backporting. I cherry picked the code and have compat files in the kernel but Im stuck trying to link them. IE I am getting an error that it can not find backport_alloc_workqueue which was defigned in the workqueue.h. I know backport_alloc_workqueue is defigned in compat-3.3 but it does not find it.

Thanks
And how is this fixed?

Sorry for too many questions. I'm don't really have too much knowledge about development but I really want to fix bluetooth for my device porting bluez
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,342
Hong Kong
First I want to thanks this thread. I'm trying to port bluez but having some issues so i'll ask for help. Sorry if I do too many quotes

Hello, I'm building for a broadcom chip too. Did you managed to fix your problems?
Also I have doubts if the kernel needs:

Code:
CONFIG_BT_HCIUART_BRCM
CONFIG_BCM_BZHW
because the replacement of some folders in the kernel source will make me to remove those lines...
@daniel_hkDo you know something about it?


And how is this fixed?

Sorry for too many questions. I'm don't really have too much knowledge about development but I really want to fix bluetooth for my device porting bluez
I'm on the road. Will take a look tonight...;)

Edit:
OK, this is basic Linux. Those CONFIG_XXX are defined in Kconfig (kernel config) inside the folder. Starting from the root kernel directory, the subdirectories are included in the root Kconfig like a tree. If you don't even know that, I don't think you can finish the backport yet. Read "how to build the Linux kernel" first. ;)

I only have and tried my device with CSR chip inside. Other chips would be similar but required the corresponding kernel driver (if exists). All materials I could provided are already in the thread, read it first.

Good luck!

BTW, Broadcom chips support Bluedroid. You don't need Bluez as bluetooth stack.
 
Last edited:
  • Like
Reactions: Alonso1398

Alonso1398

Senior Member
Jun 23, 2013
240
262
I'm on the road. Will take a look tonight...;)

Edit:
OK, this is basic Linux. Those CONFIG_XXX are defined in Kconfig (kernel config) inside the folder. Starting from the root kernel directory, the subdirectories are included in the root Kconfig like a tree. If you don't even know that, I don't think you can finish the backport yet. Read "how to build the Linux kernel" first. ;)

I only have and tried my device with CSR chip inside. Other chips would be similar but required the corresponding kernel driver (if exists). All materials I could provided are already in the thread, read it first.

Good luck!

BTW, Broadcom chips support Bluedroid. You don't need Bluez as bluetooth stack.

Ok, thanks for the answer. And I already tried using Bluedroid but for some weird reason it cause the phone to freeze when using bluetooth :-/ that's why I'm trying to port Bluez.
 

sanshinron

Senior Member
Dec 10, 2006
94
37
Is there any chance to get the BlueZ port as a flashable zip or something, so noobs like me could finally enjoy clear audio with apt-x codec on AOSP roms?
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,342
Hong Kong
Is there any chance to get the BlueZ port as a flashable zip or something, so noobs like me could finally enjoy clear audio with apt-x codec on AOSP roms?
It has been asked a few times. I usually prefer detail explainations but nowadays everything is "efficiency" oriented. Only few people really read so I'll try to precise. ;)

If you read the thread, you would know that kernel is involved. That means it is device specific. Unlikely to have one patch for different device. Should there be a universal kernel for different CPUs and hardwares, it would have "better" chance. But different device might have different Bluetooth chips too! That means different type of hardware initialization.
In conclusion, it would be highly unlikely to have a patch for different devices.
Futhermore, if you read the README from Bluez, it only fully support KK. Newer systems support (LP and MM) are only not yet complete.

There is no silly question, only different way of thinking.
There is no right or wrong, only different point of view. The only answer is to read and learn. :)

Sent from my Nexus 7 using Tapatalk
 

sanshinron

Senior Member
Dec 10, 2006
94
37
It has been asked a few times. I usually prefer detail explainations but nowadays everything is "efficiency" oriented. Only few people really read so I'll try to precise. ;)

If you read the thread, you would know that kernel is involved. That means it is device specific. Unlikely to have one patch for different device. Should there be a universal kernel for different CPUs and hardwares, it would have "better" chance. But different device might have different Bluetooth chips too! That means different type of hardware initialization.
In conclusion, it would be highly unlikely to have a patch for different devices.
Futhermore, if you read the README from Bluez, it only fully support KK. Newer systems support (LP and MM) are only not yet complete.

There is no silly question, only different way of thinking.
There is no right or wrong, only different point of view. The only answer is to read and learn. :)

Sent from my Nexus 7 using Tapatalk

On the side note I found out while browsing github that Cyanogenmod uses old BlueZ 4, which is deprecated. BlueZ website states that new version 5 (which supports apt-x) is a "drop-in replacement". Why didn't CM devs update BlueZ to version 5?
 

Codename13

Senior Member
Jun 22, 2012
935
1,304
On the side note I found out while browsing github that Cyanogenmod uses old BlueZ 4, which is deprecated. BlueZ website states that new version 5 (which supports apt-x) is a "drop-in replacement". Why didn't CM devs update BlueZ to version 5?

CM uses BlueZ 4 in the Android versions prior to 4.2.2, just like AOSP used to. They didn't bother updating it from BlueZ 4 to BlueZ 5 because those prior versions of Android are deprecated and no longer worked on.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 30
    Introduction
    When the bluetooth stack changed to Bluedroid in Android 4.2, it was a nightmare to some of the old devices like my GT-P6800. I didn't have any experience in Bluetooth before so I did what I know. I spent weeks to revert the 4.2 platform to Bluez. Even though I succeeded, it probably not doable for 4.3 and later.
    Last Nov. I found that bluez.org announced support for Andriod in Sep. It gave me hope again! Thanks to the bluez team!:good: The principle is straight forward - Implement the functions defined in "hardware/libhardware/include/hardware/bluetooth.h". That's what I thought but I didn't have enough knowledge nor confidence to try...:eek:
    After studying for a while, I started porting bluez to Android 4.4 last Christmas. It was frustrated and helpless. Although the lastest Android 4.4 example for Mako and Flo are out, they don't help much. A bunch of prebuilt kernel objects surely doesn't help! Porting for those devices already having bluedroid support is meaningless to most of us too... :(
    Building the bluez hal and daemon are straight forward but how to make it really work is another story. After a few painful and frustrated weekends, I finally managed to pull everything together. I can start/stop and pairing bluetooth devices in the platform now. And here I'm, sharing my experiences. I think there might be better way and I welcome any corrections.
    My p6800 has CSR bluetooth chip which has no bluedroid support. I think the same approach would work for other chips too. Cheers! :highfive:

    ** All paths assume your rom source dircetory to be the current directory **

    1. Downlaod and Build
    Bluez.org already has its own tutorial. I just summerize and list my suggestions.

    1.1 local manifest
    I learned my lesson and would avoid touching the "manifest.xml".
    Add the following lines to your ".repo/local_manifests/local_menifest.xml"
    For cm11, omni, etc.
    Code:
      <remote name="gcode" fetch="https://code.google.com/p/"/>
      <remote name="korg" fetch="git://git.kernel.org/pub/scm/bluetooth/"/>
      <remove-project name="android_external_bluetooth_bluedroid"/>
      <project remote="korg" path="external/bluetooth/bluez" name="bluez" group="pdk" revision="master"/>
      <project remote="korg" path="external/bluetooth/sbc" name="sbc" group="pdk" revision="master"/>
      <project remote="gcode" path="external/bluetooth/glib" name="aosp-bluez.glib" group="pdk" revision="master"/>
    For AOSP, replace the remove-project with:
    Code:
      <remove-project name="platform/external/bluetooth/bluedroid"/>
    After repo sync, bluez will replace bluedroid.

    1.2 patching bionic
    The patches for bionic are simple. Mainly by adding two flags and the function epoll_create1().
    Bionic may vary from ROMs. It is wiser to patch the bionic of your ROM manually. You may follow the changes of the two commits below:
    https://code.google.com/p/aosp-blue...96020013615b00d70579123f&repo=platform-bionic
    https://code.google.com/p/aosp-blue...3347746d0d9727d8439ef4c4&repo=platform-bionic

    1.3 neccessary tools
    There are tools in "external/bluetooth/bluez/tools". You may need some of those tools for setup or testing.
    This is the "Android.mk" I added to "external/bluetooth/bluez/tools". You may cheery pick the required tools for your device.
    Code:
    #
    # Bluetooth tools for setup and debug
    #			daniel_hk
    LOCAL_PATH := external/bluetooth
    
    # Retrieve BlueZ version from configure.ac file
    BLUEZ_VERSION := $(shell grep ^AC_INIT $(LOCAL_PATH)/bluez/configure.ac | cpp -P -D'AC_INIT(_,v)=v')
    
    # Specify pathmap for glib
    #pathmap_INCL += glib:external/bluetooth/glib
    
    # Specify common compiler flags
    BLUEZ_COMMON_CFLAGS := -DVERSION=\"$(BLUEZ_VERSION)\" \
    	-DSTORAGEDIR=$(ANDROID_STORAGEDIR) \
    
    # Disable warnings enabled by Android but not enabled in autotools build
    BLUEZ_COMMON_CFLAGS += -Wno-pointer-arith -Wno-missing-field-initializers
    
    # @ daniel, extra tools for CSR
    ifeq ($(BOARD_HAVE_BLUETOOTH_CSR),true)
    
    #
    # bccmd
    #
    include $(CLEAR_VARS)
    
    LOCAL_SRC_FILES:= \
    	bluez/lib/hci.c \
    	bluez/lib/bluetooth.c \
    	bluez/tools/bccmd.c \
    	bluez/tools/csr.c \
    	bluez/tools/csr_3wire.c \
    	bluez/tools/csr_bcsp.c \
    	bluez/tools/csr_hci.c \
    	bluez/tools/csr_h4.c \
    	bluez/tools/csr_usb.c \
    	bluez/tools/ubcsp.c
    
    LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
    
    LOCAL_C_INCLUDES:=\
    	$(LOCAL_PATH)/bluez \
    	$(LOCAL_PATH)/bluez/lib \
    	$(LOCAL_PATH)/bluez/tools \
    	$(LOCAL_PATH)/bluez/src \
    	$(LOCAL_PATH)/bluez/src/shared \
    
    LOCAL_MODULE:=bccmd
    
    include $(BUILD_EXECUTABLE)
    
    #
    # sdptool
    #
    include $(CLEAR_VARS)
    
    LOCAL_SRC_FILES:= \
    	bluez/lib/hci.c \
    	bluez/lib/bluetooth.c \
    	bluez/lib/sdp.c \
    	bluez/tools/sdptool.c \
    	bluez/src/sdp-xml.c
    
    LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
    
    LOCAL_C_INCLUDES:=\
    	$(LOCAL_PATH)/bluez \
    	$(LOCAL_PATH)/bluez/lib \
    	$(LOCAL_PATH)/bluez/tools \
    	$(LOCAL_PATH)/bluez/src \
    	$(LOCAL_PATH)/bluez/src/shared \
    
    LOCAL_C_INCLUDES += \
    	$(call include-path-for, glib) \
    	$(call include-path-for, glib)/glib \
    
    LOCAL_SHARED_LIBRARIES := \
    	libglib \
    
    LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
    LOCAL_MODULE_TAGS := optional
    LOCAL_MODULE:=sdptool
    
    include $(BUILD_EXECUTABLE)
    endif
    1.4 patches for CyanogenMod 11
    In CyanogenMod 11, the function "pin_request_cb" has one more argument. The following file need some patches:
    in the file "external/bluetooth/bluez/android/hal-bluetooth.c"
    Code:
    [I]** in function: handle_pin_request[/I]
    	bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev, 0);	// @ daniel, added 0 for cm11
    in the file "external/bluetooth/bluez/android/client/if-bt.c"
    Code:
    [I]** in function: pin_request_cb[/I]
    static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
    						uint32_t cod, uint8_t secure)	// @ daniel, added secure from cm11
    {
    	/* Store for command completion */
    	bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
    	pin_request_addr = *remote_bd_addr;
    
    	haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x secure=%02x\n", __func__,
    					last_remote_addr, bd_name->name, cod, secure);	// @ daniel, added
    	terminal_prompt_for("Enter pin: ", pin_request_answer);
    }
    2. kerenl patch
    In the "README" inside "external/bluetooth/bluez/android", there is the line:
    Minimal required version of management interface is 1.3. This corresponds to Linux 3.9 but latest available version is recommended.
    If you have tried porting bluez and fail, check the logcat. You might probably found the error "Failed to access management interface". This is the key making bluez to work! Sadly, most of the existing Android kernels are before ver. 3.9! The latest kernel we have might be ver. 3.4.x and the kernel for my p6800 is ver. 3.0.x! As the above line stated, Bluez5 requires the kernel to have management interface 1.3 or above. That means we have to backport the bluetooth subsystem from at least ver. 3.9. I backport my kernel with the latest (3.13-1) found in linux-foundation.org: http://drvbp1.linux-foundation.org/~mcgrof/rel-html/backports/
    It was a tough and painful job! There are lots of changes. I finally got a bootable backport kernel in 2 days!
    I packed my patches in View attachment kernel-3.0.x-backport-3.13-1.zip. This patch is for my 3.0.x kernel which might be different from other 3.0.x kernels. Don't have time to tidy up but it works for me. Although I've done the hard part:eek:, it still requires extra patience to get yours done. Prepare yourself...

    2.1 Backport 3.13-1 to your kernel
    • Direct replacements.
      Replace the following folders in the zip with the one in your kernel source:
      drivers/bluetooth
      net/bluetooth
      include/net/bluetooth
      include/backport​
    • Direct replacement might not work!
      Check include/linux in the zip
      For each file,
      add the required part (which I delimited with comments @ daniel and //@ ) to the corresponding file in your kernel source.
      If file not exist,
      copy the files to your kernel source​
    • Check your defconfig. As README suggested, defconfig should have:
      CONFIG_BT
      CONFIG_BT_RFCOMM
      CONFIG_BT_RFCOMM_TTY
      CONFIG_BT_BNEP
      CONFIG_BT_BNEP_MC_FILTER
      CONFIG_BT_BNEP_PROTO_FILTER
      CONFIG_BRIDGE
      CONFIG_UHID
      # and for CSR chips
      CONFIG_BT_HCIUART=y
      CONFIG_BT_HCIUART_H4=y
      CONFIG_BT_HCIUART_BCSP=y
    You probably need to compile the kernel many times to get it work. I worte a build script View attachment build-k.zip to compile the kernel only.
    Copy build-k to your ROM source directory and type:
    Code:
    ./build-k <your device>
    2.2 Backport-hid-generic to your kernel
    There is another patch in the Mako-kern example:
    https://code.google.com/p/aosp-blue...eneric-driver.patch?repo=device-lge-mako-kern
    Don't know if it is required for your kernel but adding this patch seems doesn't hurt.

    If you do it right, you may find "Bluetooth management interface 1.4" in your logcat. Congratulation! Bluetoothd can connect to your kernel now!

    3. initialization and setup
    Take a look at your devices tree's TARGET_CUSTOM_BLUEDROID definition. If you have a file assigned, it supposed to replace the file "bluetooth.c" in the "system/bluetooth" project. In Android 4.4, this project is no longer exist/needed. Before Android 4.2, this project provide the functions "bt_enable()" and "bt_disable()" which are called in the frameworks. These functions will tell you how to "power on", "power off" and init your device's Bluetooth chip.
    For CSR:
    • set /sys/class/rfkill/rfkill0/state to 1 ("power on")
    • start the service "bccmd" which will setup the chip and upload a PSConfig to the chip
    • start the service "hciattach" which init the port hci0 with parameters
    • start the service "bluetoothd" which is the bluez stack
    The services are defined in init.rc or init.${ro.hardware}.rc.

    3.1 Test your device and the tools
    Disable the "import init.bluetooth.rc" line if you have added it before.
    Example for CSR chips. Follow the steps in bt_enable. In a terminal or via adb:
    Code:
    $ su				-- [I][COLOR="SeaGreen"]root user is required[/COLOR][/I]
    # echo "1" > /sys/class/rfkill/rfkill0/state
    # bccmd -t bcsp -d /dev/ttySAC0 -b 115200 psload -r /system/etc/PSConfig_8811.psr
      Loading 0x212c ... done
      Loading 0x212d ... done
    	...
      Loading PSKEY_CLOCK_REQUEST_ENABLE ... done
      Loading PSKEY_UART_HOST_WAKE ... done
    # hciattach -p /dev/ttySAC0 bcsp 3000000 flow
      Device setup complete
    # hciconfig hci0 up
    # hcitool scan			-- [I][COLOR="SeaGreen"]turn on a device's bluetooth for testing[/COLOR][/I]
    	Nexus 4			-- [I][COLOR="SeaGreen"]found the device means bluetooth is working now[/COLOR][/I]
    3.2 Init sequence
    In Bluez5, the HAL (bluetooth.default.so) driver will be loaded at boot and the daemon (bluetoothd) will be started inside too. Take a look at the function "bool hal_ipc_init(void)" in "external/bluetooth/bluez/android/hal-ipc.c". You may find how the HAL is init which is different from pre-4.2 Androids.
    In order to get the daemon (bluetoothd) to work, we have to init the chip before that.
    I worte a shell script init.bt.sh to init the chip/port:
    Code:
    #!/system/bin/sh
    # modified by daniel_hk
    
    LOG_TAG="CSR8811-HCI"
    BTUART_PORT=/dev/ttySAC0
    BTSTATE=/sys/class/rfkill/rfkill0/state
    PSCONFIG=/system/etc/PSConfig_8811.psr
    
    logi ()
    {
      /system/bin/log -t $LOG_TAG -p i ": [email protected]"
    }
    
    loge ()
    {
      /system/bin/log -t $LOG_TAG -p e ": [email protected]"
    }
    
    failed ()
    {
      loge "$1: exit code $2"
      exit $2
    }
    
    #Enable power of csr chip
    echo "1" > $BTSTATE
    
    # PS Config with bccmd
    logwrapper /system/bin/bccmd -t bcsp -d $BTUART_PORT -b 115200 psload -r $PSCONFIG
    case $? in
      0) logi "bccmd init port....done";;
      *) failed "port: $BTUART_PORT - bccmd failed" $?;
         exit $?;;
    esac
    
    # attach HCI 
    logwrapper /system/bin/hciattach -p $BTUART_PORT bcsp 3000000 flow
    case $? in
      0) logi "hci attached to : $BTUART_PORT";;
      *) failed "port: $BTUART_PORT - hciattach failed" $?;
         exit $?;;
    esac
    
    exit 0
    It takes time for bccmd and hciattach to complete. Putting them in seperate services requires delay in between. I think it is better to run them as application one after one.

    A new rc file init.${ro.hardware}.bt.rc is created and need to be imported in your init.${ro.hardware}.rc
    Code:
    on boot
        start bt_init
    
    on property:init.svc.bluetoothd=running
        start hci0_up
    
    on property:init.svc.bluetoothd=stopped
        start hci0_down
    
    service bt_init /system/bin/logwrapper /system/bin/sh /system/etc/init.bt.sh
        class main
        user root
        group bluetooth net_bt_admin system
        disabled
        oneshot
    
    service hci0_up /system/bin/logwrapper /system/xbin/hciconfig hci0 up
        class main
        group bluetooth
        disabled
        oneshot
    
    service hci0_down /system/bin/logwrapper /system/xbin/hciconfig hci0 down
        class main
        group bluetooth
        disabled
        oneshot
    
    import init.bluetooth.rc
    Since HAL (bluetooth.default.so) is started quite early, I start the service bt_init at boot. I have tried a few places, daemon might timed out before bt_init finish. It also seems no need to repeat the init process everytime.
    When bluetoothd is running (system/core/init will set the property init.svc.bluetoothd=running), set hci0 up with hciconfig. And when the service bluetoothd is stopped, set hci0 down with hciconfig. There might be a better way. Please indulge me if something better coming up.

    You may turn ON/OFF bluetooth in settings now. Pairing and file transfer is working too.

    4. Further porting
    Take a look at the function get_profile_interface() in the file external/bluetooth/bluez/android/hal-bluetooth.c. Some interfaces which frameworks requested are missing.
    eg.
    Bluetooth Handsfree interface
    Bluetooth Map Client Interface
    Bluetooth Health Interface
    Bluetooth GATT Interface
    Update: Fully support for Kitkat now. Check the README inside the android folder for detail.

    As I mentioned before, I'm new to bluetooth. Further reading is required for me to fix other services. I also don't have enough time now. I have to process the stuck works after the Chinese New Year holiday. :cyclops: Hoping I can continue by the end of Feb. In the mean time, I hope someone have better knowledge may help fix other services.

    For those devices don't have bluedroid support, we have a chance to carry on now! :D
    2
    [GUIDE] Porting Bluez to Marshmallow

    Check the modified Bluez in my github.
    It has been tested with Omni6 (Android-6.0.1_r3)
    You have to remove system_bt in local_manifest.xml (similar to bluedroid, check post #1 for detail)

    CM needs extra modifications. Will be available after testing.
    2
    Nice , Xperia Novathor devs also working on stable bluez :)
    @95A31
    2
    I have checked your logcat. There is no management interface log. The kernel backport on blietooth subsystem is probably failed.


    Sent from my Nexus 7 using Tapatalk

    I foud this dependence in my case: WLAN init need that BT chip is initialized because WLAN ask clock to BT. The intoduction of import init.bluetooth.rc broke this dependence. Fu*king details :cyclops: I hope to save debug time to someone :D
    2
    Sucessfully ported on CyanogenMod 11.0 git (using Bluetooth from AOSP).

    HOWTO:
    Remove CyanogenMod Bluetooth and grab AOSP version by local_manifest:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <manifest>
    
      <remote name="kernel"
              fetch="git://git.kernel.org/pub/scm/" />
    
      <remote name="googlecode"
              fetch="https://code.google.com/" />
    
      <remove-project name="CyanogenMod/android_external_bluetooth_bluedroid" />
      <project remote="kernel" path="external/bluetooth/bluez" name="bluetooth/bluez" groups="pdk" revision="master" />
      <project remote="kernel" path="external/bluetooth/sbc" name="bluetooth/sbc" groups="pdk" revision="master" />
      <project remote="googlecode" path="external/bluetooth/glib" name="p/aosp-bluez.glib" groups="pdk" revision="master" />
      
      <remove-project name="CyanogenMod/android_packages_apps_Bluetooth" />
      <remove-project name="CyanogenMod/android_packages_apps_BluetoothExt" />  
      <project path="packages/apps/Bluetooth" name="platform/packages/apps/Bluetooth" remote="aosp" revision="refs/tags/android-4.4.2_r1" />
      
      <project path="aosp/packages/apps/Settings" name="platform/packages/apps/Settings" remote="aosp" revision="refs/tags/android-4.4.2_r1" />  
      <project path="aosp/frameworks/base" name="platform/frameworks/base/" remote="aosp" revision="refs/tags/android-4.4.2_r1" />
      <project path="aosp/hardware/libhardware" name="platform/hardware/libhardware/" remote="aosp" revision="refs/tags/android-4.4.2_r1" />
    
    </manifest>
    Replace CyanogenMod Bluetooth system with AOSP one:
    Code:
    rm cm-11.0/hardware/libhardware/include/hardware/bluetooth.h
    cp aosp/hardware/libhardware/include/hardware/bluetooth.h cm-11.0/hardware/libhardware/include/hardware/bluetooth.h
    
    rm -rf  cm-11.0/frameworks/base/core/java/android/bluetooth
    cp -r aosp/frameworks/base/core/java/android/bluetooth  cm-11.0/frameworks/base/core/java/android
    
    rm  cm-11.0/frameworks/base/services/java/com/android/server/BluetoothManagerService.java
    cp aosp/frameworks/base/services/java/com/android/server/BluetoothManagerService.java  cm-11.0/frameworks/base/services/java/com/android/server/BluetoothManagerService.java
    
    rm -rf  cm-11.0/packages/apps/Settings/src/com/android/settings/bluetooth
    cp -r aosp/packages/apps/Settings/src/com/android/settings/bluetooth  cm-11.0/packages/apps/Settings/src/com/android/settings
    Adapt CyanogenMod with this changes:
    Code:
    diff --git a/frameworks/base/Android.mk b/frameworks/base/Android.mk
    index 91338ef..43a87ef 100644
    --- a/frameworks/base/Android.mk
    +++ b/frameworks/base/Android.mk
    @@ -88,10 +88,8 @@ LOCAL_SRC_FILES += \
     	core/java/android/wipower/IWipower.aidl \
     	core/java/android/wipower/IWipowerManagerCallback.aidl \
     	core/java/android/bluetooth/IBluetooth.aidl \
    -	core/java/android/bluetooth/IQBluetooth.aidl \
     	core/java/android/bluetooth/IBluetoothA2dp.aidl \
     	core/java/android/bluetooth/IBluetoothCallback.aidl \
    -	core/java/android/bluetooth/IQBluetoothAdapterCallback.aidl \
     	core/java/android/bluetooth/IBluetoothHeadset.aidl \
     	core/java/android/bluetooth/IBluetoothHeadsetPhone.aidl \
     	core/java/android/bluetooth/IBluetoothHealth.aidl \
    @@ -100,18 +98,12 @@ LOCAL_SRC_FILES += \
     	core/java/android/bluetooth/IBluetoothPan.aidl \
     	core/java/android/bluetooth/IBluetoothManager.aidl \
     	core/java/android/bluetooth/IBluetoothManagerCallback.aidl \
    -	core/java/android/bluetooth/IQBluetoothManagerCallback.aidl \
     	core/java/android/bluetooth/IBluetoothPbap.aidl \
     	core/java/android/bluetooth/IBluetoothMap.aidl \
     	core/java/android/bluetooth/IBluetoothStateChangeCallback.aidl \
    -	core/java/android/bluetooth/IBluetoothHandsfreeClient.aidl \
    -	core/java/android/bluetooth/IBluetoothHidDevice.aidl \
    -	core/java/android/bluetooth/IBluetoothHidDeviceCallback.aidl \
     	core/java/android/bluetooth/IBluetoothGatt.aidl \
     	core/java/android/bluetooth/IBluetoothGattCallback.aidl \
     	core/java/android/bluetooth/IBluetoothGattServerCallback.aidl \
    -	core/java/android/bluetooth/IBluetoothSap.aidl \
    -	core/java/android/bluetooth/IBluetoothDun.aidl \
     	core/java/android/content/IClipboard.aidl \
     	core/java/android/content/IContentService.aidl \
     	core/java/android/content/IIntentReceiver.aidl \
    @@ -407,7 +399,6 @@ aidl_files := \
     	frameworks/base/core/java/com/android/internal/view/IInputMethodClient.aidl \
     	frameworks/base/core/java/com/android/internal/view/IInputMethodManager.aidl \
     	frameworks/base/core/java/com/android/internal/view/IInputMethodSession.aidl \
    -        frameworks/base/core/java/android/bluetooth/BluetoothLEServiceUuid.aidl  \
     	frameworks/base/graphics/java/android/graphics/Bitmap.aidl \
     	frameworks/base/graphics/java/android/graphics/Rect.aidl \
     	frameworks/base/graphics/java/android/graphics/Region.aidl \