Thursday, October 15, 2015

Bluedroid Stack

Directory Structure  of Bluedroid in Android:



BLuedroid Folder Structure description:

a) audio_a2dp_hw/  -->  A set of audio interfaces for external audio module to inject their implementation of these audio interface.

b) bta/  -->  It is Bluetooth application profile layer, The btif will call bta.

c) btif/  --> All the Bluetooth JNIs will direct;ly intract with btif

d) conf/ --> Configuration files for bluedroid ( Ex. debugging level, path of snoop log)

e) embdrv/ ---> SBC encoder/decoder

f) gki/  --> Defines a tiny embedded os based on pthread, It means generic kernel interface

g) HCI/ --> Implementation for HCI ( Ex. To compose the HCI command and emit it)

h) main/ --> The core initialization function for the Bluedroid( Initialze OS/HCI etc

i) osi/ --> OS interface for gki, ( Ex. Alarm/queue/list)

j) stack/ --> the bluetooth core stack, Between BTA and HCI

k) test/ --> A test tool for bluedroid ( framework and command line test tool)

l) udrv/ --> Implementation for UIPC ( IPC)

m) utils/ --> HElper function for bludroid

n) vnd/ --> Implementation for vendor features, ( Android's BLE proprietary features)


------------------------------STACK-------------------------------------



BT IF – Bluetooth Interface layer:
Implements the HAL interfaces that are invoked by the JNI calls
Maintains the callbacks registered by JNI
JNI callbacks are invoked by the IF layer based on the updates from the BTA/Stack
 
BTA – Bluetooth Application Layer:

Implements the Bluetooth profiles 
Maintains the profiles state machines
Handles events from the Stack and sends it back to IF layer

Bluedroid Stack:
Implements all protocols

HCI Layer:
HCI layer built as a shared library (libbt-hci) and acts as an interface between the transport layer and the stack. 
Support for the HCI H4 or the SMD transport – glues the serial driver calls for instance, with the upper layers

-----------> Bluedroid component---<
Structure is split into the following parts 
Application Specific Layer
ex. contains Bluetooth APK and android Services for Profiles. 
Bluetooth Middleware components
 ex. Bluetoothheadsetservice  and JNI System Object (libbluetooth_jni) 
Bluetooth Profile Interface (BTIF)  and stack adaptation layer (BTA =>  libbt-brcm_bta system object)
Core Stack (libbt-brcm_stack) and HCI Transport interface (libbt-hci)
Kernel drivers for transport layers like Serial, USB, SDIO 
Real Physical Hardware  (SOC)


Bluedroid stack, profiles and application run in a single user space process “com.android.bluetooth”
Bluetooth code runs in the context of 4 Tasks
BTIF_TASK
BTU_TASK
A2DP_MEDIA_TASK
GKI_TIMER_TASK
Communication between the above tasks is through MESSAGE_QUEUE
// Example:
void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEARCH_CBACK *p_cback)
208{...
 bta_sys_sendmsg(p_msg);
}
571void bta_sys_sendmsg(void *p_msg)
572{
573    // There is a race condition that occurs if the stack is shut down while
574    // there is a procedure in progress that can schedule a task via this
575    // message queue. This causes |btu_bta_msg_queue| to get cleaned up before
576    // it gets used here; hence we check for NULL before using it.
577    if (btu_bta_msg_queue)
578        fixed_queue_enqueue(btu_bta_msg_queue, p_msg);
579}

API calls from JNI are transferred to BTIF_TASK context by posting messages
JNI/HAL callbacks run in the context of BTIF_TASK
BTIF Task intern will switch the context to BTU_TASK based on the request
Profile and Protocol implementation run in the context of BTU_TASK
Bluetooth transport driver has Rx thread to read data from UART/SMD (bt_hc_worker_thread)

No comments:

Post a Comment

Qualcomm Short Term

  113 is the SL. 1st Target by mid July.

Total Pageviews