Skip to content

Commit

Permalink
BLE:: Refactoring BLE code changes to Q Stack
Browse files Browse the repository at this point in the history
BLE Adv RPA is not updated on first timeout

BLE Advertisement RPA is getting updated with the
same RPA instead of the newly generated RPA on the
first timeout. Make sure to send the newly generated
RPA to the Controller.

Bug: 65857055
Change-Id: I4d8e95c26fe8e5944fdee32089b8fcaffa238367

Remove unnecesary BTA redefinitions for GATT part 1

Test: compilation test
Change-Id: I98ab63a187684ae4ffbb0cb23e5c9e67994be468

Remove unnecesary BTA redefinitions for GATT part 2

Test: compilation test
Change-Id: Iaf81188596c33b92f79f163dc95187ed5c6f52a4

Remove unnecesary BTA redefinitions for GATT part 3

Test: compilation test
Change-Id: I8d4b8cfd35fcb5ccd7067f1e02dedd1a58efa3ad

Remove unnecesary BTA redefinitions for GATT part 4

Test: compilation test
Change-Id: Ibe37a1c6506d567b68497e8c7074d90cd73ddf00

SMP: Use tSMP_INT_DATA instead of void

Test: pairing sanity
Change-Id: Ie3a2f94ddd718344219760cef7f1477bd4d09e00

Refactor btm_ble_resolving_list_load_dev

Test: compilation
Change-Id: I69fd4d9df63801bcc8b529d95bee74fd06c86249

Remove unused events handler for BLE scan clients

These events should be handled only for GATT clients, not for BLE
scanner.

Bug: 67058417
Test: compilation
Change-Id: I70744d3c6fd7eb40d839863f7413a7521ca0b2e9

Add more logs for Bluetooth connection errors

Test: manual
Change-Id: I63402ee8ffa8f57a70a9c9aaa0370d8ca599bbea

Add comments to function arrays to indicate usage

No logic change. More comments are added to function arrays to indicate
how each array entry are used.

Test: Manual
Change-Id: I59283cb9786da6f3a4b8a4b36e36e79a25ca6cb8

Use std::list in GATT related code

Bug: 67057055
Test: sl4a Gatt* tests
Change-Id: I8201ebdad5ba4c3d5d0a2fd3d0fe9dc900b51d60

Run clang format on files touched by CL 488398

https://android-review.googlesource.com/#/c/488398/

Test: build
Change-Id: Iefbd5b632087be00a12b1a0c851f9e3f3b514532

Use unary operator instead of == bool

Automatically generated with coccinelle:

@@
expression e1;
@@

-e1 == false
+!e1

@@
expression e1;
@@

-false == e1
+!e1

@@
expression e1;
@@

-e1 == true
+e1

@@
expression e1;
@@

-true == e1
+e1

Test: build
Change-Id: Ic7df0dc43b550594855e457466b6bccd8f3443a3

Manually convert to unary where coccinelle could not

Test: build
Change-Id: I7b5ea758b94bf225e8776f64256d644c3e96b198

Use LOG() macros in BTA GATT logging

Test: compilation test
Change-Id: If7676af5bf915df57ab6e876d2f27500ebf5c07d

BTA GATT cache cleanup bta_gattc_disc_res_cback

Bug: 67057055
Test: compilation test
Change-Id: Iccfffe5de654070058ce3f4af3f48fa0975b7cf3

BTA GATT cache cleanup bta_gattc_srvc_in_list

Bug: 67057055
Test: compilation test
Change-Id: I22e752c1d270128ff0ae4f633d4f3eccf4cb725e

BTA GATT cache cleanup bta_gattc_discover_pri_service

Bug: 67057055
Test: compilation test
Change-Id: I23464a61282d60400ae36debc820c66a4f1a1e1a

gatt_act_discovery indentation fix

Bug: 67057055
Test: compilation test
Change-Id: I22640f47b5faf6e1d8718dec003b3cc83b51c514

gatt_utils minor style fixes

Test: compilation
Change-Id: I76f3f26b5140b7b60508756b1e841b09aeeb5e7d

Minor style fixes in bta_gattc_act.cc

Bug: 67057055
Test: compilation test
Change-Id: I862f2da834cf6f5a024ee7321229c337980f3638

bta_gattc_cache: prepare for type unification

Bug: 67057055
Test: compilation
Change-Id: I46eb07a8f118b61551b3adc404ec306ad6a14b9c

Remove casts in bta/ and stack/btm

Make pointers to const structs const pointers.
Pass complete unions instead of casting smaller objects.

Test: build
Change-Id: I7d6b61183554be70ac7f58f4133a76ec68e35408

btif: Use key types to avoid casting

Test: build
Change-Id: If816c480219552dc8833b094a6228817883b774d

stack: Remove casts and spell local_keys correctly

Test: build
Change-Id: Ide6ec9528e1f8efca9850eab53aa2bdb88ba363d

bta_gattc_explore_srvc minor style fixes

Bug: 67057055
Test: compilation
Change-Id: I37c5a138ccddcb1ddd09e3efb5dfcdaeb5bdad04

Restart legacy advertising after successfull connection

Bug: 66139617
Test: run CTS Bluetooth LE Insecure Client Test
Change-Id: I894391f608d9ac7a625dc936cf27027fd3ab6140

Use vector instead of list for keeping GATT database content

We don't use any list features, but have to pay extra for it's features.
Replace with vector.

