Bonding in BT:
Once the device is get displayed on the device, after the inquiry then we will proceed
for the bonding. Then below function will get called when the user start then bonding procedure from device.
/packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
//
private void pair() ---> mCachedDevice.startPairing()
/frameworks/base/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
mDevice.createBond()
/frameworks/base/core/java/android/bluetooth/BluetoothDevice.java
// Start the bonding (pairing) process with the remote device. It is asynchronous call, it will return immediately.
Register for #ACTION_BOND_STATE_CHANGED intentes to be notified when the bonding process
completes, and its result.
public boolean createBond()
/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterService.java
// It will send event to BondStateMachine.CREATE_BOND
public boolean createBond(BluetoothDevice device, int transport)
1. /packages/apps/Bluetooth/src/com/android/bluetooth/btservice/BondStateMachine.java
[createBond()]--> mAdapterService.createBondNative(addr, transport):from here the call will go to the native. to create the bond.--> createBondNative();
2. same file : BONDING_STATE_CHANGE--> go for weather the current state is bonded, none, bonding.
/packages/apps/Bluetooth/jni/com_android_bluetooth_btservice_AdapterService.cpp
sBluetoothInterface->create_bond()
3. /packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java
onBondStateChanged()-> This function sahll be invoked from BondStateMachine whenever th bond sate changes.
4. /hardware/libhardware/include/hardware/bluetooth.h [HAL layer]
int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
5. /system/bt/btif/src/bluetooth.c
static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
6. /system/bt/btif/src/btif_dm.c
// It will post event #BTIF_DM_CB_CREATE_BOND.
bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
// and the call will come to here
btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
BTA_DmBondByTransport()
btif_hh_connect(bd_addr); // only for the HID device other wise for BR_EDR above call.
NOTE:
1. When the call will go to [btif_dm_cb_create_bond], it will call [bond_state_changed] and then
call will go to the application layer i.e bond state is changed not , from "bond_none" to bonding.
7. /system/bt/bta/dm/bta_dm_api.c
// It will initiates a bonding procedure with a peer device. and post the event: BTA_DM_API_BOND_EVT
BTA_DmBondByTransport() or BTA_DmBond()
8. /system/bt/bta/dm/bta_dm_act.c
void bta_dm_bond (tBTA_DM_MSG *p_data)
9. /system/bt/stack/btm/btm_sec.c[this file contain regarding securitypairing SSP adn link key]
// It perform bonding with peer device. If the connection is already up, but not secure, pairing
is attempted. If already paired BTM_SUCCESS is returned.
BTM_SecBondByTransport()--> btm_sec_bond_by_transport()
btm_sec_bond_by_transport --->This is bond function that will start either SSP or SMP
//This function is cllled to perform bonding with peer device. If connection is already up, but not secure,
pairing is attempted. If already paired BTM_SUCCESS is returned.
BTM_SecBond() --> btm_sec_bond_by_transport
btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_PIN_REQ);
// IF the device matches with stored paring address reset the paring state to idle.
btm_sec_change_pairing_state(BTM_PAIR_STATE_IDLE);
10. /external/bluetooth/bluedroid/stack/btm/btm_sec.c
// This is bond function that will start either SSP or SMP.
btm_sec_bond_by_transport()
No comments:
Post a Comment