How to Enable USB Bluetooth Dongle Based on i.MX6 Android ICS

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Enable USB Bluetooth Dongle Based on i.MX6 Android ICS

No ratings

How to Enable USB Bluetooth Dongle Based on i.MX6 Android ICS

Overview

The purpose of this document is to demonstrate how to enable USB Bluetooth Dongle based on i.MX6 Android ICS.

Hardware

  • i.MX6Dual/Quad or i.MX6DualLite SabreSD board
  • USB Bluetooth Dongle

Software

  • i.MX6DQ/MX6DL Android ICS R13.4 or R13.4.1 Release

Changes

  • 0001-enable-usb-dongle-BT.patch: Update bluedroid to disable RFKILL and enable HCIATTACH property for USB Bluetooth Dongle.

diff --git a/bluedroid/Android.mk b/bluedroid/Android.mk

index 17df49b..569be44 100644

--- a/bluedroid/Android.mk

+++ b/bluedroid/Android.mk

@@ -5,6 +5,13 @@

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

+ifeq ($(BOARD_BLUETOOTH_DOES_NOT_USE_RFKILL),true)

+  LOCAL_CFLAGS := $(LOCAL_CFLAGS) -DBLUETOOTH_DOES_NOT_USE_RFKILL

+endif

+

+ifeq ($(BOARD_BLUETOOTH_USES_HCIATTACH_PROPERTY),true)

+  LOCAL_CFLAGS := $(LOCAL_CFLAGS) -DBLUETOOTH_HCIATTACH_USING_PROPERTY

+endif

LOCAL_SRC_FILES := \

  bluetooth.c

diff --git a/bluedroid/bluetooth.c b/bluedroid/bluetooth.c

index 4cc9204..2636942 100644

--- a/bluedroid/bluetooth.c

+++ b/bluedroid/bluetooth.c

@@ -44,7 +44,7 @@

static int rfkill_id = -1;

static char *rfkill_state_path = NULL;

-

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

static int init_rfkill() {

     char path[64];

     char buf[16];

@@ -135,6 +135,7 @@ out:

     if (fd >= 0) close(fd);

     return ret;

}

+#endif

static inline int create_hci_sock() {

     int sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);

