Bluedroid stack in android

Bluedroid stack in android


Table of Contents

  • Bluetooth stack in android
  • Bluedroid .VS. Bluez
  • Porting guide of Bluedroid stack

1 Bluetooth stack in android

From Android 4.2, google use Bluedroid stack as its default Bluetooth host stack, before android 4.2, its default Bluetooth host stack was Bluez, which is also the Linux distribution's default stack. So why google changed its Bluetooth stack? The reason is maybe that Bluez stack was designed for the desktop environment, so in order to port Bluez into android, android must solve some dependency issues, like porting Dbus, Linux desktop's default IPC, into android. So there are at least five processes to power Bluetooth before android 4.2, they are systems, Bluetooth APP, Bluez, hciattach, and Dbus. The damn thing is that there are bugs between them, so Bluetooth stack is the weakest part in the android system before android 4.2, yeah, it is the usual reason that android system corrupted.

So, what's the difference between Bluedroid and Bluez stack, Bluedroid was developed by Broadcom, a famous wireless communication technology company, which is more suitable for embedded equipment? According to the following scratch, there are only two processes left to driver Bluetooth subsystem up by use the Bluedroid stack, the Bluetooth APP process and system framework process. The Bluedroid stack is running and embedded in the Bluetooth App process. I think this design simplified the Bluetooth subsystem.

+--------------------------------------+
|       Application Framework          |
|   +-----------------------------+    |
|   |       BT Apps API           |    |
|   |    android.bluetooth        |    |
|   +-----------------------------+    |
+-----------------^--------------------+
                  |
                  |Binder
                  |
+-----------------v--------------------+
|   Bluetooth process: Packages/apps/  |
|                      Bluetooth       |
|                                      |
|   +------------------------------+   |
|   |      Bluetooth Service       |   |
|   +------------------------------+   |
|   |      Bluetooth Profiles      |   |
|   +------------------------------+   |
+-----------------^--------------------+
                  |
                  |JNI
                  |   
+-----------------v--------------------+
|   HAL hardware/libhardware/include/  |
|                           hardware/  |
|                                      |
|  +--------------------------------+  |
|  |   Bluetooth HAL Interfaces     |  |
|  +--------------------------------+  |
|  |Bluetooth Profile HAL Interfaces|  |
|  +--------------------------------+  |
+----------------^---------------------+
                 |
                 |
+----------------v---------------------+
|  BlueDroid Stack /external/bluetooth/|
|                            bluedroid |
|                                      |
|  +---------------------------------+ |
|  |    Bluetooth App Layer          | |
|  +---------------------------------+ |
|  |  Bluetooth Embedded System      | |
|  +---------------------------------+ |
|  +---------------------------------+ |
|  |        Vendor Extensions        | |
|  |    /vendor/company/libbt-vendor | |
|  +---------------------------------+ |
+--------------------------------------+

2 Bluedroid .VS. Bluez

The primary difference of implementation details between Bluedroid and Bluez is that HCI layer was included in Bluedroid. HCI, short for host control interface, is the communication protocol between host stack and control stack, it has an implementation in Linux kernel, so it was excluded from the Linux's traditional Bluetooth stack, Bluez. Beside the HCI layer, Bluedroid excluded any IPC mechanism, that means it is not running in an independent daemon process anymore, instead, it have to embed into your system.

3 Porting guide of Bluedroid stack

So how to use Bluedroid in your system? Yeah, I have known Bluedroid is Broadcom's Bluetooth host stack for android and a much stable one, so what if I wanna porting Bluedroid stack into another system.
There are two parts of this question, or I separated this question into two phases.

  1. How to porting the Bluedroid stack into another operating system except android?
  2. How to driver another Bluetooth hardware instead of Broadcom's in Bluedroid?

Question one: The critical part is the btif directory in Bluedroid sources, I have to reimplement the btif part of Bluedroid stack, fortunately, there is already an android implementation in btif, that's a good reference.

Question two: There is a module named bt_vendor whose responsibility include resetting the communication bus, power management, and configuring firmware. So I need to adjust the bt_vendor module to drive the new hardware.

Comments

  1. Dont you think, btif is purely for android and we need to eliminate btif and communicate directly with bluedroid stack?

    ReplyDelete
  2. Good post. I am trying to dig into the native code of Android blueetooth APIs. Do you have any idea of how I should understand a simple connect API?

    ReplyDelete
  3. Hello Thanks for sharing. I am made some changes on the BLuedroid source code I've found on the internet and I want to port that code on my Android phone. Do you please know how to do that?

    ReplyDelete

Post a Comment

Popular posts from this blog

How to setup a NAT server?

Network programming in elisp