Bug: 67057055
Test: compilation
Change-Id: I4209c24b4f87780ea29e4e0707ce0a2a0d440d6b

GATT discovery refactor

Currently, when doing service discovery, we store pending discovery
content into tBTA_GATTC_ATTR_REC structure, and rewrite it into cache,
service after service during discovery.
From now on, we save discovery result directly into pending_discovery,
and at end of discovery we swap it with cache. This remove unncecessary
intermidiate step, and simplify the discovery.

Bug: 67057055
Test: GattReadTest
Change-Id: Id09026b6fb6df04eaf0a0ebefeb6e35b3d175f62

Change the connecting state to FALSE for BLE devices while releasing LCB

To reconnect a paired BLE device, the connecting stage should change to
FALSE when LCB is releasing. BLE device should be in connectable state to
connect the device next time.

BUG: 64432592
Test: reconnecting a paired BLE mouse failed randomly
Change-Id: I2c9016a267c9f5cd10d1eb05751eceb6046fbdb5

Add missing space in GATT_Register log

Test: none
Change-Id: Idab3083daa68a958f33b264db1ff5e2f0c211ba5

Find connection ID on BR/EDR

GATT profile may send service change indication to its
connected client and gatt_profile_find_conn_id_by_bd_addr
function helps gatt profile to find its connected client.
Gatt profile may use a BR/EDR link. So need to check it
also to avoid missing.

Test: manual
Change-Id: Ieb64cf6eab9d94352440c876be69990a7a4eb57f

BTA GATT operation queue

Currently, HID BTA app have own GATT queue for scheduling reads/writes
during device setup. Such queue will also be needed for Hearing Aid.
This patch makes the GATT queue code generic and clean it up.

Test: manual, bond HID device
Bug: 69623109
Change-Id: Ic893d630ab5154f7c1875748f3e275cbad02a7b2

GATT cache memory corruption fix

When doing GATT discovery, we interleave adding elements to vector,
and storing pointers to them. This can cause memory corruption, because
vector can reallocate the memory when adding element, leaving the pointers
invalid. To fix that, never store pointers to mutable vector elements.

Bug: 70041392
Test: manual, connected to HID device
Change-Id: I6bb3fec61afa742f446b66e3291c5f326738ee17

Fix GATT discovery service fail over BR/EDR

According to the current gattc state machine, stack queues
discovery services request comes from framework when gattc
is in BTA_GATTC_DISCOVER_ST state. This request is re-scheduled
after discovery on server finished in bta_gattc_disc_cmpl
and return the discovery results to framemwork. But now, stack
assumed LE transport in code, which prevents discovery services
executing. This error can be detected by ACTS GATTOverBrEdrTest:
test_gatt_bredr_connect_trigger_on_services_discovered

Fix assumed transport to actual situantion

Test: ACTS GATTOverBrEdrTest:
test_gatt_bredr_connect_trigger_on_services_discovered
Change-Id: I110a0a3c19595fb76c3bb15b092ce18ebf7b11bf

Minor GATT logging fixes

Test: compilation
Bug: 70297056
Change-Id: If71bbb19a08abbbb30b5ce5027aed97e03b3baaa

Advertising Filtering: send all filters in one batch (2/2)

Bug: 67371480
Test: sl4a FilteringTest
Change-Id: I93595b5ed4e7cf25cdb6a8b1f9413a7f05e61774

BLE: Don't set SC bit in AuthReq for Legacy Devices

Disable SC bit for legacy LE devices (< 4.2) since as per earlier
spec, this BIT should be 0 and ignored by remote device. Some remote
legacy devices which don't follow the approach of ignoring these bits
(if set) go in bad state and result in SMP pairing failure.

Test: Pairing succeeds with remote device after resettings SC bit.

Fixes: 70259025
Change-Id: I35838c60fb08916a141f764b3e1922d277b99f28

Remove casts for callbacks

Casting callbacks can hide parameter mismatches from
the compiler, which makes it impossible to check
argument types.

Bug: 72005262
Test: Toggle Bluetooth, connect to a headset
Change-Id: I0c3e0653c77e829655377fbf170d1b03efa5ea32

Add Connection Event Min/Max hint to Connection Update Request

Bug: 69623109
Test: manual on HA
Change-Id: Idc08d08029f287751fafb4a8e2379dcc118e5ac3

Minor improvements in LE Create Connection handling

1. According to spec, controller should never send "Command Complete" event
after "LE Create Connection" or "LE Extened Create Connection" command.
Add error message in such case.

2. Parse Comand Status for LE Enhanced Create Connection.

3. Fix NPE in btm_ble_update_mode_operation, when called from
btm_ble_create_ll_conn_complete.

Test: Bond/unbond with few LE devices while connected.
Change-Id: Ic135d9a8d096634afe33997afb42d054237598c2

Set pending_discovery when doing GATT over BR/EDR

SDP discovery can return services before LE discovery, or after LE
discovery is already done. In both cases, pending_discover is not a
valid pointer, and must be set before call to bta_gattc_explore_srvc

Test: sl4a GattOverBrEdr
Change-Id: I2b43d2348edfa641c56a8085a92b6367b146030d

Add more details in native Bluetooth debug logs

As part of debugging a security/pairing issue, these logs are modified
to give better debug information.

Test: compiled
Bug: 71364658
Change-Id: I742cc7dda0afc6350e881c22d03bdc1c69d37d88

