How to use UART3 for bluetooth HCI?

96boards

#61

Ok, so first off, undo everything you did with that domain. I think you’re just giving yourself a hard time with it. What you want to do is mimic the existing (working) bluetooth adapter, which is;

crw-rw---- 1 system bluetooth u:object_r:console_device:s0 204, 67 2018-05-01 12:04 ttyAMA3
crw------- 1 root root u:object_r:device:s0 10, 61 2018-05-01 11:47 rfkill

Second, since you are running permissive, the selinux denials are NOT ACTUALLY DENYING ANYTHING, which means that if it isn’t working, there is some other problem that you need to address first.

And let me ask you this; why are you trying to use a different bluetooth adapter?


#62

Ok, When I undo those changes I’ve same issue, my BT service is still crashing. (with writesafely function returning error)

I can see only one adapter rfkill , can’t see the other one. My BT USB is found under this location . /dev/bus/usb/001(.*) …


#63

You don’t need hciattach in your case since a hci device should be automatically created by the Bluetooth USB driver.

Do you have a hci device created when pluggin the USB BT dongle (in /sys/class/bluetooth/) ?
You can check and set rfkill state via sysfs sys/class/rfkill/rfkillX/state.


#64

Hello Loic

Yes, I have hci0 created in the /sys/class/bluetooth/ and state of rfkill is 1 (?) . Since I have it created , are you pointing me to use /dev/rfkill instead of /dev/bus/usb/001(.*) ?

sys/class/rfkill/rfkill2 # ls -ltr

lrwxrwxrwx 1 root root 0 1970-01-01 17:51 device -> …/…/hci0

Internally it is pointing to hci0


#65

Hello Loic/doitright,

I discard those modifications, My BT device comes up (show running) and crash. Here is the error:

01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 6 retval 0
01-01 01:16:47.977 2894 2944 D android.hardware.bluetooth@1.0-impl: OnFirmwareConfigured Calling StartLowPowerWatchdog()
01-01 01:16:47.978 2894 2944 I bt_vendor: bt_vendor_op op 1 retval 0
01-01 01:16:47.978 19851 19885 I bt_hci : event_finish_startup
01-01 01:16:47.978 19851 19871 I bt_core_module: module_start_up Started module "hci_module"
01-01 01:16:47.980 19851 19888 I bt_osi_thread: run_thread: thread id 19888, thread name bt_workqueue started
01-01 01:16:47.980 19851 19888 I bt_btu : btu_task pending for preload complete event
01-01 01:16:47.980 19851 19888 I bt_btu_task: Bluetooth chip preload is complete
01-01 01:16:47.980 19851 19888 I bt_btu : btu_task received preload complete event
01-01 01:16:47.981 19851 19888 E bt_att : gatt_profile_db_init: gatt_if=1
01-01 01:16:47.981 19851 19889 I bt_osi_thread: run_thread: thread id 19889, thread name module_wrapper started
01-01 01:16:47.981 19851 19889 I bt_core_module: module_start_up Starting module "controller_module"
01-01 01:16:47.982 2894 2944 I bt_vendor: bt_vendor_op op 7
01-01 01:16:47.982 2894 2944 I bt_vendor: bt_vendor_op op 7 retval 0
01-01 01:16:47.982 2894 2944 E android.hardware.bluetooth-hci-hci_protocol: WriteSafely error writing to UART (Invalid argument)
01-01 01:16:49.983 19851 19874 E bt_hci : command_timed_out: 1 commands pending response
01-01 01:16:49.983 19851 19874 E bt_hci : command_timed_out: Waited 2001 ms for a response to opcode: 0xc03 matches timer
01-01 01:16:49.983 19851 19874 E bt_hci : command_timed_out: Size 3 Hex 03 0c 00
01-01 01:16:49.983 19851 19874 E bt_hci : command_timed_out: requesting a firmware dump.
01-01 01:16:49.983 2894 2944 E android.hardware.bluetooth-hci-hci_protocol: WriteSafely error writing to UART (Invalid argument)
01-01 01:16:49.983 19851 19874 E bt_hci : command_timed_out restarting the Bluetooth process.
01-01 01:16:50.484 19851 19874 F libc : Fatal signal 6 (SIGABRT), code -6 in tid 19874 (alarm_default_c)

