From: Andrei Emeltchenko <[email protected]>
Adaptation of bluetooth.h HAL to BlueZ
Andrei Emeltchenko (6):
android/hal-bluetooth: Add parameter to create_bond
android/hardware: Update bluetooth.h header from Android 5.0
android/hal-bluetooth: Add missing functions
android/client: Add new API argument for create_bond()
android/tester: Use dummy parameter in create_bond()
android/client: Add energy_info_callback print
android/bluetooth.c | 2 ++
android/client/if-bt.c | 21 +++++++++++-
android/hal-bluetooth.c | 53 +++++++++++++++++++++++++++-
android/hal-ipc-api.txt | 1 +
android/hal-msg.h | 5 +++
android/hardware/bluetooth.h | 82 ++++++++++++++++++++++++++++++++++++++++++--
android/tester-main.c | 6 +++-
7 files changed, 165 insertions(+), 5 deletions(-)
--
1.9.1
Hi Andrei,
On Tuesday 04 of November 2014 14:24:44 Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <[email protected]>
>
> Adaptation of bluetooth.h HAL to BlueZ
>
> Andrei Emeltchenko (6):
> android/hal-bluetooth: Add parameter to create_bond
> android/hardware: Update bluetooth.h header from Android 5.0
> android/hal-bluetooth: Add missing functions
> android/client: Add new API argument for create_bond()
> android/tester: Use dummy parameter in create_bond()
> android/client: Add energy_info_callback print
>
> android/bluetooth.c | 2 ++
> android/client/if-bt.c | 21 +++++++++++-
> android/hal-bluetooth.c | 53 +++++++++++++++++++++++++++-
> android/hal-ipc-api.txt | 1 +
> android/hal-msg.h | 5 +++
> android/hardware/bluetooth.h | 82 ++++++++++++++++++++++++++++++++++++++++++--
> android/tester-main.c | 6 +++-
> 7 files changed, 165 insertions(+), 5 deletions(-)
>
Patches 1,3,4 and 6 are now applied. Thanks.
I've made few changes to them:
- lets check against >=5.0.0 for new API
- I've fixed missing checks for new API in 6/6
- moved parameter validation to daemon in 1/6
--
Best regards,
Szymon Janc
From: Andrei Emeltchenko <[email protected]>
---
android/tester-main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/android/tester-main.c b/android/tester-main.c
index 515c69e..22224cc 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -19,6 +19,7 @@
#include "src/shared/util.h"
#include "emulator/bthost.h"
#include "tester-main.h"
+#include "hal-msg.h"
#include "monitor/bt.h"
@@ -2904,8 +2905,11 @@ void bt_create_bond_action(void)
return;
}
+ /* TODO: take into account transport parameter */
+
step->action_status =
- data->if_bluetooth->create_bond(action_data->addr);
+ data->if_bluetooth->create_bond(action_data->addr,
+ BT_TRANSPORT_UNKNOWN);
schedule_action_verification(step);
}
--
1.9.1
From: Andrei Emeltchenko <[email protected]>
New Android API has new argument transport.
---
android/client/if-bt.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index 2d7ac79..a25d7bc 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -19,6 +19,7 @@
#include "if-main.h"
#include "terminal.h"
+#include "../hal-msg.h"
#include "../hal-utils.h"
const bt_interface_t *if_bluetooth;
@@ -609,11 +610,23 @@ static void cancel_discovery_p(int argc, const char **argv)
static void create_bond_p(int argc, const char **argv)
{
bt_bdaddr_t addr;
+#if ANDROID_VERSION > PLATFORM_VER(4, 4, 4)
+ int transport;
+#endif
RETURN_IF_NULL(if_bluetooth);
VERIFY_ADDR_ARG(2, &addr);
+#if ANDROID_VERSION > PLATFORM_VER(4, 4, 4)
+ if (argc < 3)
+ transport = BT_TRANSPORT_UNKNOWN;
+ else
+ transport = atoi(argv[3]);
+
+ EXEC(if_bluetooth->create_bond, &addr, transport);
+#else
EXEC(if_bluetooth->create_bond, &addr);
+#endif
}
/* Just addres to complete, use complete_addr_c */
--
1.9.1
From: Andrei Emeltchenko <[email protected]>
---
android/client/if-bt.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index a25d7bc..3fd04a3 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -328,6 +328,11 @@ static void le_test_mode_cb(bt_status_t status, uint16_t num_packets)
num_packets);
}
+static void energy_info_cb(bt_activity_energy_info *energy_info)
+{
+ haltest_info("%s\n", __func__);
+}
+
static bt_callbacks_t bt_callbacks = {
.size = sizeof(bt_callbacks),
.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -341,7 +346,8 @@ static bt_callbacks_t bt_callbacks = {
.acl_state_changed_cb = acl_state_changed_cb,
.thread_evt_cb = thread_evt_cb,
.dut_mode_recv_cb = dut_mode_recv_cb,
- .le_test_mode_cb = le_test_mode_cb
+ .le_test_mode_cb = le_test_mode_cb,
+ .energy_info_cb = energy_info_cb,
};
static void init_p(int argc, const char **argv)
--
1.9.1
From: Andrei Emeltchenko <[email protected]>
---
android/hardware/bluetooth.h | 82 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 80 insertions(+), 2 deletions(-)
diff --git a/android/hardware/bluetooth.h b/android/hardware/bluetooth.h
index b957c6f..74cd1fc 100644
--- a/android/hardware/bluetooth.h
+++ b/android/hardware/bluetooth.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_INCLUDE_BLUETOOTH_H
#define ANDROID_INCLUDE_BLUETOOTH_H
+#include <stdbool.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
@@ -39,6 +40,7 @@ __BEGIN_DECLS
#define BT_PROFILE_HANDSFREE_ID "handsfree"
#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
+#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
#define BT_PROFILE_HEALTH_ID "health"
#define BT_PROFILE_SOCKETS_ID "socket"
#define BT_PROFILE_HIDHOST_ID "hidhost"
@@ -47,6 +49,7 @@ __BEGIN_DECLS
#define BT_PROFILE_GATT_ID "gatt"
#define BT_PROFILE_AV_RC_ID "avrcp"
+#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
/** Bluetooth Address */
typedef struct {
@@ -85,7 +88,8 @@ typedef enum {
BT_STATUS_PARM_INVALID,
BT_STATUS_UNHANDLED,
BT_STATUS_AUTH_FAILURE,
- BT_STATUS_RMT_DEV_DOWN
+ BT_STATUS_RMT_DEV_DOWN,
+ BT_STATUS_AUTH_REJECTED
} bt_status_t;
@@ -94,6 +98,15 @@ typedef struct {
uint8_t pin[16];
} __attribute__((packed))bt_pin_code_t;
+typedef struct {
+ uint8_t status;
+ uint8_t ctrl_state; /* stack reported state */
+ uint64_t tx_time; /* in ms */
+ uint64_t rx_time; /* in ms */
+ uint64_t idle_time; /* in ms */
+ uint64_t energy_used; /* a product of mA, V and ms */
+} __attribute__((packed))bt_activity_energy_info;
+
/** Bluetooth Adapter Discovery state */
typedef enum {
BT_DISCOVERY_STOPPED,
@@ -128,6 +141,18 @@ typedef struct
int manufacturer;
} bt_remote_version_t;
+typedef struct
+{
+ uint8_t local_privacy_enabled;
+ uint8_t max_adv_instance;
+ uint8_t rpa_offload_supported;
+ uint8_t max_irk_list_size;
+ uint8_t max_adv_filter_supported;
+ uint8_t scan_result_storage_size_lobyte;
+ uint8_t scan_result_storage_size_hibyte;
+ uint8_t activity_energy_info_supported;
+}bt_local_le_features_t;
+
/* Bluetooth Adapter and Remote Device property types */
typedef enum {
/* Properties common to both adapter and remote device */
@@ -210,6 +235,13 @@ typedef enum {
BT_PROPERTY_REMOTE_VERSION_INFO,
+ /**
+ * Description - Local LE features
+ * Access mode - GET.
+ * Data type - bt_local_le_features_t.
+ */
+ BT_PROPERTY_LOCAL_LE_FEATURES,
+
BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
} bt_property_type_t;
@@ -221,6 +253,7 @@ typedef struct
void *val;
} bt_property_t;
+
/** Bluetooth Device Type */
typedef enum {
BT_DEVICE_DEVTYPE_BREDR = 0x1,
@@ -323,6 +356,15 @@ typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t le
* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
* The num_packets is valid only for le_test_end command */
typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
+
+/** Callback invoked when energy details are obtained */
+/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
+ * If the ctrl_state value is 0, it means the API call failed
+ * Time values-In milliseconds as returned by the controller
+ * Energy used-Value as returned by the controller
+ * Status-Provides the status of the read_energy_info API call */
+typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
+
/** TODO: Add callbacks for Link Up/Down and other generic
* notifications/callbacks */
@@ -342,8 +384,27 @@ typedef struct {
callback_thread_event thread_evt_cb;
dut_mode_recv_callback dut_mode_recv_cb;
le_test_mode_callback le_test_mode_cb;
+ energy_info_callback energy_info_cb;
} bt_callbacks_t;
+typedef void (*alarm_cb)(void *data);
+typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
+typedef int (*acquire_wake_lock_callout)(const char *lock_name);
+typedef int (*release_wake_lock_callout)(const char *lock_name);
+
+/** The set of functions required by bluedroid to set wake alarms and
+ * grab wake locks. This struct is passed into the stack through the
+ * |set_os_callouts| function on |bt_interface_t|.
+ */
+typedef struct {
+ /* set to sizeof(bt_os_callouts_t) */
+ size_t size;
+
+ set_wake_alarm_callout set_wake_alarm;
+ acquire_wake_lock_callout acquire_wake_lock;
+ release_wake_lock_callout release_wake_lock;
+} bt_os_callouts_t;
+
/** NOTE: By default, no profiles are initialized at the time of init/enable.
* Whenever the application invokes the 'init' API of a profile, then one of
* the following shall occur:
@@ -419,7 +480,7 @@ typedef struct {
int (*cancel_discovery)(void);
/** Create Bluetooth Bonding */
- int (*create_bond)(const bt_bdaddr_t *bd_addr);
+ int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
/** Remove Bond */
int (*remove_bond)(const bt_bdaddr_t *bd_addr);
@@ -427,6 +488,13 @@ typedef struct {
/** Cancel Bond */
int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
+ /**
+ * Get the connection status for a given remote device.
+ * return value of 0 means the device is not connected,
+ * non-zero return status indicates an active connection.
+ */
+ int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
+
/** BT Legacy PinKey Reply */
/** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
@@ -455,6 +523,16 @@ typedef struct {
/* enable or disable bluetooth HCI snoop log */
int (*config_hci_snoop_log)(uint8_t enable);
+
+ /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
+ * This should be called immediately after a successful |init|.
+ */
+ int (*set_os_callouts)(bt_os_callouts_t *callouts);
+
+ /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
+ * Success indicates that the VSC command was sent to controller
+ */
+ int (*read_energy_info)();
} bt_interface_t;
/** TODO: Need to add APIs for Service Discovery, Service authorization and
--
1.9.1
From: Andrei Emeltchenko <[email protected]>
Add missing HAL functions for new Android version
---
android/hal-bluetooth.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index e9e413b..f9a3426 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -952,6 +952,35 @@ static int config_hci_snoop_log(uint8_t enable)
return BT_STATUS_SUCCESS;
}
+#if ANDROID_VERSION > PLATFORM_VER(4, 4, 4)
+static int get_connection_state(const bt_bdaddr_t *bd_addr)
+{
+ DBG("bdaddr: %s", bdaddr2str(bd_addr));
+
+ /* TODO: implement */
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_os_callouts(bt_os_callouts_t *callouts)
+{
+ DBG("callouts: %p", callouts);
+
+ /* TODO: implement */
+
+ return BT_STATUS_SUCCESS;
+}
+
+static int read_energy_info(void)
+{
+ DBG("");
+
+ /* TODO: implement */
+
+ return BT_STATUS_UNSUPPORTED;
+}
+#endif
+
static const bt_interface_t bluetooth_if = {
.size = sizeof(bt_interface_t),
.init = init,
@@ -978,6 +1007,11 @@ static const bt_interface_t bluetooth_if = {
.dut_mode_send = dut_mode_send,
.le_test_mode = le_test_mode,
.config_hci_snoop_log = config_hci_snoop_log,
+#if ANDROID_VERSION > PLATFORM_VER(4, 4, 4)
+ .get_connection_state = get_connection_state,
+ .set_os_callouts = set_os_callouts,
+ .read_energy_info = read_energy_info,
+#endif
};
static const bt_interface_t *get_bluetooth_interface(void)
--
1.9.1
From: Andrei Emeltchenko <[email protected]>
Add parameter to create_bond following new bluetooth.h HAL, transport is
defined in bluedroid include/bt_types.h. Bluetooth daemon shall check
transport parameter and make needed decisions, by default parameter is
unknown and this is the way bluedroid manage it itself.
---
android/bluetooth.c | 2 ++
android/hal-bluetooth.c | 19 ++++++++++++++++++-
android/hal-ipc-api.txt | 1 +
android/hal-msg.h | 5 +++++
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 03eb1a1..fdfa0d3 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -4323,6 +4323,8 @@ static void handle_create_bond_cmd(const void *buf, uint16_t len)
cp.addr.type = select_device_bearer(dev);
bacpy(&cp.addr.bdaddr, &dev->bdaddr);
+ /* TODO: Handle transport parameter */
+
if (device_is_paired(dev, cp.addr.type)) {
status = HAL_STATUS_FAILED;
goto fail;
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 97440e2..e9e413b 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -736,7 +736,7 @@ static int cancel_discovery(void)
NULL, NULL, NULL, NULL);
}
-static int create_bond(const bt_bdaddr_t *bd_addr)
+static int create_bond_real(const bt_bdaddr_t *bd_addr, int transport)
{
struct hal_cmd_create_bond cmd;
@@ -745,12 +745,29 @@ static int create_bond(const bt_bdaddr_t *bd_addr)
if (!interface_ready())
return BT_STATUS_NOT_READY;
+ if (transport < BT_TRANSPORT_UNKNOWN || transport > BT_TRANSPORT_LE)
+ return BT_STATUS_PARM_INVALID;
+
+ cmd.transport = transport;
+
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
+#if ANDROID_VERSION > PLATFORM_VER(4, 4, 4)
+static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
+{
+ return create_bond_real(bd_addr, transport);
+}
+#else
+static int create_bond(const bt_bdaddr_t *bd_addr)
+{
+ return create_bond_real(bd_addr, BT_TRANSPORT_UNKNOWN);
+}
+#endif
+
static int cancel_bond(const bt_bdaddr_t *bd_addr)
{
struct hal_cmd_cancel_bond cmd;
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 6c647b7..3a3ae92 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -275,6 +275,7 @@ Commands and responses:
Opcode 0x0d - Create Bond command/response
Command parameters: Remote address (6 octets)
+ Transport (1 octet)
Response parameters: <none>
In case of an error, the error response will be returned.
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 12efcef..bcb73b2 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -190,9 +190,14 @@ struct hal_cmd_get_remote_services {
#define HAL_OP_CANCEL_DISCOVERY 0x0c
+#define BT_TRANSPORT_UNKNOWN 0x00
+#define BT_TRANSPORT_BR_EDR 0x01
+#define BT_TRANSPORT_LE 0x02
+
#define HAL_OP_CREATE_BOND 0x0d
struct hal_cmd_create_bond {
uint8_t bdaddr[6];
+ uint8_t transport;
} __attribute__((packed));
#define HAL_OP_REMOVE_BOND 0x0e
--
1.9.1