blob: 13eb4b5425d8727628d95fefdaf34dde1031d67d [file] [log] [blame]
Robert Ly35f2fda2013-01-29 16:27:05 -08001page.title=Bluetooth
2@jd:body
3
4<!--
Heidi von Markham1e7b8b72015-03-09 10:13:48 -07005 Copyright 2015 The Android Open Source Project
Robert Ly35f2fda2013-01-29 16:27:05 -08006
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
26
Heidi von Markhamb493fb62015-03-25 12:35:11 -070027<img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_bluetooth.png" alt="Android Bluetooth HAL icon"/>
Robert Ly35f2fda2013-01-29 16:27:05 -080028
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070029<p>Android provides a default Bluetooth stack, BlueDroid, that is divided into two layers: The Bluetooth Embedded System (BTE), which implements the core Bluetooth functionality and the Bluetooth Application Layer (BTA), which communicates with Android framework applications.</p>
30
Bert McMeenbf880eb2015-03-24 10:37:54 -070031<p>To fully leverage the <a href="http://developer.android.com/about/versions/android-5.0.html#BluetoothBroadcasting">Bluetooth Low Energy APIs</a> added in Android 5.0, you should implement the <a href="Android-5.0-Bluetooth-HCI-Reqs.pdf">Android 5.0 Bluetooth HCI Requirements</a>.</p>
32
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070033<h2 id="architecture">Architecture</h2>
34<p>A Bluetooth system service communicates with the Bluetooth stack through JNI and with applications through Binder IPC. The system service provides developers access to various Bluetooth profiles. The following diagram shows the general structure of the Bluetooth stack:
Robert Ly35f2fda2013-01-29 16:27:05 -080035</p>
36
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070037<img src="images/ape_fwk_bluetooth.png" alt="Android Bluetooth architecture" id="figure1" />
Clay Murphy1b77cc22014-12-17 18:20:06 -080038<p class="img-caption">
39 <strong>Figure 1.</strong> Bluetooth architecture
40</p>
Robert Ly35f2fda2013-01-29 16:27:05 -080041
42<dl>
43 <dt>Application framework</dt>
44 <dd>At the application framework level is the app's code, which utilizes the <a
45 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a>
46 APIs to interact with the bluetooth hardware. Internally, this code calls the Bluetooth process through
47 the Binder IPC mechanism.</dd>
48
49 <dt>Bluetooth system service</dt>
50 <dd>The Bluetooth system service, located in <code>packages/apps/Bluetooth</code>, is packaged as an Android
51 app and implements the Bluetooth service and profiles at the Android framework layer. This app
Bert McMeen2122a972015-01-27 12:35:25 -080052 calls into the HAL layer via JNI.</dd>
Robert Ly35f2fda2013-01-29 16:27:05 -080053
54 <dt>JNI</dt>
55 <dd>The JNI code associated with <a
56 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a> is located in
57 <code>packages/apps/Bluetooth/jni</code>. The JNI code calls into the HAL layer and receives
58 callbacks from the HAL when certain Bluetooth operations occur, such as when devices are
59 discovered.</dd>
60
61 <dt>HAL</dt>
62 <dd>The hardware abstraction layer defines the standard interface that the <a
63 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a> APIs
64 and Bluetooth process calls into and that you must implement to have your bluetooth hardware
65 function correctly. The header files for the Bluetooth HAL is located
66 in the <code>hardware/libhardware/include/hardware/bluetooth.h</code> and
67 <code>hardware/libhardware/include/hardware/bt_*.h</code> files.
68 </dd>
69
70 <dt>Bluetooth stack</dt>
71 <dd>The default Bluetooth stack is provided for you and is located in
72 <code>external/bluetooth/bluedroid</code>. The stack implements the generic Bluetooth HAL as well
73 as customizes it with extensions and configuration changes.
74 </dd>
75
76 <dt>Vendor extensions</dt>
77 <dd>To add custom extensions and an HCI layer for tracing, you can create a libbt-vendor module
78 and specify these components.
79 </dd>
80
81 </dl>
82
83
84<h2 id="implementing">Implementing the HAL</h2>
85<p>The Bluetooth HAL is located in the <code>hardware/libhardware/include/hardware/</code> directory
86 and consists of the following header files:
87
88<ul>
89 <li><code>bluetooth.h</code>: Contains the HAL for the Bluetooth hardware on the device</li>
90 <li><code>bt_av.h</code>: Contains the HAL for the advanced audio profile.</li>
91 <li><code>bt_hf.h</code>: Contains the HAL for the handsfree profile.</li>
92 <li><code>bt_hh.h</code>: Contains the HAL for the HID host profile</li>
93 <li><code>bt_hl.h</code>: Contains the HAL for the health profile</li>
94 <li><code>bt_pan.h</code>: Contains the HAL for the pan profile</li>
95 <li><code>bt_sock.h</code>: Contains the HAL for the socket profile.</li>
96</ul>
97
98</p>
99
100<p>Keep in mind that your Bluetooth implementation is not constrained to the features
101 and profiles exposed in the HAL. You can find the default implementation located
102 in the BlueDroid Bluetooth stack in the <code>external/bluetooth/bluedroid</code> directory,
103 which implements the default HAL and also extra features and customizations.</p>
104</p>
105
106<h2>Customizing the BlueDroid Stack</h2>
107
108<p>If you are using the default BlueDroid stack, but want to make a few customizations, you can
109 do the following things:</p>
110
111<ul>
112 <li>Custom Bluetooth profiles - If you want to add Bluetooth profiles that do not have
113 HAL interfaces provided by Android, you must supply an SDK add-on download to make the profile available to app developers,
114 make the APIs available in the Bluetooth system process app (<code>packages/apps/Bluetooth</code>), and add them
115 to the BlueDroid stack (<code>external/bluetooth/bluedroid</code>).</li>
116 <li>Custom vendor extensions and configuration changes - You can add things such as extra AT commands or device-specific configuration changes
117 by creating a <code>libbt-vendor</code> module. See the <code>vendor/broadcom/libbt-vendor</code> directory
118 for an example.</li>
119 <li>Host Controller Interface (HCI) - You can provide your own HCI by creating a <code>libbt-hci</code> module, which
120 is mainly used for debug tracing. See the <code>external/bluetooth/hci</code> directory for an example.</li>
121</ul>