Please let me know if you recognize the issue , after above error bluetooth process died and restarted service.


#66

Are you trying to use the bluetooth hal from hardware/interfaces/bluetooth/1.0/default/? You can’t use that one with Linux style bluetooth drivers. You need to use the hal in system/bt/vendor_libs/linux/interface/


#67

Hello doitright,

Yes , that’s where the Android O architecture is pointing (https://source.android.com/devices/bluetooth/) and do you mean by this http://androidxref.com/8.0.0_r4/xref/system/bt/vendor_libs/linux/ or I am missing some interface here ?

I have seen vendor_lib getting loaded during BT start up Or is the only thing I required (no android.hardware.bluetooth@1.0-impl) or implement my own .

Please correct me on this.


#68

Hello doitright,

I saw hikey code for BT, you have moved the HW interface to the /device/…/bluetooth to make it independent and calling the /dev/hci_tty (TI transport layer interface) and I can’t see hci_tty under /dev ?

Just for my understanding can you please explain all the changes (To make BT device working) you made and why? My understanding was layer structure is moved into Android (as explained by Loic too) .

Please correct me if above understanding is wrong?


#69
  1. I don’t work for linaro.

  2. Ignore the stuff in device/linaro/hikey/bluetooth/ --> That stuff is obsolete and only selected if you use kernel 4.4.

  3. Use the HAL in system/bt/vendor_libs/linux/

I am still curious about why you are trying to make a USB bluetooth dongle work on the board. Is this an academic exercise? Or do you have some special reason why you need to have 2 adapters?


#70

Ah ok :slight_smile:

I am using K4.4 … & doing for a client. We have a fresh board which we wanted to use and BT is not working.


#71

Yes look like you’re using the legacy Hikey hal here, Like doitright said, try to use the one in (system/bt/vendor_libs/linux/). This is configurable in your from your device makefile, cf (device/linaro/hikey/device-common.mk).

PRODUCT_PACKAGES += android.hardware.bluetooth@1.0-service.btlinux

Then please double check the HCI socket is correctly open in openBtHci (system/bt/vendor_libs/linux/)


#72

Hello Loic,

I am loading the vendor library from the /system/bt/vendor_libs/linux , Here are the log’s from the library.

bt_vendor: bt_vendor_init
01-01 01:16:47.977 2894 2944 I bt_vendor: Using interface hci0
01-01 01:16:47.977 2894 2944 D android.hardware.bluetooth@1.0-impl: Open vendor library loaded
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 0
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 0 retval 0
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 3
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_open
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_open returning 6
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 3 retval 1
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_op op 1
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_fw_cfg
01-01 01:16:47.977 2894 2944 I bt_vendor: bt_vendor_wait_hcidev
01-01 01:16:47.977 2894 2944 I bt_vendor: HCI device ready

It show the HCI device is ready.

And yes, this library is loaded from (/system/hardware/interfaces/bluetooth) , Are you saying I should’t load it from here and rather use android.hardware.bluetooth@1.0-service.btlinux, is this a wrapper service to just invoke the library ?


#73

THIS android.hardware.bluetooth@1.0-service.btlinux IS /system/bt/vendor_libs/linux
That is what you need to use.

THIS android.hardware.bluetooth@1.0-impl is /system/hardware/interfaces/bluetooth
That is NOT COMPATIBLE WITH YOUR HARDWARE. DO NOT USE IT.


#74

Thank you doitright for correcting me.

After I change it to the android.hardware.bl…btlinux , I dont see the crash however my bt_hci unable to start the hci_module.

01-01 00:01:04.210 462 563 E bt_hci : startup_timer_expired
01-01 00:01:04.211 462 559 E bt_core_module: module_start_up Failed to start up module "hci_module"
01-01 00:01:04.215 462 878 I bt_osi_thread: run_thread: thread id 878, thread name bt_workqueue started
01-01 00:01:04.216 462 878 I bt_btu : btu_task pending for preload complete event
01-01 00:01:04.216 462 878 I bt_btu_task: Bluetooth chip preload is complete
01-01 00:01:04.216 462 878 I bt_btu : btu_task received preload complete event
01-01 00:01:04.218 462 878 E bt_att : gatt_profile_db_init: gatt_if=1
01-01 00:01:04.220 462 879 I bt_osi_thread: run_thread: thread id 879, thread name module_wrapper started
01-01 00:01:04.220 462 879 I bt_core_module: module_start_up Starting module “controller_module”

I didn’t have any message after that for BT, I wonder if vendor_lib ever get called here.

This message was posted ever second:
01-01 00:01:01.195 462 732 W com.android.bluetooth: Waited one second for android.hardware.bluetooth@1.0::IBluetoothHci/default. Waiting another…

fyi, this is how my vendor_libs looks like (http://androidxref.com/8.0.0_r4/xref/system/bt/vendor_libs/linux/bt_vendor_linux.cc)

Please correct me here


#75

Might be time for you to start over from a clean slate, because you’ve made a whole heap of changes in switching from one HAL to another HAL to another HAL, and really all you needed to do in the first place is change a few system properties to direct it to the proper path for the new hardware. The file you linked to is the file that reads them.


#76

Yes, I got it working. Issue was I had the BT stack missing new changes in the code , was not expecting after all this struggle, moreover I thank you both for all the assistance.

Thank you :slight_smile:


#77

Hi Arnab,

I too trying to Port hcitool on Android 8 but I am getting build error. It is throwing shared library build error between system/bt stack and external/bluez stack.

Please help me with this issue. It will be very helpful if you can share the steps for how you build selective images as mentioned by Loic.

Thanks n Regards,
Wasim


#78

Dear Mr. Nazir,

If you are building it on Android 8, please follow the steps below :

  1. Download BlueZ (https://git.kernel.org/pub/scm/bluetooth/bluez.git)
  2. Place the downloaded ‘bluez’ folder inside - /device/linaro/hikey/bluetooth/
  3. Modify the makefile - /bluez/android/Android.mk (refer to this - https://pastebin.com/xJxWJzYq) and copy it to /device/linaro/hikey/bluetooth/
  4. Remove the Android.mk makefile from bluez/android/ (rename it to Android.mk.disabled)
  5. Compile and check if it works - mmma /device/linaro/hikey/bluetooth -j4
  6. Add the required BlueZ tools to device/linaro/hikey/hikey960/device-hikey960.mk as follows -
    PRODUCT_PACKAGES += hciattach
    PRODUCT_PACKAGES += hciconfig
    PRODUCT_PACKAGES += hcitool
  7. Compile and run on AOSP…

Please let me know if you find any issue.
Note : If you are using Android 9, you may have to do some extra steps as far as I remember.

Thanking you,

Regrads,
Arnab Dey


#79

Hi Arnab,

Thanks for you detailed explanation.

I copied all the files as mentioned above.
I copied the Android.mk file from the link mentioned and disable the other one.
Then I tried building with mmma <path/to/bluetooth>
This command fails with the error below:
ninja: error: unknown target ‘MODULES-IN–home-wasim.nazir-android_build-device-fsl-navico_6dq-bluetooth’

Can you help me with this.

Thanks & regards,
Wasim


#80

Dear Mr. Nazir,

You are using Android 8, right? To debug the issue, I would suggest to do the following -

  1. Revert back to original AOSP (I mean without whatever modification you have done to it)
  2. Compile and make it working properly.
  3. Add ONLY BlueZ changes to it. (No other modification which you might have done for other purpose)
  4. Compile.
  5. Check if it works.

Thanking you,

Regards,
Arnab Dey