@@ -151,13 +152,20 @@ int bt_enable() {

     int ret = -1;

     int hci_sock = -1;

     int attempt;

-

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

     if (set_bluetooth_power(1) < 0) goto out;

-

+#endif

+#ifndef BLUETOOTH_HCIATTACH_USING_PROPERTY

     LOGI("Starting hciattach daemon");

-    if (property_set("ctl.start", "hciattach") < 0) {

+    if (property_set("ctl.start", "hciattach") < 0)

+#else

+    if (property_set("bluetooth.hciattach", "true") < 0)

+#endif

+    {

         LOGE("Failed to start hciattach");

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

         set_bluetooth_power(0);

+#endif

         goto out;

     }

@@ -186,14 +194,18 @@ int bt_enable() {

         if (property_set("ctl.stop", "hciattach") < 0) {

             LOGE("Error stopping hciattach");

         }

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

         set_bluetooth_power(0);

+#endif

         goto out;

     }

     LOGI("Starting bluetoothd deamon");

     if (property_set("ctl.start", "bluetoothd") < 0) {

         LOGE("Failed to start bluetoothd");

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

         set_bluetooth_power(0);

+#endif

         goto out;

     }

@@ -222,14 +234,20 @@ int bt_disable() {

     ioctl(hci_sock, HCIDEVDOWN, HCI_DEV_ID);

     LOGI("Stopping hciattach deamon");

-    if (property_set("ctl.stop", "hciattach") < 0) {

+#ifndef BLUETOOTH_HCIATTACH_USING_PROPERTY

+    if (property_set("ctl.stop", "hciattach") < 0)

+#else

+   if (property_set("bluetooth.hciattach", "false") < 0)

+#endif

+   {

         LOGE("Error stopping hciattach");

         goto out;

     }

-

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

     if (set_bluetooth_power(0) < 0) {

         goto out;

     }

+#endif

     ret = 0;

out:

@@ -246,9 +264,10 @@ int bt_is_enabled() {

     // Check power first

+#ifndef BLUETOOTH_DOES_NOT_USE_RFKILL

     ret = check_bluetooth_power();

     if (ret == -1 || ret == 0) goto out;

-

+#endif

     ret = -1;

     // Power is on, now check if the HCI interface is up

  • 0002-usb_dongle-on-SabreSD.patch: Update MX6 board configuration files to enable USB Bluetooth dongle feature.

diff --git a/imx6/imx6.mk b/imx6/imx6.mk

@@ -63,6 +63,7 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
  audio.tinyalsa.freescale   \
  audio.legacy.freescale    \
+        audio.a2dp.default                      \
  alsa_aplay                \
  alsa_arecord    \
  alsa_amixer        \
diff --git a/imx6/sabresd/SabreSDBoardConfigComm.mk b/imx6/sabresd/SabreSDBoardConfigComm.mk
index 03d8ce5..1a8a6bd 100755
--- a/imx6/sabresd/SabreSDBoardConfigComm.mk
+++ b/imx6/sabresd/SabreSDBoardConfigComm.mk
-# atheros 3k BT
-BOARD_USE_AR3K_BLUETOOTH := true
+# Default use USB BT dongle for imx6, so should enable below
+BOARD_BLUETOOTH_DOES_NOT_USE_RFKILL := true
+BOARD_BLUETOOTH_USES_HCIATTACH_PROPERTY := true
+
USE_ION_ALLOCATOR := false
USE_GPU_ALLOCATOR := true
diff --git a/imx6/sabresd/init.rc b/imx6/sabresd/init.rc
index ff9f0ff..f127177 100755
--- a/imx6/sabresd/init.rc
+++ b/imx6/sabresd/init.rc
@@ -84,9 +84,12 @@ on boot
     # No bluetooth hardware present
     setprop hw.bluetooth 0
     setprop wlan.interface wlan0
+    setprop hw.bluetooth 1

diff --git a/imx6/sabresd/required_hardware.xml b/imx6/sabresd/required_hardware.xml
index c9a2271..f7db37b 100644
--- a/imx6/sabresd/required_hardware.xml
+++ b/imx6/sabresd/required_hardware.xml
@@ -22,6 +22,7 @@
     <feature name="android.hardware.camera.flash" />
     <feature name="android.hardware.camera.front" />
     <feature name="android.hardware.location" />
+    <feature name="android.hardware.bluetooth" />
     <feature name="android.hardware.location.network" />
     <feature name="android.hardware.location.gps" />
     <feature name="android.hardware.telephony" />

Labels (2)
Attachments
Comments

Are there any updates to this for the Jelly Bean 4.2.2 release?

the above changes are already integrated in Android JellyBean 4.2.2, when i insmod ath3k.ko driver with btusb.ko driver able to see /sysfs entries. But when i start Bluettoh ON from android UI not able to start BT interface and getting following errors:

The bt_enable() is not calling when i start BT ON from UI

==========================================

D/BluetoothAdapterService( 2934): Profile still not running:com.android.bluetooth.pan.PanService

I/bluedroid( 2934): enable

D/BTIF_CORE( 2934): not disabled

E/BluetoothAdapterState( 2934): Error while turning Bluetooth On

D/BluetoothAdapterService( 2934): Broadcasting updateAdapterState() to 1 receivers.

D/BluetoothManagerService( 2542): Message: 60

D/BluetoothManagerService( 2542): MESSAGE_BLUETOOTH_STATE_CHANGE: prevState = 11, newState=10

D/BluetoothManagerService( 2542): Broadcasting onBluetoothStateChange(false) to 8 receivers.

===============================================================

Kindly help if anyone is aware of the issue.?

Hi,

Sandesh

Are you able to fixed the Bluetooth playback on Jellybean?

Same issue here?

Can you share your findings?

-John

John,

Android 4.2.2 removes Bluez which supported USB BT.

The libbt_vendor library which implemented by Google for BCM chip or by FSL for ATH chip only supports UART interface.

There are two ways to support USB BT.

1. Backport Bluez to Android 4.2.2. There is a link for reference - http://gitorious.org/android-bluez

2. implement a new libbt_vendor to support USB BT.

Also, the source below modifies libbt-vendor for Broadcom chip for USB. For your reference.

https://github.com/CyanogenMod/android_hardware_broadcom_libbt

Please let me know if this helps.

Thanks,

Sandesh

Hi Sandesh,

We am using IMX6 sabre lite with JB4.2.2, the BT-Dongle is Azio BT-v201 .

The interest is to route the phone traffic to BT phone profile.

A2DP traffic is fine and it is routed through Bluetooth, but with just phone profile the SCO traffic is not coming to headphone.

Do i need to add the SCO support in any configuration file?

Any light on the SCO support with BT-USB or has any one tried Bluetooth phone profile with IMX6 Jelleybean?

Thanks,

Sridhar

Hi sridharmuvvala,

Do I understand correctly that you have A2DP profile working with a USB Bluetooth dongle on 4.2.2?  Can you share what you have done?

Hi Sandesh and Chris,

I've also tried to use USB Bluetooth dongle with JB4.2.2 and IMX6 Sagbresd board.

In my case, i use libusb library to access USB Bluetooth device. .

I did reference below link to do that.

ac100 - Bluedroid 4.2 battle

I can create SCO link between USB Bluetooth device and USB headset.

But i don't know how to send traffic this SCO link.

If you have any progress about SCO issue, could you share that in here?

Thanks,

Shin.

Hi Shin,

I am working on this issue now. ( i am trying SCO with USB Bluetooth dongle with JB4.2.2 and IMX6 Sagbre-lite board)

in your post you said "I can create SCO link between USB Bluetooth device and USB headset", , i hope you mean bluetooth Headset.

How are you confirming that SCO link is created?  Because i am bit confused here in my setup.

Incase if link is configured SCO link properly, the audio traffic has to be routed to some HAL, similar to A2DP or USB.

If you know more details please let me know.

Thanks,

Sridhar

Hi Sridhar,

In my case, i used test application in Jellybean source directory.

It's frameworks\base\media\tests\ScoAudioTest. If you run that application, you can see SCO connect button.

Of course, pairing and connection are should be done before.

And click SCO connect button in App, you can see SCO state is changing in UI.

In my case, i can see the state is changing like 0, 2, 1. It means that disconnect, connecting and connected.

And also, i can hear notify sound  through Bluetooth headset when SCO is connected.

I added some debug code and it shows as follow :

01-02 00:01:27.930 E       3127     ScoAudioTest                 startBluetoothSco() IN

01-02 00:01:27.940 D       2817     bte_main                     bte_main_hci_send : event = 0x2100

01-02 00:01:27.940 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:27.940 D       2817     bta_ag_sco                   bta_ag_sco_open

01-02 00:01:27.940 D       2817     bta_ag_sco                   bta_ag_sco_event

01-02 00:01:27.940 D       2817     bta_ag_sco                   bta_ag_remove_sco

01-02 00:01:27.940 D       2817     bta_ag_sco                   bta_ag_create_sco

01-02 00:01:27.940 D       2817     btu_hcif                     btu_hcif_send_cmd

01-02 00:01:27.940 D       2817     bte_main                     bte_main_hci_send : event = 0x2000

01-02 00:01:27.940 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:27.940 D       2817     bte_main                     bte_main_hci_send : event = 0x2100

01-02 00:01:27.940 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:27.940 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2100, sub_event = 0x0

01-02 00:01:27.940 D       2817     bte_main                     bte_main_hci_send : event = 0x2100

01-02 00:01:27.940 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:27.940 D       2817     bte_main                     bte_main_hci_send : event = 0x2100

01-02 00:01:27.940 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:27.940 E       3127     ScoAudioTest                 startBluetoothSco() OUT

01-02 00:01:27.940 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2000, sub_event = 0x0

01-02 00:01:27.940 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2100, sub_event = 0x0

01-02 00:01:27.940 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2100, sub_event = 0x0

01-02 00:01:27.940 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2100, sub_event = 0x0

01-02 00:01:27.940 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:27.940 D       2817     btu_hcif                     btu_hcif_send_cmd

01-02 00:01:27.960 I       3127     ScoAudioTest                 SCO Broadcast receiver : action = android.media.ACTION_SCO_AUDIO_STATE_UPDATED

01-02 00:01:27.960 E       3127     ScoAudioTest                 ACTION_SCO_AUDIO_STATE_UPDATED, state: 2 prev state: 0

01-02 00:01:28.610 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.610 D       2817     btu_hcif                     btu_hcif_send_cmd

01-02 00:01:28.610 D       2817     bte_main                     bte_main_hci_send : event = 0x2000

01-02 00:01:28.610 D       2817     bt_hci_bdroid                transmit_buf

01-02 00:01:28.610 D       2817     bt_hci_bdroid                bt_hc_worker_thread : send HCI

01-02 00:01:28.610 I       2817     bt_h4                        hci_h4_send_msg : event = 0x2000, sub_event = 0x0

01-02 00:01:28.620 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.620 D       2817     btu_hcif                     btu_hcif_send_cmd

01-02 00:01:28.640 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.670 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.670 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.720 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.780 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.780 D       2817     bta_ag_sco                   bta_ag_sco_conn_cback

01-02 00:01:28.780 D       2817     bta_ag_sco                   bta_ag_sco_conn_open

01-02 00:01:28.780 D       2817     bta_ag_sco                   bta_ag_sco_event

01-02 00:01:28.780 D       2817     bta_ag_sco                   bta_ag_cback_sco

01-02 00:01:28.780 I       3127     ScoAudioTest                 SCO Broadcast receiver : action = android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED

01-02 00:01:28.780 E       3127     ScoAudioTest                 BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED: 12

01-02 00:01:28.780 I       3127     ScoAudioTest                 SCO Broadcast receiver : action = android.media.ACTION_SCO_AUDIO_STATE_UPDATED

01-02 00:01:28.790 E       3127     ScoAudioTest                 ACTION_SCO_AUDIO_STATE_UPDATED, state: 1 prev state: 2

01-02 00:01:28.790 I       3127     ScoAudioTest                 SCO Broadcast receiver : action = android.media.SCO_AUDIO_STATE_CHANGED

01-02 00:01:28.790 E       3127     ScoAudioTest                 ACTION_SCO_AUDIO_STATE_CHANGED: 1

01-02 00:01:28.830 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.880 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:28.910 I       2817     bt_h4                        hci_h4_receive_msg

01-02 00:01:33.240 I       2817     bt_h4                        hci_h4_receive_msg

But i can't hear any sound when i play sound through test UI.

I think i have to add some codes in ALSA and Kernel because there is no PCM interface

between Bluetooth audio HAL and  USB Bluetooth dongle.

Case of USB headset, device driver create PCM interface when USB audio device is attached.

I think similar procedure needs after SCO link established.

Could you share your thinking about this issue?

Thanks,

Shin.

Woogeun,

Did u add codec specific configuration changes into alsa layer?

Ex: For sgtl5000 in following path  /hardware/imx/alsa/

-----------------------------------------------------------------------------------------------

/* ALSA cards for IMX, these must be defined according different board / kernel config*/

static struct audio_card  sgtl5000_card = {

    .name = "sgtl5000-audio",

    .driver_name = "sgtl5000-audio",

    .supported_out_devices = (

            AUDIO_DEVICE_OUT_WIRED_HEADPHONE |

            AUDIO_DEVICE_OUT_SPEAKER |

            AUDIO_DEVICE_OUT_DEFAULT ),

    .supported_in_devices = (

            AUDIO_DEVICE_IN_WIRED_HEADSET |

            AUDIO_DEVICE_IN_BUILTIN_MIC |

            AUDIO_DEVICE_IN_DEFAULT),

    .defaults            = defaults_SGTL5000,

    .bt_output           = NULL,

    .speaker_output      = NULL,

    .hs_output           = NULL,

    .earpiece_output     = NULL,

    .vx_hs_mic_input     = NULL,

    .mm_main_mic_input   = NULL,

    .vx_main_mic_input   = NULL,

    .mm_hs_mic_input     = NULL,

    .vx_bt_mic_input     = NULL,

    .mm_bt_mic_input     = NULL,

    .card                = 0,

    .out_rate            = 0,

    .out_channels        = 0,

    .out_format          = 0,

    .in_rate             = 0,

    .in_channels         = 0,

    .in_format           = 0,

};

--------------------------------------------------------------------------------------------------

Thanks,

Sandesh D

Sandesh D,

I agree that i need specific configuration or specific library.

But, i don't know how to write PCM data to SCO link.

If i know that, i can create new Audio HAL like tinyalsa_hal.c.

Normally, SCO traffic(data) is sent through PCM interface, In that case, we can write SCO data to PCM interface.

But i don't find it after SCO link is created in USB Bluetooth headset with Bluedroid.

Do you know about how to write SCO traffic? 

Thanks,

Shin.

Hi shin,

Are u still working on this issue?

I am planning to have  a HAL similar to a2dp_hw.c. But I am not sure of writing the data to the so called SCO socket.

Do we need to write to RFCOMM socket, or are u aware of any other way?

Thanks,

Sridhar M

Hi Sridhar,

I think that i have to use HCI to send SCO data through USB interface.

It's called SCO over HCI. I found some code about "SCO over HCI" in Bluedroid stack.

But, it's not complete. Broadcom may remove that code when Bluedroid stack merge in Android.

So, we have to add some code in Bluedroid to use SCO with USB interface.

But it''s too hard for me. -_-!!

So, i consider A2DP sink role. Jellybean doesn't include A2DP sink role.

I think  create A2DP sink role is easier than "SCO over HCI".

If you have another idea, please update hear.

Thanks,

Shin.

Hi shin,

I am facing the same problem you described here.

I am trying to use SCO over HCI too but it looks like bluedroid stack doesn't support this

(there are lots of missing parts and commented code)

Did you manage to add A2DP sink ?

Thanks,

Naaman.

Hi All,

My platform is IMX6SL, Android kitkat 4.4.3 , Bluedroid, bluetooth USB driver.

When I am inserting my ko from the GUI, it is giving this error,

Can you please suggest me what to do???

Unable to unload driver module "/system/bin/bluetooth.ko": Operation not permitted

************* bluetooth.c insmod is called**********

Failed to load module: Unknown error -1 (-1)

                                                 

I think it's purely permissions issue,

Here I have few questions,

1. Is the path which I am placing my kernel object file (ko) above /system/bin/release/ is correct ?? or it is /data/misc/bluetooth/ path???

2. If it is /data/misc/bluetooth/ then where should I mention permissions for that path.

Please respond me,

Thanks and Regards,

Mutyalarao.

Hi All,

Platform : IMX6SL

Bluedroid on Android kitkat 4.4.3.

Can you please help me I am struck at this point not able to move forward.

D/BluetoothAdapterState(  704):  CURRENT_STATE=PENDING, MESSAGE = ENABLE_TIMEOUT, isTurningOn=true, isTurningOff=false
E/BluetoothAdapterState(  704): Error enabling Bluetooth
D/BluetoothAdapterProperties(  704): Setting state to 10
I/BluetoothAdapterState(  704): Bluetooth adapter state changed: 11-> 10
D/BluetoothAdapterService(  704): Broadcasting updateAdapterState() to 1 receivers.

what's wrong with this..... Not getting any idea. Please help me.....

Thanks and regards,

MutyalaRao.

Hi all,

  I am glad to inform you that the above issue which I have posted earlier got resolved, but I have another 2 issues one while data transfer, the other while enabling via GUI.

   1) After enabling bluetooth, while transferring file from third party mobile to IMX_6SL board, file is getting transferred(TX), but vice versa (RX) is not happening, it is giving the error message :

   File not Received

   File : sample.jpg

   Reason : Storage issue

  2) And presently I am inserting my driver via GUI, I am getting an error message while enabling bluetooth via GUI   ie Operation not permitted while loading .ko (driver)Please suggest me what to do?? whether I need to install my driver at boot by adding in init.rc?? if I do it always on boot bt will be in ON State only??  OR Do i need to build my driver along with android source code???

Please suggest me how to proceed further???

Thanks and Regards,

Mutyala Rao.

Hi mutyalarao neelapala

Do you have already fixed this issue?

Unable to unload driver module "/system/bin/bluetooth.ko": Operation not permitted

************* bluetooth.c insmod is called**********

Failed to load module: Unknown error -1 (-1)

If so, could you please share with us what you have done in detail to overcome this?

Currently i have a similiar problem - think it's because of the permissions as well.

Version history
Revision #:
1 of 1
Last update:
‎01-21-2013 02:43 AM
Updated by: