1 page.title=Bluetooth 2 @jd:body 3 4 <!-- 5 Copyright 2010 The Android Open Source Project 6 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 27 28 <p>Android provides a default Bluetooth stack, BlueDroid, that is divided into two layers: The Bluetooth Embedded System (BTE), which implements the core 29 Bluetooth functionality and the Bluetooth Application Layer (BTA), which communicates 30 with Android framework applications. A Bluetooth system service communicates with the Bluetooth stack through JNI and with applications through 31 Binder IPC. The system service provides developers access to various Bluetooth profiles. The following 32 diagram shows the general structure of the Bluetooth stack: 33 </p> 34 35 <p><img src="images/bt.png"></p> 36 37 <dl> 38 <dt>Application framework</dt> 39 <dd>At the application framework level is the app's code, which utilizes the <a 40 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a> 41 APIs to interact with the bluetooth hardware. Internally, this code calls the Bluetooth process through 42 the Binder IPC mechanism.</dd> 43 44 <dt>Bluetooth system service</dt> 45 <dd>The Bluetooth system service, located in <code>packages/apps/Bluetooth</code>, is packaged as an Android 46 app and implements the Bluetooth service and profiles at the Android framework layer. This app 47 calls into the HAL layer via JNI.</p> 48 49 <dt>JNI</dt> 50 <dd>The JNI code associated with <a 51 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a> is located in 52 <code>packages/apps/Bluetooth/jni</code>. The JNI code calls into the HAL layer and receives 53 callbacks from the HAL when certain Bluetooth operations occur, such as when devices are 54 discovered.</dd> 55 56 <dt>HAL</dt> 57 <dd>The hardware abstraction layer defines the standard interface that the <a 58 href="http://developer.android.com/reference/android/bluetooth/package-summary.html">android.bluetooth</a> APIs 59 and Bluetooth process calls into and that you must implement to have your bluetooth hardware 60 function correctly. The header files for the Bluetooth HAL is located 61 in the <code>hardware/libhardware/include/hardware/bluetooth.h</code> and 62 <code>hardware/libhardware/include/hardware/bt_*.h</code> files. 63 </dd> 64 65 <dt>Bluetooth stack</dt> 66 <dd>The default Bluetooth stack is provided for you and is located in 67 <code>external/bluetooth/bluedroid</code>. The stack implements the generic Bluetooth HAL as well 68 as customizes it with extensions and configuration changes. 69 </dd> 70 71 <dt>Vendor extensions</dt> 72 <dd>To add custom extensions and an HCI layer for tracing, you can create a libbt-vendor module 73 and specify these components. 74 </dd> 75 76 </dl> 77 78 79 <h2 id="implementing">Implementing the HAL</h2> 80 <p>The Bluetooth HAL is located in the <code>hardware/libhardware/include/hardware/</code> directory 81 and consists of the following header files: 82 83 <ul> 84 <li><code>bluetooth.h</code>: Contains the HAL for the Bluetooth hardware on the device</li> 85 <li><code>bt_av.h</code>: Contains the HAL for the advanced audio profile.</li> 86 <li><code>bt_hf.h</code>: Contains the HAL for the handsfree profile.</li> 87 <li><code>bt_hh.h</code>: Contains the HAL for the HID host profile</li> 88 <li><code>bt_hl.h</code>: Contains the HAL for the health profile</li> 89 <li><code>bt_pan.h</code>: Contains the HAL for the pan profile</li> 90 <li><code>bt_sock.h</code>: Contains the HAL for the socket profile.</li> 91 </ul> 92 93 </p> 94 95 <p>Keep in mind that your Bluetooth implementation is not constrained to the features 96 and profiles exposed in the HAL. You can find the default implementation located 97 in the BlueDroid Bluetooth stack in the <code>external/bluetooth/bluedroid</code> directory, 98 which implements the default HAL and also extra features and customizations.</p> 99 </p> 100 101 <h2>Customizing the BlueDroid Stack</h2> 102 103 <p>If you are using the default BlueDroid stack, but want to make a few customizations, you can 104 do the following things:</p> 105 106 <ul> 107 <li>Custom Bluetooth profiles - If you want to add Bluetooth profiles that do not have 108 HAL interfaces provided by Android, you must supply an SDK add-on download to make the profile available to app developers, 109 make the APIs available in the Bluetooth system process app (<code>packages/apps/Bluetooth</code>), and add them 110 to the BlueDroid stack (<code>external/bluetooth/bluedroid</code>).</li> 111 <li>Custom vendor extensions and configuration changes - You can add things such as extra AT commands or device-specific configuration changes 112 by creating a <code>libbt-vendor</code> module. See the <code>vendor/broadcom/libbt-vendor</code> directory 113 for an example.</li> 114 <li>Host Controller Interface (HCI) - You can provide your own HCI by creating a <code>libbt-hci</code> module, which 115 is mainly used for debug tracing. See the <code>external/bluetooth/hci</code> directory for an example.</li> 116 </ul> 117