Reduce spammy error log in gatt_attr.cc, plus minor logging improvements

Test: compilation, observe colored log output on startup
Change-Id: I6671f5a900f15a57cc9b38b01aaec296002ad233

BLE: Don't access freed buffer in log message

When GATT fail to write data on L2CAP, buffer is freed by L2CAP.
Accessing the buffer leads to fatal failure while printing the message info.

Test: BLE discover services and BT off test cases

Fixes: 73018520
Change-Id: I661398fd1321f6e68026b3720db4965fd6584d70

bta_gattc_sdp_callback move null check above first usage

Bug: 75311714
Test: Test scenario described in _bug
Change-Id: Ib2da24134205277ae03cf28394db74758de17e5d

Guard ACPF with proper checks

Fail on calls to  ACPF when it's not supported in controller.
Right now we sent such commands when starting/stopping the regular scan.

Bug: 69116550
Test: Enable bluetooth on platform without ACPF, start/stop scan
Change-Id: I334114d36a8af8c8f58d230f75ab3a00f009c4c5

Use proper HCI_ERR_* constants in advertisement termination handling

There is no functional change, just making the code pretty, and updating
names to match 5.0 specification.

Test: sl4a AdvertisingSetTest:test_reenabling
Bug: 74198564
Change-Id: I1811e19bd18470adda55f7af7cfee23bcc4d1871

Pass new LE CoC min_ce/max_ce parameters to native stack

Add new test connection event (ce) parameters, min_ce and max_ce, to
the SL4A tests for LE Connection-oriented Channel (CoC) feature.

Test: Run cmd: act.py -c $MY_SL4A_CONFIG -tc BleCoc2ConnTest
Bug: 77528723

Change-Id: Ifea040f0eb105f89539e6b74f5c2edc76147a065

GATT: make last service end group handle equal to 0xFFFF

ESR06 (errata 4065) added sentence:
"The End Group Handle of the last service in a device can be 0xFFFF."
It talks about last service, not last primary service. Right now,
secondary service added after last primary service will result in in
last primary service being corrupted - descriptor added to last
characteristic, and some characteristics added.

Bug: 78107486
Change-Id: I6a146fce2c946cdff176ff79f147830e29d3b807

GATT: fix 32 bit UUID handling

When writing UUID into stream with gatt_build_uuid_to_stream, we always
use 16bit or 128bit representation. In GATT code returning service UUID,
we were returning 32bit representation lenght, even though 128bit
representation was being returned in the stream. This resulted in
invalid GATT database content being returned, and the service not being
visible.

Bug: 66912853
Test: create GATT database with 32bit UUID, discover from remote device
Change-Id: I791a518ab080bd99db0a8be18d97e865c838fc7e

Add ability to modify IO capability of Bluetooth device

Redirects all access to Bluetooth IO capability from
macros. This allows it to be config determined but fall back to #define
values to maintain backward compatibility.

There is also the addition of methods to set IO capability properties.
Since these are done at the adapter level, it reuses
set_adapter_property from the bluetooth interface by adding new
property configs.

Bug: 36015413
Test: Created a test activity to modify values using the API and pair
with different settings. Default value is picked up from macro.

Change-Id: I7b80ea70cef4eacab91d20a58e745281aed273cd
(cherry picked from commit 7a5281f7ffe6860f15fcc088c63b1109f98c0e0e)

BTM_BleClearBgConnDev: Return if there is no BLE

Bug: 77495521
Bug: 76192234
Test: Start Bluetooth with a BT 3.0 chip (or a simulated one)
Change-Id: I718b7532bbba6100dd51c0677a44d41a2db0ce26

Return early if vendor-specific command fails

Add CHECK() statements to _crash if the callback is passed the incorrect
opcode or if there are no parameters.

Bug: 76192234
Bug: 77495521
Test: Start Bluetooth with a BT 3.0 chip (or a simulated one)
Change-Id: Iddd9a8503b2cfd52b16fb1c59f40e108b478e7b6

Fix PTS: TC_GATT_SR_UNS_BI_01_C sends unsupported opcode

In this PTS test, add code to send back an unsupported error response
when an unsupported OpCode is received.

Bug: 79347869
Test: Rerun and pass PTS test
Change-Id: Ibf95dbc18dabbe201850da675c7a1b2739624de9

Fix LE cancel open when physical connection is established but not ready

Issue:
Cancel open does not work when the physical connection is established
but negotiation is not finished.

Fix:
Close the physical connection and release resources when fitting in this
situation.

Bug: 64230040
Test: test_cancel_open_ble_process
Change-Id: Ia23b5f3aab427b333d9d484b97e4cd4ff49f5319

Use identity addr in BLE scan filter

For BT controllers with the ability to filter scans and resolve RPAs on
controller, when trying to filter for a Public ID type address the
filter must use the static identity address of the peer device instead
of the random pseudo address.

Bug: 78888800
Test: manually tested filtered scanning for BLE peer with RPA with a
device with both offloaded RPA resolution & controller filtering
supported. Tested on a device with no controller filtering, which has
no changes, as expected.

Change-Id: I1d92e219bdbc9ba2399eae637a1f4623d695a3f8

Simplify bta_gattc_sdp_callback

* join multiple if statements to improve readability
* malloc and free memory just once for tBTA_GATTC_CB_DATA

Test: compilation
Change-Id: I907645ed04ed4b628a3b24785b1ccd16b69d83bb

Unify logging in gatt_api.cc

- always log conn_id as hex value
- use "=" instead of ":" as delimiter between name and value
- get rid of StringPrintf

Test: compilation
Change-Id: Ia35b79c3732b19661e4655d5cf0923b7e701985f

gatt_api: Avoid possible NULL dereference

We move a logging statement which dereferences a NULL pointer
until after the NULL check, and expand the error message for
the NULL check to include the function name.

Test: TreeHugger
Change-Id: Ib5134b0d6b9ec5da95ee62da9412b977925000ee

Increase LE connection interval with bonded Hearing Aids

When there are bonded Hearing Aids device, increase the minimum LE
Connection Interval to reduce the audio noises on the devices.

Bug: 80079923
Test: Manual test with RAT mouse and HA devices
Change-Id: I589bc574ef7ff3754a149e30fb3c0a685ce27823

Fix log level - requesting MTU is not error

Test: compilation
Change-Id: Idf99af22cf4d29f6fb3da08e86e36b3394617c4f

Don't refresh GATT database after bonding

According to the Bluetooth spec: "For a given client, the server shall have
one set of attributes.".

If we discover services before bonding, we should be fine using them
afterwards, without need to refresh whole GATT database.

This change should speed up bonding HOGP devces by around one second.

Refreshment of GATT database was tied to connection parameter
reenabling. Make sure bonding does not disable connection parameter
change.

Bug: 67057055
Test: Bond with HOGP device, verify profile is connected properly
Change-Id: I1e738c56e211cf3d9234b424f354bf3e468227aa

Gracefully recover on bad attempt to cancel LE connection

According to logs some devices are stuck when in BLE_CONN_CANCEL state.
That is they sent "LE Create Connection Cancel" request, and are
awaiting "LE Connection Complete" event with invalid handle forever.
But they wait and wait, and the event never arrive. That's because
"LE Create Connection Cancel" was sent, when connection attempt is not
pending. In such case, we should act upon command complete status, and
decide to leave BLE_CONN_CANCEL state.

To properly fix this issue, one would have to implement a proper queue
for managing LE connection attempt state, preferably for scratch. This
fix just give option of graceful recovery.

Test: sl4a GattConnectTest
Bug: 75290221
Change-Id: I7e7a377c789ac0a587390320fbf504267cca8727

LE Create Connection Complete - _crash on Command Disallowed

When LE Create Connection Complete is received with status "Command
Disallowed", we can't tell which state we should transition to. This
can be triggered only in case of rare race condition. _Crash to recover.

This was introduced in 24adb37, when
generic handling of all errors to this event was added.

Bug: 77429706
Test: sl4a GattConnectTest
Change-Id: I888861461da296876d97e8784a3dc7c53130fb51

SMP_Encrypt refactor

* key must be 16bit, so no need to pass it's length, and check it's
  value
* p_out being null is a bad call that should _crash to be catched, not an
  error we should handle
* hash computation always succeed, don't return any errors

Test: existing unit tests cover it, i.e. AesCmacTest
Change-Id: Ifba8902f3f1a7be3c54dd7a33d9ff1e52ffd237b

GATT database refactor

Move logic and data responsible for GATT Discovery into separate class.
Create clean representation of GATT database, and attributes for
storage.
Minor service discovery improvements:
* don't send requests to explore services with start handle equal to end handle.
* don't try to discover characteristic if only one handle is left at end
  of service - it uses two handles, one for definition, one for value
* if secondary service is defined before service that includes it, it
  should now be properly discovered.

Test: Added DatabaseBuilderTest, manual tests with LE HID devices, Daydream
      Controller and Clips camera.
Bug: 67057055
Change-Id: I511f4ee7c56c8fa65f012de0b6d1291321840d11

GATTC_Discover: pass parameters directly instead of through pointer

Bug: 67057055
Test: manual
Change-Id: I7be853241595b336e2d4b67bc57170ee01ce6e72

SMP_Encrypt - convert p_out into raw array

SMP_Encrypt output is really 128bit value. No need for status or any
other additional fields.

Test: net_test_stack_smp.AesCmacTest covers that
Change-Id: Iabfaa85d6f4bd5715e0bdab9d3eaf22bb5c39239

Replace BT_OCTET16 with Octet16

BT_OCTET16 was a uint8_t[16], that is a pointer.
This means that it was not copyable, and one had to be always aware of
what this type really means when passing it to function.

Octet16 is std::array<uint8_t, 16> and is copyable. It can also be
copied using "=" operator, instead of memcpy, or ARRAY_TO_STREAM.

Octet16 can also be returned from function by value. Thanks to it, some
smp functions can be simplified, by returning value instead of accepting
pointer to output.

Test: net_stack_smp_test
Change-Id: I0687a948e5807f76ec3d1b5d1d4d2ad2b50b87dd

Add more crypto toolbox tests, plus minor fix in smp_keys.cc

This code extracts two new functions, smp_calculate_ltk_to_link_key
and smp_calculate_link_key_to_ltk, in order to test them.
Also use modulo operator to compute modulo in smp_calculate_g2.
Plus remove unused function definitions in smp_int.h, that were probably
previously used for testing.

Test: added and updated CryptoToolboxTest
Change-Id: Ia84f72af666fc8e34f887b65b07208bc786bf2e0

