Commit Graph

134 Commits

Author SHA1 Message Date
Marcel Holtmann
c1add0ff9f android: Use src/log.h include instead of just log.h 2014-01-26 00:23:15 -08:00
Szymon Janc
3be8272df5 android/bluetooth: Handle device unpaired mgmt event 2014-01-24 20:20:15 +01:00
Szymon Janc
90fb3a75e3 android/bluetooth: Check event length in mgmt_auth_failed_event 2014-01-24 20:20:15 +01:00
Szymon Janc
f5512018e2 android/bluetooth: Fix removing bonded device if connection failed 2014-01-24 20:20:15 +01:00
Szymon Janc
509b120a1a android/bluetooth: Check not paired status in unpair_device_complete
This is needed to make sure framework is updated with proper bond state
of device.
2014-01-24 15:17:24 +01:00
Szymon Janc
b8207d382f android/bluetooth: Rename devices list to cached_devices
This makes it clear what is the purpose of this list.
2014-01-24 15:17:24 +01:00
Szymon Janc
a7fc397087 android/bluetooth: Add support for loading caches devices from storage
Info is now stored for all devices and bond state depends on file.
Based on that devices loaded from storage are put either to cache
or to bonded_devices list.
2014-01-24 15:17:23 +01:00
Szymon Janc
3c12dc59e3 android/bluetooth: Add support for caching remote device info
Cache is limited to DEVICES_CACHE_MAX. Devices are sorted with
timestamp so if cache is full olderst device is removed.
2014-01-24 15:17:23 +01:00
Szymon Janc
579e1af763 android/bluetooth: Use defines for settings and devices files paths 2014-01-24 15:17:23 +01:00
Szymon Janc
429f9eb75b android/bluetooth: Split devices list to devices and bonded_devices
Bonded devices are permament until unbondedn. Non-bonded devices will
be held in (size limited) cache based on timestamp property so split
list to ease separation.
2014-01-24 15:17:23 +01:00
Szymon Janc
326d212791 android/bluetooth: Move option_index declaration to close other static
Don't intermix defines with static variables.
2014-01-21 15:19:43 +01:00
Johan Hedberg
1a9051e9ee Rename glib-helper to uuid-helper 2014-01-21 14:12:47 +02:00
Szymon Janc
cada0c0896 core: Add flags parameter to bt_search_service
This allows to pass custom SDP flags to sdp_connect.
2014-01-20 15:19:25 +02:00
Szymon Janc
1e0e4dfde2 android/bluetooth: Fix sending device prop change event with no props 2014-01-19 20:21:01 +01:00
Szymon Janc
73613fe026 android/bluetooth: Fix discovering new devices
Device found events should be send also for known devices if this is
new discovery session. Otherwise Android will ignore those devices.
2014-01-16 15:46:41 +01:00
Szymon Janc
da6f8e532c android/bluetooth: Fix compare function when finding devices
Elements on list are struct device not bdaddr_t so make comparing
function use proper types. This was working so far only due to
bdaddr_t being first element in struct device.
2014-01-12 20:43:15 +01:00
Szymon Janc
9b174ddfe2 android/bluetooth: Use helper for finding device 2014-01-12 20:43:07 +01:00
Szymon Janc
c31615b82b android/bluetooth: Log error for any non-success code
Returning non-SUCCESS code in command reply is considered error and
that includes DONE status.
2014-01-11 17:15:41 +01:00
Szymon Janc
86905a8968 android/bluetooth: Rename labels from failed to reply
This name match better and avoid confusion when setting status to
SUCCESS and then jumping to failed label.
2014-01-11 17:15:41 +01:00
Szymon Janc
b4dac30570 android/bluetooth: Use HAL_STATUS_SUCCESS instead of _DONE in replies
JNI code in Android is mapping returned code to boolean value. Only
SUCCESS status is mapped to true and that value is returned to Java
code. This could result in faultyly triggering error path in Java
when returning DONE in command reply.
2014-01-11 17:15:41 +01:00
Marcel Holtmann
883486009f android: Use LinkKeyPinLength instead of LinkKeyPINLength 2014-01-11 01:14:28 -08:00
Marcel Holtmann
93d858bcd2 android: Enable secure connections if supported 2014-01-11 01:13:46 -08:00
Szymon Janc
b6df31f1c8 android/bluetooth: Set major and minor class od device
Currently this is hardcoded to Phone/Smartphone.
2014-01-09 10:30:45 +01:00
Szymon Janc
4c0e55c4df android/bluetooth: Set default adapter name on first start
On first start always set name to default name. Adapter name is
updated on start only if current name is different.
2014-01-09 10:30:45 +01:00
Lukasz Rymanowski
7bfd06208a android: Send remote devices properties on enable
If there is any bonded device stored then on bluetooth enable we
should send notification with its properties.
2014-01-08 13:13:49 +01:00
Lukasz Rymanowski
3dee7edf88 android: Move get_remote_device_props up in the file
This patch moves up function get_remote_device_props() and all
functions required by this function.
2014-01-08 13:13:49 +01:00
Lukasz Rymanowski
c8aabab889 android: Add wrapper function for get remote dev properties 2014-01-08 13:13:49 +01:00
Szymon Janc
8a73184567 android/bluetooth: Fix browse_remote_sdp return value
False was converted to HAL_STATUS_SUCCESS resulting in wrong error
code in case of failure in handle_get_remote_services_cmd.
2014-01-03 22:56:50 +01:00
Szymon Janc
784ef1cd31 android/bluetooth: Print command opcode in DUT mode functions
Print command opcode in handle_le_test_mode_cmd and
handle_dut_mode_send_cmd. This is valuable information on what kind
of HCI command the Java layer tries to send.
2013-12-23 16:42:47 +01:00
Szymon Janc
7c3a06b743 android/bluetooth: Print error on unimplemented functions
Functions, callbacks or properties that are not implemented due to
being bogus or not feasible now prints error messages.
2013-12-23 14:41:41 +02:00
Szymon Janc
385c00cedd android/bluetooth: Add support for DUT mode configure command
This allows to enable and disable DUT mode. This is special mode so
adding more info from related kernel commit:

"The Device Under Test (DUT) mode is useful for doing certification
testing and so expose this as debugfs option.

This mode is actually special since you can only enter it. Restoring
normal operation means that a HCI Reset is required. The current mode
value gets tracked as a new device flag and when disabling it, the
correct command to reset the controller is sent."
2013-12-23 14:41:41 +02:00
Szymon Janc
3330781a20 android/bluetooth: Fix error message in stop_discovery 2013-12-23 12:47:31 +01:00
Szymon Janc
8af14a0ec4 android/bluetooth: Add support for timestamp device property
This allows to handle timestamp property request. Also this will be
usefull for devices info cache (clearing old devices).
2013-12-23 11:41:52 +02:00
Szymon Janc
9bc70e63b1 android/bluetooth: Fix memory leaks in load_devices_info
Groups and key file were not free on function return. This fix
following valgrind reports:

34 (16 direct, 18 indirect) bytes in 1 blocks are definitely lost in
loss record 33 of 77
   at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-
amd64-linux.so)
   by 0x4E81DD0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so
.0.3800.1)
   by 0x4E74BF1: g_key_file_get_groups (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x40CDFA: read_info_complete (bluetooth.c:1672)
   by 0x40827C: request_complete (mgmt.c:221)
   by 0x4085E9: received_data (mgmt.c:319)
   by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
   by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x403B15: main (main.c:439)

1,633 (72 direct, 1,561 indirect) bytes in 1 blocks are definitely lost
in loss record 75 of 77
   at 0x4C2A2DB: malloc (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
   by 0x4E81DD0: g_malloc (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E9796D: g_slice_alloc (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E97EAD: g_slice_alloc0 (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E746DA: g_key_file_new (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x40CDD4: read_info_complete (bluetooth.c:1667)
   by 0x40827C: request_complete (mgmt.c:221)
   by 0x4085E9: received_data (mgmt.c:319)
   by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
   by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x403B15: main (main.c:439)
2013-12-20 15:46:51 +01:00
Johan Hedberg
224b6b8088 android: Add clarifying comment to store_device_info() 2013-12-20 14:12:06 +02:00
Szymon Janc
5022d5ab42 android/bluetooth: Add support for restoring devices from storage
This adds support to restore bonded devices from storage (including
linkkeys).
2013-12-20 14:08:25 +02:00
Szymon Janc
d3174bdc20 android/bluetooth: Add support for storing link keys
When new linkkey event is received store linkkey in devices info file.
Stored info includes linkkey, linkkey type and pin length.
2013-12-20 14:08:06 +02:00
Szymon Janc
40a69f0ac5 android/bluetooth: Add initial support for storing device info
This allows to store information about remote device. For now this is
stored only for bonded devices. Currently stored data includes devices
ddress, type, name, friendly name, class and uuids.
2013-12-20 14:07:55 +02:00
Szymon Janc
316d0eec54 android/bluetooth: Add initial support for permanent storage
This patch adds initial support for storing adapter configuration.
Currently stored data is address, name and discoverable timeout.

Since Android daemon storage format is to be simpler than Linux check
if correct adapter is used before going operational. This is
a precaution to avoid e.g. using linkkeys generated for different
controller.
2013-12-20 14:07:22 +02:00
Szymon Janc
d217739b95 android/bluetooth: Add stubs for missing commands
This adds stubs for commands that were introduced by BT HAL changes
in Android 4.3+.
2013-12-20 12:57:27 +02:00
Szymon Janc
ff43d507cd android/bluetooth: Fix sending invalid RSSI device property
RSSI property is of int32_t type but int8_t was send in durring
remote devices discovery.
2013-12-19 22:19:25 +01:00
Szymon Janc
c1a0601a84 android/bluetooth: Add support for getting remote device UUIDs property
This allows to query for remote device UUIDs property.
2013-12-13 16:53:30 +02:00
Szymon Janc
c85aa9d126 android/bluetooth: Fix missing property change notification
After setting new discoverable timeout property change notification
with new value should be send.
2013-12-13 16:46:08 +02:00
Szymon Janc
5a56558ffe android/bluetooth: Code style and whitespace cleanup
This fix some random style or whitespace damages. Also moves statics
after last type definition.
2013-12-11 15:48:51 +02:00
Szymon Janc
c7ee3585b3 android/bluetooth: Add support for remote device type property
This makes daemon store remote device address type to be able to handle
remote device type property.
2013-12-11 15:48:25 +02:00
Szymon Janc
e58c3f51b1 android/bluetooth: Add support for get remote device properties command
This allows to get all properties of specified remote device.
2013-12-11 15:48:05 +02:00
Szymon Janc
da5838fabf android/bluetooth: Add support for remote device RSSI
This allows to cache remote device RSSI and get it with get property
command.
2013-12-11 15:47:55 +02:00
Szymon Janc
a1c695fb1c android/bluetooth: Add support for remote device class
This allows to cache remote device CoD and get it with get property
command.
2013-12-11 15:47:41 +02:00
Szymon Janc
a306ed3d2c android/bluetooth: Free devices on service unregister
There is no need to keep devices list in memory if service was
unregistered.
2013-12-11 15:41:51 +02:00
Szymon Janc
ff2c83e54c android/bluetooth: Add support for remote device friendly name
This allows to get and set remote device property with friendly name.
Storage support is still missing.
2013-12-11 15:38:24 +02:00
Szymon Janc
a328efa7b6 android/bluetooth: Add support for adapter bonded devices property
This allows to get property with list of bonded devices.
2013-12-11 15:38:01 +02:00
Szymon Janc
63d0afde96 android/bluetooth: Add support for reporting adapter type property
This allows to get property with adapter type.
2013-12-11 15:37:23 +02:00
Szymon Janc
ab663fe425 android/bluetooth: Add send_adapter_property helper function
Adapter property notification are send from multiple places so it make
sense to have helper for that. This is especially usefull for 'simple'
properties.
2013-12-10 17:28:14 +02:00
Szymon Janc
51185f0fa5 android/bluetooth: Add send_device_property helper function
Remote device property notification will be send from multiple places
so it make sense to have helper for that. This will be especially
usefull for 'simple' properties.
2013-12-10 17:27:59 +02:00
Szymon Janc
87b0ec339f android/bluetooth: Add stubs for set device property command
This adds per property stubs.
2013-12-10 17:27:50 +02:00
Szymon Janc
01376acfdc android/bluetooth: Add stubs for get device properties command
This adds per property stubs.
2013-12-10 17:27:34 +02:00
Szymon Janc
fffc2b05d5 android/bluetooth: Refactor send_remote_device_name_prop
Rename send_remote_device_name_prop to get_device_name and make it
accept struct device as parameter. Also return HAL status code.
This will allow to use this function also in get device property
command handler.
2013-12-10 17:27:03 +02:00
Szymon Janc
3effdfbd16 android/bluetooth: Fix coding style issue in set_device_bond_state 2013-12-10 17:26:52 +02:00
Szymon Janc
7ad67aedc3 android/bluetooth: Use single list for device caching
This makes code much simpler and easier to follow. It is also
a preparation for supporting remote device properties getting, setting
and storing.
2013-12-10 17:26:33 +02:00
Szymon Janc
e634c06c3b android/bluetooth: Rename functions to match adapter properties names
This match adapter properties handling functions with properties names.
Will make code easier to understand and avoid clashes with remote
device properties functions.
2013-12-10 17:22:11 +02:00
Andrei Emeltchenko
7560b22e96 core: Remove useless eir parsing function return value
Currently eir_parse always return 0 but it is checked throughout the code
(in android/bluetooth code as well in src/adapteri, etc) for return value
(err < 0) which never happens. Make function eir_parse return void. This
fixes warnings from static analyzer tools.
2013-12-10 10:32:57 +02:00
Szymon Janc
ffb856322c android: Use G_N_ELEMENTS macro for table elements calculation
It is more common in codebase to use this macro instead of opencoded
(sizeof(foo)/sizeof(foo[0])).
2013-12-03 13:44:04 +02:00
Szymon Janc
d64785addb android/bluetooth: Make property handling function return HAL status
This makes funtions follow have similar style and makes properties
dispatch function much simpler.
2013-12-02 16:24:02 +02:00
Szymon Janc
a29d4b3212 android/bluetooth: Use generic IPC msg handling for commands
Handlers are registered on service register and unregistered on
unregister.
2013-12-02 16:24:02 +02:00
Szymon Janc
7624ea2d42 android: Don't pass notification socket on services register
It is no longer needed as proper socket is use by IPC helpers.
2013-11-28 18:02:27 +02:00
Szymon Janc
9ed863baef android/bluetooth: Remove not needed notification_sk checks
This is now checked inside ipc_send_notif helper.
2013-11-28 18:02:27 +02:00
Szymon Janc
daf1186c38 android: Use ipc_send_notif for sending notifications 2013-11-28 18:02:26 +02:00
Szymon Janc
a50edbf560 android: Use ipc_send_rsp helper for replying success
Where applicable use helper as this make code easier to understand.
2013-11-28 18:02:26 +02:00
Szymon Janc
6456e15664 android: Remove socket parameter from ipc_send_rsp
Use command socket provided to IPC on init.
2013-11-28 18:02:26 +02:00
Szymon Janc
63681815bd android/bluetooth: Change discoverable mode only if connectable
There is no need to sending set_discoverable command if new settings
are not connectable as clearing connectable also clear discoverable.
Sending set_discoverable when not connectable result in 'rejected'
mgmt response.
2013-11-27 12:57:04 +02:00
Johan Hedberg
cc38f090de android: Fix pointless eir debug log 2013-11-27 12:52:29 +02:00
Andrei Emeltchenko
044baf78ef android/bluetooth: Fix memory leak 2013-11-25 14:51:08 +02:00
Ravi kumar Veeramally
b32461d42d android: Handle multiple init(register) and cleanup(unregister) calls properly
This can be tested with haltest.
2013-11-19 18:15:37 +02:00
Szymon Janc
fc10c55498 android: Improve IPC helper to not send invalid status response
This fix issue with sending invalid success response from several
places where ipc_send_rsp was used for reporting success. Instead of
using using ipc_send for success response, make helper handle that.
2013-11-18 15:17:22 +02:00
Szymon Janc
2e86eac876 android: Refactor update_found_device function
This makes function flow easier to follow and understand. Besides that
it also fix issue with sending to many bytes if some prop were not
present in EIR.
2013-11-16 20:22:03 +02:00
Szymon Janc
51012a0104 android: Fix sending invalid remote device property event
Remote device property event has variable length, pass whole event
length to ipc_send, not only header.
2013-11-16 20:22:01 +02:00
Szymon Janc
ff7246fb8f android: Fix sending remote device property if name is not present
This fix missing bdaddr to string convertion if name was NULL. This
was resulting in using undefined dst value.
2013-11-16 20:21:59 +02:00
Lukasz Rymanowski
ba310d7f90 android: Change TODO with explaining comment 2013-11-15 20:23:38 +02:00
Lukasz Rymanowski
e623075212 android: Update bond state on auth and connect failed 2013-11-15 20:22:23 +02:00
Lukasz Rymanowski
818d532ba3 android: Cache device name on device list. 2013-11-15 20:20:51 +02:00
Lukasz Rymanowski
e9d43a87fa android: Update bond state on incoming bonding
Before sending any ssp request or pin code request up to HAL library we
need to send bond state change with bonding state. Otherwise incoming
bonding is not correctly handled by Bluetooth.apk.
In this patch also device list has been added in order to e.g track
bonding state.

Note: For incoming paring (security mode 3) there is a  need to send
HAL_EVE_REMOTE_DEVICE_PROPS before HAL_EV_PIN_REQUEST.
It is because Android will crash due to bug in pinRequestCallback
function in java. Android checks if device is already in HashMap and if
not then creates  device, but forget to use that one, but instead do
operations on NULL. By sending HAL_BOND_STATE_BONDING event it works
better but we have race issue. It is because new device is added to
HashMap not in callback context but later after BONDING msg will be
received  by BondStateMachine. If it happens before pin_request_cb hits
java then we are fine, otherwise not. So for that reason we send
HAL_EV_REMOTE_DEVICE_PROPS so in the java handler class new device will
be added to HashMap in the  callback context.

In ssp case we don't have this problem as we send device found once acl
is created.
2013-11-15 20:19:50 +02:00
Szymon Janc
e30125fa92 android: Fix not storing adapter index in index added event
If controller was addded after daemon start its index was not stored
resulting in mgmt commands to be always send to MGMT_INDEX_NONE index.
2013-11-15 14:44:10 +02:00
Szymon Janc
9ad9540f7d android: Rename bluetooth service functions to match service name
Make public functions match service name.
2013-11-14 14:58:16 +02:00
Szymon Janc
c060fc6976 android: Rename adapter.c to bluetooth.c
Match service name that is implemened in that file. This will also
keep convention of foo.c and hal-foo.c implementing remote parts of
same service.
2013-11-14 14:57:56 +02:00