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

Search This thread

NV-Dev

Senior Member
May 7, 2015
146
288
CM-11.0 Bluez - Kernel 3.4

Hi, I had some problems with the device holder BlueZ.

It was made avaialble to the BlueZ kernel and can connect to the kernel.

But still does not work, and try to run the commands adb shell and this happens.

Shell:

Code:
bccmd -t bcsp -d /dev/ttyHS0 -b 115200 psload -r /system/etc/PSConfig_7820.psr
Result: Initialization timed out

Code:
hciattach -p /dev/ttyHS0 bcsp 3000000 flow
Result: BCSP initialization timed out

Thanks in advance, and I hope you can help me.
@Daniel_Kh

Device-tree: https://github.com/CyanogenMod-S6310/android_device_samsung_royss
branch: cm-11.0

vendor: https://github.com/CyanogenMod-S6310/proprietary_vendor_samsung
branch: cm-11.0
 
Last edited:

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,344
Hong Kong
Realme X2
Hi, I had some problems with the device holder BlueZ.

It was made avaialble to the BlueZ kernel and can connect to the kernel.

But still does not work, and try to run the commands adb shell and this happens.

Shell:

Code:
bccmd -t bcsp -d /dev/ttyHS0 -b 115200 psload -r /system/etc/PSConfig_7820.psr
Result: Initialization timed out

Code:
hciattach -p /dev/ttyHS0 bcsp 3000000 flow
Result: BCSP initialization timed out

Thanks in advance, and I hope you can help me.

@Daniel_Kh

Device-tree: https://github.com/CyanogenMod-S6310/android_device_samsung_royss
branch: cm-11.0

vendor: https://github.com/CyanogenMod-S6310/proprietary_vendor_samsung
branch: cm-11.0

This is one of my old threads. You didn't quote and your mention was misspelled. There was no notification to me. You are lucky that someone told me about your post. As a developer, these kind of careless mistakes should not happen. ;)

You didn't provide the log so I can't tell what's wrong. Giving me the device tree and your commands won't help. I simply don't have your device to test. :cyclops:

I guess your kernel backport was not done or fail. Read the thread again. All I can tell are already there. You need to backport the bluetooth subsystem to at least 3.10.y (3.13.y or higher is recommended). Only you have the device can get this done.
Good luck!
 
  • Like
Reactions: NV-Dev

NV-Dev

Senior Member
May 7, 2015
146
288
CM-11.0 Bluez - Kernel 3.4 (Logcat)

This is one of my old threads. You didn't quote and your mention was misspelled. There was no notification to me. You are lucky that someone told me about your post. As a developer, these kind of careless mistakes should not happen. ;)

You didn't provide the log so I can't tell what's wrong. Giving me the device tree and your commands won't help. I simply don't have your device to test. :cyclops:

I guess your kernel backport was not done or fail. Read the thread again. All I can tell are already there. You need to backport the bluetooth subsystem to at least 3.10.y (3.13.y or higher is recommended). Only you have the device can get this done.
Good luck!

Here it is in the log with BlueZ backported in the kernel: Logcat

Lines: 202, 1560- 1562, 1916 - 1917, 2040, 2070.

Kernel source
@daniel_hk
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,344
Hong Kong
Realme X2
Here it is in the log with BlueZ backported in the kernel: Logcat

Lines: 202, 1560- 1562, 1916 - 1917, 2040, 2070.

Kernel source

@daniel_hk

I can't pretended I read all your log and sources. I did a few search and follow some of your source. It already spent me over an hour...
1. The BT chip is not initialized. I don't know if you have turn the BT chip on. I assume you have.
2. I don't know which BT chip you have (I think athero?). You used BSCP and bccmd to initialize it. I assume you got it from the cm-10 (or earlier) device tree.
3. The ports are not initialized. That means the protocols are not ready. You can't configure the HCI if the chip is not initialized.
4. The command interface is not started. The bluetoothd would start it if the kernel is ready.
All the above concluded that your kernel is no ready.
Frankly, I can't follow your kernel source. Backport the bluetooth subsystem is straight forward. It is definitely not a simple job and I can't see where you really started.
Your approach seems in the right direction. I suggest you start from fresh again. Backport to 3.18-1 is a good start. All you need is the drivers/bluetooth and net/bluetooth subsystem. You may need a driver for your BT chip too but I can't find which in your source.
Again, only you have the device can get this done. Just finish the backport in kernel and everything would be in the right place.
Good luck!
 

NV-Dev

Senior Member
May 7, 2015
146
288
Bluetooth working now.

I can't pretended I read all your log and sources. I did a few search and follow some of your source. It already spent me over an hour...
1. The BT chip is not initialized. I don't know if you have turn the BT chip on. I assume you have.
2. I don't know which BT chip you have (I think athero?). You used BSCP and bccmd to initialize it. I assume you got it from the cm-10 (or earlier) device tree.
3. The ports are not initialized. That means the protocols are not ready. You can't configure the HCI if the chip is not initialized.
4. The command interface is not started. The bluetoothd would start it if the kernel is ready.
All the above concluded that your kernel is no ready.
Frankly, I can't follow your kernel source. Backport the bluetooth subsystem is straight forward. It is definitely not a simple job and I can't see where you really started.
Your approach seems in the right direction. I suggest you start from fresh again. Backport to 3.18-1 is a good start. All you need is the drivers/bluetooth and net/bluetooth subsystem. You may need a driver for your BT chip too but I can't find which in your source.
Again, only you have the device can get this done. Just finish the backport in kernel and everything would be in the right place.
Good luck!

@daniel_hk

The bluetooth is working now. :D

Thanks men, you are the best! :good:

BlueZ 5.38 with Backport 3.18 working in royss (msm7x27a and kernel 3.4) :fingers-crossed:

12442931_980520998694252_773370088_n.jpg 12899719_979769918769360_579597324_n.jpg
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,344
Hong Kong
Realme X2
  • Like
Reactions: NV-Dev

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,344
Hong Kong
Realme X2
start script for BCM4330
Hi Daniel,

Thanks for this excellent post. I would never have been able to port bluetooth to kitkat without your help.

You might want add this start script for BCM4330 to the replies to your posting in the hope that it might prove useful to others as I don't have sufficient privileges.

Shlomo
I received the above PM earlier. Sharing is the essence of open source. I don't have problem posting it. :)
The following is his script:
Code:
#!/system/bin/sh
# modified by shlomo kut

LOG_TAG="EQUATEL-HCI"
BTUART_PORT=/dev/ttySAC0
BTSTATE=/sys/class/rfkill/rfkill0/state
PSCONFIG=/system/etc/bluetooth/bcm4330.hcd
BAUDRATE=3000000
loge ()
{
/system/bin/log -t $LOG_TAG -p e "$LOG_NAME $@"
}

logi ()
{
/system/bin/log -t $LOG_TAG -p i "$LOG_NAME $@"
}

failed ()
{
loge "$1: exit code $2"
exit $2
}

logi "Enable power of csr chip"
echo "1" > $BTSTATE

logi "Config with brcm_patchram_plus"
logwrapper /system/bin/brcm_patchram_plus --baudrate $BAUDRATE --patchram /etc/bluetooth/bcm4330.hcd --no2bytes $BTUART_PORT
case $? in
0) logi "brcm_patchram_plus....done";;
*) failed "port: $BTUART_PORT - brcm_patchram_plus failed" $?;
exit $?;;
esac

logwrapper /system/xbin/hciattach -n -s $BAUDRATE $BTUART_PORT bcm43xx
case $? in
0) logi "hci attached to : $BTUART_PORT";;
*) failed "port: $BTUART_PORT - hciattach failed" $?;
exit $?;;
esac

setprop bluetooth.status on

logi "started bluetooth smd transport"

exit 0
 

stosem

Member
Sep 23, 2013
7
0
Last edited:

truthz03

New member
Jul 23, 2009
3
0
Hi.

Last weekend I have tried to compile the bluez lollipop version for my Nexus 7 flo.
The build was successful and the devices starts correct with working bluetooth functionallity.
Now I tried to enable the handsfree feature which is the reason I switched to bluez.
After I set the "persist.sys.bluetooth.handsfree" property to "hfp" or "hfp_wbs" nothing changes.
I also tried to reboot the device but the hfp is not working. If I pair my phone to the table the phone does not show the hfp service.
Have I missed something?

Thanks Thomas
 

daniel_hk

Inactive Recognized Contributor
Nov 12, 2012
1,634
5,344
Hong Kong
Realme X2
Hi.

Last weekend I have tried to compile the bluez lollipop version for my Nexus 7 flo.
The build was successful and the devices starts correct with working bluetooth functionallity.
Now I tried to enable the handsfree feature which is the reason I switched to bluez.
After I set the "persist.sys.bluetooth.handsfree" property to "hfp" or "hfp_wbs" nothing changes.
I also tried to reboot the device but the hfp is not working. If I pair my phone to the table the phone does not show the hfp service.
Have I missed something?

Thanks Thomas

Thomas,

flo is one of the official example in Bluez port. You might not need to build your own. You can use their output files directly. See if those work.

I ported to a Samsung device. During a call, I need to push the button of the BT earpiece once to connect.

A tablet's bluetooth might not be acted as a handsfree device (eg. a ear piece). Extra audio redirection might required.

I was porting Bluez to a device doesn't have Bluedroid support. Further questions you can consult Bluez directly.

Good luck.
 

truthz03

New member
Jul 23, 2009
3
0
Hi daniel,

thanks for your answer.
Do you know where I can find these output files?
I didn't find them on "https://github.com/bluez-android".

Thanks,
Thomas
 

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 ": $@"
    }
    
    loge ()
    {
      /system/bin/log -t $LOG_TAG -p e ": $@"
    }
    
    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 \