Move crypto toolbox functions into separate file

Test: already covered by CryptoToolboxTest
Change-Id: I9ba12616d51744fe46648a00a73065cf66f54297

Move crypto related functions into  crypto_toolbox

Also clean up the code:
* remove spurious logging, or replace with DVLOG
* use std::copy and std::reverse_copy instead of ARRAY_TO_STREAM and
  REVERSE_ARRAY_TO_STREAM

Test: CryptoToolboxTest already cover all those functions
Change-Id: I3221d0966d2dd6ca229adf441ceb75dd37a54d7c
Merged-In: I3221d0966d2dd6ca229adf441ceb75dd37a54d7c

Get rid of warning when connecting LE device

We are sending LE fixed channel notification to classic callback. Stop
doing that. This triggers following warning in log output on every
LE connection:
W bt_smp  : smp_br_connect_callback is called on unexpected transport 2

Test: manual with phone, verify warning is gone when connecting over LE
Change-Id: I47597fa03744fb1bff03d287f790ea32fa033cc7

Register for Service Changed notification after encryption

This fixes issue introduced in commit 645ee14
Registration for Service Changed notifications was
disabled, because there was no good way back then to have
"opportunistic" app. Since opportunistic apps were introduced, and the
code in GATT_ConfigServiceChangeCCC is already marking connection as
opportunistic, reenable notification registration.

Test: manual verification, that Service Changed descriptor is set
Change-Id: Iefaec3914829fa4a4a60dc3c3790c3daa9f4f4d8

Clean up style in BLE White List code

* Remove unused code
* Update BgConnHash to return size_t for hashcode
* Change BLE scan_int and scan_win to uint16_t according to spec

Bug: 111562702
Test: SL4A BLE test and manual with BLE mouse
Change-Id: Ieff3acbfaa95b7d804e57021d562218d9fbe42cc

Add security handling for LE connection oriented channels

Use case:
Run PTS test cases TP/LE/CFC/BV-10-C to BV-16-C

Steps:
1. These test cases executed with two DUT as PTS support not available
2. Set desired security level on DUT and Remote with tool
3. Initiate LE COC connection request from DUT

Failure:
LE COC connection accepted though even remote security are not met.

Fix:
Added security handling for COC connection

Test: Ran sl4a test for BleCocTest
Change-Id: I5f6385d462698582e701b5a07953c0ccb932bbbf

Get rid of meaningles GATT client error log

Right now we often get this error in logs:

E bt_btif_gattc: btif_gattc_upstreams_evt: Unhandled event (7)!

This is often misinterpreted during log analysis as error, where this
really means just uninteresting event we don't want to handle.

Change-Id: Ia7804b2e1802a117198a31e025d05a80f973e896

Fix reliable write.

We cannot simply assume the write is terminated in reliable write. When
the reliable write value is longer than MTU allows, the current
implementation can only send whatever MTU allows and naively set the
status to GATT_SUCCESS, in the name of "application should verify handle
offset and value are matched or not". That's why MTU negotiation is a
workaround as people mention in b/37031096, which just fits all the write
value into a single request.

This also blocks our test on CtsVerifier.

Bug: 37031096
Test: Manual test and confirm that we don't simply send partial value
Change-Id: I907877608f4672f24c002e630e58bf9133937a5e

Suppress implicit-fallthrough warnings.

Add FALLTHROUGH_INTENDED for clang compiler.

Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: Iedf7e46445101a5e3358473e1200212d67cf58d1

Add noexcept to move constructors and assignment operators.

Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I4adaf89db5001e9b627beac8160f62b50513d18f

GATTC: Use hex for conn_id in log

For host conn_id, use hex format

Test: manual
Change-Id: I7d7e690a1dbe0665b827c59d104540eafa45d426

Rename functions related to BLE scan cache

They are not related to GATT, update naming.

Test: compilation
Bug: 67058417
Change-Id: Ia84ed98e02fbc04ecfde979f860b8766b0018218

Fix race condition around Le Start Encryption handling.

When sending Le Start Encryption, it's possible that at the same exact
moment the connection was disconnected, and there is an incoming
"Disconnection Complete Event". The controller would send error 0x02
"unknown connection identifier" in such case. This can happen
sporadically when reconnecting device multiple times.

Currently, we don't handle this error code. This lead to the timeout
when waiting for "Encryption Complete", and unbonding of the device.

From now on, if 0x02 error code is returned, we'll cancel current SMP
operation, which is the "LE Start Encryption". This will stop the SMP
timer, and make sure the bond to remote device is not lost.

Test: Manual test reconnecting with HID device multiple time in a row,
causing the link drop right after connection, by removing battery, or
closing the shield box.
Bug: 113652889
Change-Id: I2ff9c13dbc8e7b71505908996e26b89fa1ea6a42

LE Enhanced Connection Complete: Check address types

Only pass identity addresses to btm_identity_addr_to_random_pseudo.
Only pass random addresses into btm_ble_resolve_random_addr.

Test: bond twice to device using non-resolvable address
Change-Id: I5931e5bc89449ea4ae9b873aedfd7bbcdeef2e01

Use proper naming for Identity Address

During Bonding, devices exchange "Identity Address Information", which
include Identity Address, and Identity Address Type.

Identity Address is either Public Address, or Static Random Address.

Thorugh stack, we improperly use "static" where we should use
"identity" to refer to this address.

Bug: 109827460
Test: compilation, just renamed variables.
Change-Id: Iccee1e8ae881e9b9f480e0bf05eea440a905109a

Uprev libchrome to r576279 (1/multiple)

This patch brings the latest and greatest features of libchrome to
android. It contains ~2600 patches.
Reason for uprev: libbluetooth want to use some of the most recent
features avaliable.

Test: libchrome_test
Change-Id: I5f8d5931b404767d3b86cb3bd8df2a05dd67a768
Merged-In: I5f8d5931b404767d3b86cb3bd8df2a05dd67a768

Fix errors around logging when compiling on Linux

* cutils/log.h -> log/log.h
* add missing #include "log/log.h"
* add android_errorWriteWithInfoLog stub

Test: compile on linux using ninja
Change-Id: I720921a2fbf86b5ce5e2a2f691f1e769c91672b6

separate btm_ble_stop_auto_conn from btm_ble_start_auto_conn

There is no common code in those two code paths. Also, minor if/else
refactoring to simplify the code.

Test: compilation, no change in how code works.
Change-Id: I82a03a18041bb5ad396f21ed13e8047e093f2765

Split gatt_update_auto_connect_dev into separate add/remove functions

Test: compilation, no functional changes
Change-Id: I58b5d565753e0c1b99a3b06b27074b593f3b903b

Minor style fixes in gatt_api.cc

Test: compilation
Change-Id: I3050d84443149a5ed77ab1e07f079553546b628c

Split BTM_BleUpdateBgConnDev into BTM_WhiteListAdd and BTM_WhiteListRemove

There is very little common code between both codepath. Having them
separate makes the code cleaner.

Test: compilation, no functional changes.
Bug: 112827989
Change-Id: I936f69a93366d3230df4435fc4b24962cc0bd4b2

BTM_BleClearBgConnDev -> BTM_WhiteListClear

BTM_WhiteList* functions are called only from gatt_utils.cc.
BTM_BleClearBgConnDev is currently an exception - instead of being
called from there, it does call gatt_reset_bgdev_list. This patch fixes
that.

Test: compilation, no functional change
Bug: 112827989
Change-Id: I4cd5bfee44c46d2ef37912496cd6cf5298ab1dfc

Move white list specific code in GATT to separate file

Test: compilation, no functional change
Bug: 112827989
Change-Id: I8c57dd5a3b0d6c088acc1a40d9f3437428a8bd8b

Separate GATT white list from global GATT control block.

Bug: 112827989
Test: compilation, no functional changes
Change-Id: I456a18c6ce567991c4768afaaa3266085a9d30fb

Small cleanup in GATT white list

* move local helper functions into local namespace
* reduce dependency on other modules

Bug: 112827989
Test: compilation
Change-Id: Ie4f783b00b5d0b77698412e09e35a5d11ed8f5f6

Cleanup LE White List HCI interface

Replace global functions with callbacks, to reduce interface size.

Test: add/remove at least two devices in whitelist, verify HCI snoop log
Bug: 112827989
Change-Id: Id05c9f4970bbb795309a3a233f83559bcc1c56e2

Minor style fixes in gatt_main.cc

Test: compilation
Change-Id: I446b9e83603e7224abe1eddd030b4502cc7dceb5

gatt_utils_white_list -> connection_manager

Test: compilation
Change-Id: Ib6741ddd8332ff70efd47a8ede0176d887743ff4

Naming cleanup in stack/gatt/connection_manager.*

Test: compilation
Change-Id: Ic73632cb258515856b9ae5616ec47881b4b28c61

introduce gatt::connection_manager::get_apps_connecting_to

This is to clean up the interface, and don't expose internal control
structures.

Test: compilation
Change-Id: Id2afc5efb4c14be0b787cfabbe21fc1961381cb7

Use map instead of list for keeping apps interested in connection

Bug: 112827989
Test: BleGattConnectionManager
Change-Id: I7b7ea608f5e27a9f17141ccec0c5d5c06bb22e60

Dump gatt::connection_manager state into bugreport

Knowing what's in the white list is useful for debugging.

Bug: 112827989
Test: adb bugreport, verify content.
Change-Id: I195d1ee2fe277f0f0ef534c73f7a964c5f5e61b6

Remove unused BTM_BleSetAdvParams

Test: compilation
Change-Id: I5797a16b3fd92c5ffa1ad1fd048699a591fd1e4c

Centralize call to gatt_update_app_use_link_flag for GATT_Connect

Bug: 112827989
Test: manual connection test
Change-Id: I5d55f6467ffca78ff785ecdad02dd049ea5481bf

Allow Resolvable Private Address into LE White List

When doing background connection, we don't want to put RPA into the
white list, as it might expire in 15 minutes.
For direct connect procedure, RPA is ok - the request times out after 30
seconds.

This patch moves address type check from the White List to the background
connection procedure. It is prepearation for handling direct connect
with white list.

Bug: 112827989
Test: sl4a GattConnectTest
Change-Id: I907ad44d1d255c9212ed58112bb8b99464e46f43

Fix GATT not working due to address mismatch

If the initial connection is established when using RPA, device can
later decide to use it's Identity Address for reconnections, if it
doesn't care about privacy.
When we receive such Identity Address, we must translate it into pseudo
address before passing it further down the stack.

Test: Connect to device using RPA, try to reconnect when it advertise
      it's Public address
Change-Id: Icb8eed25e1aad7003f1a3e0fed684168a8344544

Turn stack/gatt/conneciton_manager.cc into text file

Change-Id: I031bfaa1745de55aeb0a0dbde3a7a67be0f9c982

Use White List for direct connection establishment to multiple devices

Currently, we implement GAP Direct Connect procedure exactly as the spec
says: we attempt connection to just one device.

This means that an app doing Direct Connection can take over the ability
to establish connections, and if it repeats the request, can cause other
devices to not connect.

From now on, we will use White List for both Background and Direct
connections. When there is at least one direct connection, we will
increase the scan parameters used for connection.

Bug: 112827989
Test: added unittests, also sl4a GattConnectTest
Change-Id: Ic0b2f631e3c84d5e8e0f4683b0148f031bfd5639

Remove redundant GATT_StartIf

GATT_StartIf is just sending connect callback about all currently
connected devices, even ones that this app is not interested in.

For btif/java apps, we will trigger connection attempt to just one
device right after registration, which would trigger connect callback
anyway.

For all bta layer apps, they do guard inside connect callback to make
sure code is triggered for already known device, but the devices are
considered as known only after they already connected, and some event
triggered app to create control block.

Thus, GATT_StartIf is surplus feature that should be removed.

Test: run all sl4a GATT tests
Change-Id: I8c45b92dbbf80894c32bb870eb392e766063c934

Enable BLE background connection when stack is started

Remove variable btm_cb.ble_ctr_cb.bg_conn_type. We can enable the
background mode when the Bluetooth stack is started and don't have
to wait until the first background connection request from HID
Device/Hearing Aid/GATT. As soon as we add the first device to white
list, the stack will send HCI Create Connection (White List) command.

Test: manual. Bond to a BLE mouse and turn off/on Bluetooth. Also test
with initiating another direct/white list connection while another white
list connection is pending
Bug: 111562702
Bug: 112827989
Change-Id: I82a476489d181d17aa1c1da8202df1be76928d77

Change-Id: I031bfaa1745de55aeb0a0dbde3a7a67be0f9c982

Unify code in scanner/advertiser connection complete handler.

btm_ble_set_conn_st is called in every possible scenario of
l2cble_scanner_conn_comp. Call it at start, instead of before each
return.

Test: sl4a GattConnectTest
Bug: 112827989
Change-Id: I969fc59b934dc1c7a52be00741fdf38402545b26

Merge code in scanner/advertiser connection complete handler

Test: sl4a GattConnectTest
Bug: 112827989
Change-Id: I860693c11c263643858cfa0b4e4deb6a9f231cdd

Call btm_ble_set_conn_st before on_connection_complete

on_connection_complete can trigger BTM_WhiteListRemove, which sends
"LE Create Connection Cancel" if the connection is pending.

Make sure connection state is updated before calling on_connection_complete.
Otherwise we send an unnecessary "LE Create Connection Cancel" request.

Bug: 112827989
Test: establish Direct connection with at least one device in the
      background connection procedure. Verify HCI snoop log content

Change-Id: I1b8532f4e58d5ab62b471ce0bde6c48640c83ff7

Get rid of direct connect queueing logic

Instead of queueing requests, we should use whitelist to process the
requests simulteanously.
This patch does remove the queueing logic, succeeding patch will add the
logic to schedule through whitelist.

Test: compilation
Bug: 112827989
Change-Id: Ia7132812f704658ecb6919e52c70b291e6874660

Use conneciton_manager for all LE connection establishment

Test: sl4a GattConnectTest, manual bonding test
Bug: 112827989
Change-Id: I55878e03d268c43002e22ce4ebfbf0e334523882

Get rid of is_ble_connecting and ble_connecting_bda

These variables make no sense any more, as we might be attempting
multiple connections at the same time.

Test: sl4a GattConnectTest, manual bonding test
Bug: 112827989
Change-Id: I7e1d01e8d80383b49ff9c20fb3758cef03c52882

Remove connection_manager from gatt namespace

connection_manager handles more than GATT. Celanup naming.

Bug: 112827989
Test: compilation
Change-Id: Id5fdfacb12921cff04204cf2589f73a7c6a0d01f

BLE:Missing changes while porting - 1

Change-Id: I29e192e84961daae0a6fa9a9c8df93d422c2e8f0

Add more checks to LE Connection Parameters

This part of code is missing the necessary LE Connection Parameters
checks.

Test: Tested on R.A.T. LE mouse
Bug: 70683224
Change-Id: I966a3dd4fd2fa9dc54109872df3d4c43d34f0156

Linux build fix

Add empty android_errorWriteLog implementation for Linux
Add missing license headers
Fix BUILD.gn files

Test: compile using ninja
Change-Id: I9be297d5847b4c0856786738eac2c30424593919

Change-Id: I031bfaa1745de55aeb0a0dbde3a7a67be0f9c982
  • Loading branch information
Janardhana Rao Bokka authored and Hemant Gupta committed Feb 28, 2019
1 parent f0508c8 commit 2a4e9b2
Show file tree
Hide file tree
Showing 139 changed files with 8,160 additions and 8,802 deletions.
7 changes: 6 additions & 1 deletion bta/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ cc_library_static {
"gatt/bta_gattc_api.cc",
"gatt/bta_gattc_cache.cc",
"gatt/bta_gattc_main.cc",
"gatt/bta_gattc_queue.cc",
"gatt/bta_gattc_utils.cc",
"gatt/bta_gatts_act.cc",
"gatt/bta_gatts_api.cc",
"gatt/bta_gatts_main.cc",
"gatt/bta_gatts_utils.cc",
"gatt/database.cc",
"gatt/database_builder.cc",
"hf_client/bta_hf_client_act.cc",
"hf_client/bta_hf_client_api.cc",
"hf_client/bta_hf_client_at.cc",
Expand Down Expand Up @@ -116,7 +119,9 @@ cc_test {
defaults: ["fluoride_bta_defaults_qti"],
srcs: [
"test/bta_hf_client_test.cc",
"test/gatt_cache_file_test.cc",
"test/gatt/database_builder_test.cc",
"test/gatt/database_builder_sample_device_test.cc",
"test/gatt/database_test.cc",
],
shared_libs: [
"liblog",
Expand Down
164 changes: 83 additions & 81 deletions bta/dm/bta_dm_act.cc

Large diffs are not rendered by default.

21 changes: 3 additions & 18 deletions bta/dm/bta_dm_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ void BTA_DmConfirm(const RawAddress& bd_addr, bool accept) {
*
******************************************************************************/
void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
LINK_KEY link_key, tBTA_SERVICE_MASK trusted_mask,
const LinkKey& link_key, tBTA_SERVICE_MASK trusted_mask,
bool is_trusted, uint8_t key_type, tBTA_IO_CAP io_cap,
uint8_t pin_length) {

tBTA_DM_API_ADD_DEVICE* p_msg =
(tBTA_DM_API_ADD_DEVICE*)osi_calloc(sizeof(tBTA_DM_API_ADD_DEVICE));

Expand All @@ -528,12 +529,7 @@ void BTA_DmAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
p_msg->tm = trusted_mask;
p_msg->is_trusted = is_trusted;
p_msg->io_cap = io_cap;

if (link_key) {
p_msg->link_key_known = true;
p_msg->key_type = key_type;
memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
}
p_msg->link_key = link_key;

/* Load device class if specified */
if (dev_class) {
Expand Down Expand Up @@ -879,17 +875,6 @@ void BTA_DmSetBleConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
bta_sys_sendmsg(p_msg);
}

/**
* Set BLE connectable mode to auto connect
*/
void BTA_DmBleStartAutoConn() {
tBTA_DM_API_SET_NAME* p_msg =
(tBTA_DM_API_SET_NAME*)osi_calloc(sizeof(tBTA_DM_API_SET_NAME));

p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
bta_sys_sendmsg(p_msg);
}

/*******************************************************************************
*
* Function bta_dm_discover_send_msg
Expand Down
10 changes: 6 additions & 4 deletions bta/dm/bta_dm_ci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ void bta_dm_ci_io_req(const RawAddress& bd_addr, tBTA_IO_CAP io_cap,
* Returns void
*
******************************************************************************/
void bta_dm_ci_rmt_oob(bool accept, const RawAddress& bd_addr, BT_OCTET16 c,
BT_OCTET16 r) {
void bta_dm_ci_rmt_oob(bool accept, const RawAddress& bd_addr, const Octet16& c,
const Octet16& r) {
//TODO -if it impacts issues. please revert back

tBTA_DM_CI_RMT_OOB* p_msg =
(tBTA_DM_CI_RMT_OOB*)osi_malloc(sizeof(tBTA_DM_CI_RMT_OOB));

p_msg->hdr.event = BTA_DM_CI_RMT_OOB_EVT;
p_msg->bd_addr = bd_addr;
p_msg->accept = accept;
memcpy(p_msg->c, c, BT_OCTET16_LEN);
memcpy(p_msg->r, r, BT_OCTET16_LEN);
p_msg->c = c;
p_msg->r = r;

bta_sys_sendmsg(p_msg);
}
Expand Down
10 changes: 5 additions & 5 deletions bta/dm/bta_dm_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ typedef struct {
typedef struct {
BT_HDR hdr;
RawAddress bd_addr;
BT_OCTET16 c;
BT_OCTET16 r;
Octet16 c;
Octet16 r;
bool accept;
} tBTA_DM_CI_RMT_OOB;

Expand Down Expand Up @@ -316,7 +316,7 @@ typedef struct {
BT_HDR hdr;
RawAddress bd_addr;
DEV_CLASS dc;
LINK_KEY link_key;
LinkKey link_key;
tBTA_SERVICE_MASK tm;
bool is_trusted;
uint8_t key_type;
Expand Down Expand Up @@ -425,7 +425,7 @@ typedef struct {
/* set scan parameter for BLE connections */
typedef struct {
BT_HDR hdr;
tBTA_GATTC_IF client_if;
tGATT_IF client_if;
uint32_t scan_int;
uint32_t scan_window;
tBLE_SCAN_MODE scan_mode;
Expand Down Expand Up @@ -735,7 +735,7 @@ typedef struct {
bool cancel_pending; /* inquiry cancel is pending */
tBTA_TRANSPORT transport;
tBTA_DM_SEARCH_CBACK* p_scan_cback;
tBTA_GATTC_IF client_if;
tGATT_IF client_if;
uint8_t num_uuid;
bluetooth::Uuid* p_srvc_uuid;
uint8_t uuid_to_search;
Expand Down
Loading

0 comments on commit 2a4e9b2

Please sign in to comment.