blob: 6d2edc77a4419f0470b2e0417a0a007bc78c552f [file] [log] [blame]
/*
* Copyright (C) 2013 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <glib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/signalfd.h>
#include <libgen.h>
#include "lib/bluetooth.h"
#include "lib/mgmt.h"
#include "src/shared/util.h"
#include "src/shared/tester.h"
#include "src/shared/mgmt.h"
#include "src/shared/hciemu.h"
#include "emulator/bthost.h"
#include "monitor/bt.h"
#include <hardware/hardware.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_hh.h>
#include "utils.h"
struct priority_property {
bt_property_t prop;
int prio;
};
struct generic_data {
int expected_adapter_status;
uint32_t expect_settings_set;
int expected_cb_count;
bt_property_t set_property;
bt_callbacks_t expected_hal_cb;
struct priority_property *expected_properties;
uint8_t expected_properties_num;
};
struct socket_data {
btsock_type_t sock_type;
const char *service_name;
const uint8_t *service_uuid;
const bt_bdaddr_t *bdaddr;
int channel;
int flags;
bt_status_t expected_status;
bool test_channel;
};
struct hidhost_generic_data {
bthh_status_t expected_status;
int expected_conn_state;
int expected_cb_count;
bthh_protocol_mode_t expected_protocol_mode;
int expected_report;
bthh_callbacks_t expected_hal_cb;
int expected_report_size;
};
#define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
#define EMULATOR_SIGNAL "emulator_started"
#define BT_STATUS_NOT_EXPECTED -1
struct test_data {
struct mgmt *mgmt;
uint16_t mgmt_index;
unsigned int mgmt_settings_id;
struct hciemu *hciemu;
enum hciemu_type hciemu_type;
const void *test_data;
pid_t bluetoothd_pid;
guint signalfd;
struct hw_device_t *device;
const bt_interface_t *if_bluetooth;
const btsock_interface_t *if_sock;
const bthh_interface_t *if_hid;
int conditions_left;
/* Set to true if test conditions should be verified */
bool test_checks_valid;
bool test_result_set;
int cb_count;
GSList *expected_properties_list;
/* hidhost */
uint16_t sdp_handle;
uint16_t sdp_cid;
uint16_t ctrl_handle;
uint16_t ctrl_cid;
uint16_t intr_handle;
uint16_t intr_cid;
};
struct bt_cb_data {
bt_state_t state;
bt_status_t status;
bt_bdaddr_t bdaddr;
bt_bdname_t bdname;
uint32_t cod;
bt_ssp_variant_t ssp_variant;
uint32_t passkey;
int num;
bt_property_t *props;
};
struct hh_cb_data {
bt_bdaddr_t bdaddr;
bthh_status_t status;
bthh_hid_info_t hid_info;
bthh_protocol_mode_t mode;
bthh_connection_state_t state;
uint8_t *report;
int size;
};
static char exec_dir[PATH_MAX + 1];
static gint scheduled_cbacks_num = 0;
static gboolean check_callbacks_called(gpointer user_data)
{
/* Wait for all callbacks scheduled in current test context to execute
* in main loop. This will avoid late callback calls after test case has
* already failed or timed out.
*/
if (g_atomic_int_get(&scheduled_cbacks_num) == 0) {
tester_teardown_complete();
return FALSE;
}
return TRUE;
}
static void check_daemon_term(void)
{
int status;
pid_t pid;
struct test_data *data = tester_get_data();
if (!data)
return;
pid = waitpid(data->bluetoothd_pid, &status, WNOHANG);
if (pid != data->bluetoothd_pid)
return;
data->bluetoothd_pid = 0;
if (WIFEXITED(status) && (WEXITSTATUS(status) == EXIT_SUCCESS)) {
g_idle_add(check_callbacks_called, NULL);
return;
}
tester_warn("Unexpected Daemon shutdown with status %d", status);
}
static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
gpointer user_data)
{
struct signalfd_siginfo si;
ssize_t result;
int fd;
if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
return FALSE;
fd = g_io_channel_unix_get_fd(channel);
result = read(fd, &si, sizeof(si));
if (result != sizeof(si))
return FALSE;
switch (si.ssi_signo) {
case SIGCHLD:
check_daemon_term();
break;
}
return TRUE;
}
static guint setup_signalfd(void)
{
GIOChannel *channel;
guint source;
sigset_t mask;
int fd;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
return 0;
fd = signalfd(-1, &mask, 0);
if (fd < 0)
return 0;
channel = g_io_channel_unix_new(fd);
g_io_channel_set_close_on_unref(channel, TRUE);
g_io_channel_set_encoding(channel, NULL, NULL);
g_io_channel_set_buffered(channel, FALSE);
source = g_io_add_watch(channel,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
signal_handler, NULL);
g_io_channel_unref(channel);
return source;
}
static void mgmt_debug(const char *str, void *user_data)
{
const char *prefix = user_data;
tester_print("%s%s", prefix, str);
}
static void test_update_state(void)
{
struct test_data *data = tester_get_data();
if (data->conditions_left == 0 && !data->test_result_set) {
data->test_result_set = true;
tester_test_passed();
}
}
static void test_mgmt_settings_set(struct test_data *data)
{
data->conditions_left--;
test_update_state();
}
static void command_generic_new_settings(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test_data = data->test_data;
uint32_t settings;
if (length != 4) {
tester_warn("Invalid parameter size for new settings event");
tester_test_failed();
return;
}
settings = get_le32(param);
if ((settings & test_data->expect_settings_set) !=
test_data->expect_settings_set)
return;
test_mgmt_settings_set(data);
mgmt_unregister(data->mgmt, data->mgmt_settings_id);
}
static void check_cb_count(void)
{
struct test_data *data = tester_get_data();
if (!data->test_checks_valid)
return;
if (data->cb_count == 0) {
data->conditions_left--;
test_update_state();
}
}
static void expected_cb_count_init(struct test_data *data)
{
const struct generic_data *test_data = data->test_data;
data->cb_count = test_data->expected_cb_count;
check_cb_count();
}
static void mgmt_cb_init(struct test_data *data)
{
const struct generic_data *test_data = data->test_data;
if (!test_data->expect_settings_set)
test_mgmt_settings_set(data);
else
data->mgmt_settings_id = mgmt_register(data->mgmt,
MGMT_EV_NEW_SETTINGS, data->mgmt_index,
command_generic_new_settings, NULL, NULL);
}
static void expected_status_init(struct test_data *data)
{
const struct generic_data *test_data = data->test_data;
if (test_data->expected_adapter_status == BT_STATUS_NOT_EXPECTED)
data->conditions_left--;
}
static void test_property_init(struct test_data *data)
{
const struct generic_data *test_data = data->test_data;
GSList *l = data->expected_properties_list;
int i;
if (!test_data->expected_properties_num) {
data->conditions_left--;
return;
}
for (i = 0; i < test_data->expected_properties_num; i++)
l = g_slist_prepend(l, &(test_data->expected_properties[i]));
data->expected_properties_list = l;
}
static void init_test_conditions(struct test_data *data)
{
data->test_checks_valid = true;
data->conditions_left = 4;
expected_cb_count_init(data);
mgmt_cb_init(data);
expected_status_init(data);
test_property_init(data);
}
static void check_expected_status(uint8_t status)
{
struct test_data *data = tester_get_data();
const struct generic_data *test_data = data->test_data;
if (test_data->expected_adapter_status == status) {
data->conditions_left--;
test_update_state();
} else
tester_test_failed();
}
static int locate_property(gconstpointer expected_data,
gconstpointer received_prop)
{
bt_property_t rec_prop = *((bt_property_t *)received_prop);
bt_property_t exp_prop =
((struct priority_property *)expected_data)->prop;
if (exp_prop.type && (exp_prop.type != rec_prop.type))
return 1;
if (exp_prop.len && (exp_prop.len != rec_prop.len))
return 1;
if (exp_prop.val && memcmp(exp_prop.val, rec_prop.val, exp_prop.len))
return 1;
return 0;
}
static int compare_priorities(gconstpointer prop_list, gconstpointer priority)
{
int prio = GPOINTER_TO_INT(priority);
int comp_prio = ((struct priority_property *)prop_list)->prio;
if (prio > comp_prio)
return 0;
return 1;
}
static bool check_prop_priority(int rec_prop_prio)
{
struct test_data *data = tester_get_data();
GSList *l = data->expected_properties_list;
if (!rec_prop_prio || !g_slist_length(l))
return true;
if (g_slist_find_custom(l, GINT_TO_POINTER(rec_prop_prio),
&compare_priorities))
return false;
return true;
}
static void check_expected_property(bt_property_t received_prop)
{
struct test_data *data = tester_get_data();
int rec_prio;
GSList *l = data->expected_properties_list;
GSList *found_exp_prop;
if (!g_slist_length(l))
return;
found_exp_prop = g_slist_find_custom(l, &received_prop,
&locate_property);
if (found_exp_prop) {
rec_prio = ((struct priority_property *)
(found_exp_prop->data))->prio;
if (check_prop_priority(rec_prio))
l = g_slist_remove(l, found_exp_prop->data);
}
data->expected_properties_list = l;
if (g_slist_length(l))
return;
data->conditions_left--;
test_update_state();
}
static bool check_test_property(bt_property_t received_prop,
bt_property_t expected_prop)
{
if (expected_prop.type && (expected_prop.type != received_prop.type))
return false;
if (expected_prop.len && (expected_prop.len != received_prop.len))
return false;
if (expected_prop.val && memcmp(expected_prop.val, received_prop.val,
expected_prop.len))
return false;
return true;
}
static void read_info_callback(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
const struct mgmt_rp_read_info *rp = param;
char addr[18];
uint16_t manufacturer;
uint32_t supported_settings, current_settings;
tester_print("Read Info callback");
tester_print(" Status: 0x%02x", status);
if (status || !param) {
tester_pre_setup_failed();
return;
}
ba2str(&rp->bdaddr, addr);
manufacturer = btohs(rp->manufacturer);
supported_settings = btohl(rp->supported_settings);
current_settings = btohl(rp->current_settings);
tester_print(" Address: %s", addr);
tester_print(" Version: 0x%02x", rp->version);
tester_print(" Manufacturer: 0x%04x", manufacturer);
tester_print(" Supported settings: 0x%08x", supported_settings);
tester_print(" Current settings: 0x%08x", current_settings);
tester_print(" Class: 0x%02x%02x%02x",
rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
tester_print(" Name: %s", rp->name);
tester_print(" Short name: %s", rp->short_name);
if (strcmp(hciemu_get_address(data->hciemu), addr)) {
tester_pre_setup_failed();
return;
}
tester_pre_setup_complete();
}
static void index_added_callback(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
tester_print("Index Added callback");
tester_print(" Index: 0x%04x", index);
data->mgmt_index = index;
mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
read_info_callback, NULL, NULL);
}
static void index_removed_callback(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
tester_print("Index Removed callback");
tester_print(" Index: 0x%04x", index);
if (index != data->mgmt_index)
return;
mgmt_unregister_index(data->mgmt, data->mgmt_index);
mgmt_unref(data->mgmt);
data->mgmt = NULL;
tester_post_teardown_complete();
}
static void read_index_list_callback(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
tester_print("Read Index List callback");
tester_print(" Status: 0x%02x", status);
if (status || !param) {
tester_pre_setup_failed();
return;
}
mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
index_added_callback, NULL, NULL);
mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
index_removed_callback, NULL, NULL);
data->hciemu = hciemu_new(data->hciemu_type);
if (!data->hciemu) {
tester_warn("Failed to setup HCI emulation");
tester_pre_setup_failed();
return;
}
tester_print("New hciemu instance created");
}
static void test_pre_setup(const void *test_data)
{
struct test_data *data = tester_get_data();
data->signalfd = setup_signalfd();
if (!data->signalfd) {
tester_warn("Failed to setup signalfd");
tester_pre_setup_failed();
return;
}
data->mgmt = mgmt_new_default();
if (!data->mgmt) {
tester_warn("Failed to setup management interface");
tester_pre_setup_failed();
return;
}
if (!tester_use_debug())
fclose(stderr);
else
mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL);
mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
NULL, read_index_list_callback, NULL, NULL);
}
static void test_post_teardown(const void *test_data)
{
struct test_data *data = tester_get_data();
hciemu_unref(data->hciemu);
data->hciemu = NULL;
g_source_remove(data->signalfd);
data->signalfd = 0;
}
static void bluetoothd_start(int hci_index)
{
char prg_name[PATH_MAX + 1];
char index[8];
char *prg_argv[5];
snprintf(prg_name, sizeof(prg_name), "%s/%s", exec_dir, "bluetoothd");
snprintf(index, sizeof(index), "%d", hci_index);
prg_argv[0] = prg_name;
prg_argv[1] = "-i";
prg_argv[2] = index;
prg_argv[3] = "-d";
prg_argv[4] = NULL;
if (!tester_use_debug())
fclose(stderr);
execve(prg_argv[0], prg_argv, NULL);
}
static void emulator(int pipe, int hci_index)
{
static const char SYSTEM_SOCKET_PATH[] = "\0android_system";
char buf[1024];
struct sockaddr_un addr;
struct timeval tv;
int fd;
ssize_t len;
fd = socket(PF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (fd < 0)
goto failed;
tv.tv_sec = WAIT_FOR_SIGNAL_TIME;
tv.tv_usec = 0;
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path, SYSTEM_SOCKET_PATH, sizeof(SYSTEM_SOCKET_PATH));
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("Failed to bind system socket");
goto failed;
}
len = write(pipe, EMULATOR_SIGNAL, sizeof(EMULATOR_SIGNAL));
if (len != sizeof(EMULATOR_SIGNAL))
goto failed;
memset(buf, 0, sizeof(buf));
len = read(fd, buf, sizeof(buf));
if (len <= 0 || strcmp(buf, "bluetooth.start=daemon"))
goto failed;
close(pipe);
close(fd);
return bluetoothd_start(hci_index);
failed:
close(pipe);
if (fd >= 0)
close(fd);
}
static void emu_connectable_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
{
switch (opcode) {
case BT_HCI_CMD_WRITE_SCAN_ENABLE:
case BT_HCI_CMD_LE_SET_ADV_ENABLE:
break;
default:
return;
}
tester_print("Emulated remote set connectable status 0x%02x", status);
if (status)
tester_setup_failed();
else
tester_setup_complete();
}
static void setup_powered_emulated_remote(void)
{
struct test_data *data = tester_get_data();
struct bthost *bthost;
tester_print("Controller powered on");
bthost = hciemu_client_get_host(data->hciemu);
bthost_set_cmd_complete_cb(bthost, emu_connectable_complete, data);
if (data->hciemu_type == HCIEMU_TYPE_LE)
bthost_set_adv_enable(bthost, 0x01);
else
bthost_write_scan_enable(bthost, 0x03);
}
static void enable_success_cb(bt_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_STATE_ON) {
setup_powered_emulated_remote();
data->cb_count--;
check_cb_count();
}
}
static void disable_success_cb(bt_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_STATE_OFF) {
data->cb_count--;
check_cb_count();
}
}
static gboolean adapter_state_changed(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid &&
test->expected_hal_cb.adapter_state_changed_cb) {
test->expected_hal_cb.adapter_state_changed_cb(cb_data->state);
goto cleanup;
}
if (!data->test_checks_valid && cb_data->state == BT_STATE_ON)
setup_powered_emulated_remote();
cleanup:
g_free(cb_data);
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
return FALSE;
}
static void adapter_state_changed_cb(bt_state_t state)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->state = state;
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(adapter_state_changed, cb_data);
}
static void discovery_start_success_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_DISCOVERY_STARTED) {
data->cb_count--;
check_cb_count();
}
}
static void discovery_start_done_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
bt_status_t status;
status = data->if_bluetooth->start_discovery();
data->cb_count--;
check_cb_count();
check_expected_status(status);
}
static void discovery_stop_success_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
bt_status_t status;
if (state == BT_DISCOVERY_STARTED && data->cb_count == 2) {
status = data->if_bluetooth->cancel_discovery();
check_expected_status(status);
data->cb_count--;
return;
}
if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
data->cb_count--;
check_cb_count();
}
}
static void discovery_device_found_state_changed_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_DISCOVERY_STARTED && data->cb_count == 3) {
data->cb_count--;
return;
}
if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
data->cb_count--;
check_cb_count();
}
}
static void remote_discovery_state_changed_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_DISCOVERY_STARTED && data->cb_count == 3) {
data->cb_count--;
return;
}
if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
data->cb_count--;
check_cb_count();
}
}
static void remote_setprop_disc_state_changed_cb(bt_discovery_state_t state)
{
struct test_data *data = tester_get_data();
if (state == BT_DISCOVERY_STARTED && data->cb_count == 4) {
data->cb_count--;
return;
}
if (state == BT_DISCOVERY_STOPPED) {
data->cb_count--;
check_cb_count();
}
}
static gboolean discovery_state_changed(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (test && test->expected_hal_cb.discovery_state_changed_cb)
test->expected_hal_cb.discovery_state_changed_cb(
cb_data->state);
g_free(cb_data);
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
return FALSE;
}
static void discovery_state_changed_cb(bt_discovery_state_t state)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->state = state;
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(discovery_state_changed, cb_data);
}
static bt_property_t *copy_properties(int num_properties,
bt_property_t *properties)
{
int i;
bt_property_t *props = g_new0(bt_property_t, num_properties);
for (i = 0; i < num_properties; i++) {
props[i].type = properties[i].type;
props[i].len = properties[i].len;
props[i].val = g_memdup(properties[i].val, properties[i].len);
}
return props;
}
static void free_properties(int num_properties, bt_property_t *properties)
{
int i;
for (i = 0; i < num_properties; i++)
g_free(properties[i].val);
g_free(properties);
}
static void discovery_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
uint8_t *remote_bdaddr =
(uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
uint32_t emu_remote_type = BT_DEVICE_DEVTYPE_BREDR;
int32_t emu_remote_rssi = -60;
bt_bdaddr_t emu_remote_bdaddr;
int i;
bt_property_t expected_prop;
bt_property_t received_prop;
data->cb_count--;
check_cb_count();
if (num_properties < 1) {
tester_test_failed();
return;
}
bdaddr2android((const bdaddr_t *) remote_bdaddr, &emu_remote_bdaddr);
for (i = 0; i < num_properties; i++) {
received_prop = properties[i];
switch (properties[i].type) {
case BT_PROPERTY_BDADDR:
expected_prop.type = BT_PROPERTY_BDADDR;
expected_prop.len = sizeof(emu_remote_bdaddr);
expected_prop.val = &emu_remote_bdaddr;
break;
case BT_PROPERTY_TYPE_OF_DEVICE:
expected_prop.type = BT_PROPERTY_TYPE_OF_DEVICE;
expected_prop.len = sizeof(emu_remote_type);
expected_prop.val = &emu_remote_type;
break;
case BT_PROPERTY_REMOTE_RSSI:
expected_prop.type = BT_PROPERTY_REMOTE_RSSI;
expected_prop.len = sizeof(emu_remote_rssi);
expected_prop.val = &emu_remote_rssi;
break;
default:
expected_prop.type = 0;
expected_prop.len = 0;
expected_prop.val = NULL;
break;
}
if (!check_test_property(received_prop, expected_prop)) {
data->if_bluetooth->cancel_discovery();
tester_test_failed();
return;
}
}
data->if_bluetooth->cancel_discovery();
}
static void remote_getprops_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 2)
data->cb_count--;
data->if_bluetooth->cancel_discovery();
data->if_bluetooth->get_remote_device_properties(&remote_addr);
}
static void remote_get_property_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
bt_status_t status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
const bt_property_t prop = test->expected_properties[0].prop;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 2)
data->cb_count--;
data->if_bluetooth->cancel_discovery();
status = data->if_bluetooth->get_remote_device_property(&remote_addr,
prop.type);
check_expected_status(status);
}
static void remote_setprop_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
bt_status_t status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
const bt_property_t prop = test->expected_properties[0].prop;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 3)
data->cb_count--;
data->if_bluetooth->cancel_discovery();
status = data->if_bluetooth->set_remote_device_property(&remote_addr,
&prop);
check_expected_status(status);
}
static void remote_setprop_fail_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
bt_status_t status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
const bt_property_t prop = test->expected_properties[0].prop;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 2)
data->cb_count--;
data->if_bluetooth->cancel_discovery();
status = data->if_bluetooth->set_remote_device_property(&remote_addr,
&prop);
check_expected_status(status);
}
static void bond_device_found_cb(int num_properties, bt_property_t *properties)
{
struct test_data *data = tester_get_data();
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
bt_status_t status;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 4) {
data->cb_count--;
status = data->if_bluetooth->create_bond(&remote_addr);
check_expected_status(status);
}
}
static void bond_nostatus_device_found_cb(int num_properties,
bt_property_t *properties)
{
struct test_data *data = tester_get_data();
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (data->cb_count == 4) {
data->cb_count--;
data->if_bluetooth->create_bond(&remote_addr);
}
}
static gboolean device_found(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid && test->expected_hal_cb.device_found_cb)
test->expected_hal_cb.device_found_cb(cb_data->num,
cb_data->props);
free_properties(cb_data->num, cb_data->props);
g_free(cb_data);
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
return FALSE;
}
static void device_found_cb(int num_properties, bt_property_t *properties)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->num = num_properties;
cb_data->props = copy_properties(num_properties, properties);
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(device_found, cb_data);
}
static void check_count_properties_cb(bt_status_t status, int num_properties,
bt_property_t *properties)
{
int i;
for (i = 0; i < num_properties; i++)
check_expected_property(properties[i]);
}
static gboolean adapter_properties(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid &&
test->expected_hal_cb.adapter_properties_cb)
test->expected_hal_cb.adapter_properties_cb(cb_data->status,
cb_data->num, cb_data->props);
free_properties(cb_data->num, cb_data->props);
g_free(cb_data);
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
return FALSE;
}
static void adapter_properties_cb(bt_status_t status, int num_properties,
bt_property_t *properties)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->status = status;
cb_data->num = num_properties;
cb_data->props = copy_properties(num_properties, properties);
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(adapter_properties, cb_data);
}
static void remote_test_device_properties_cb(bt_status_t status,
bt_bdaddr_t *bd_addr, int num_properties,
bt_property_t *properties)
{
int i;
for (i = 0; i < num_properties; i++)
check_expected_property(properties[i]);
}
static void remote_setprop_device_properties_cb(bt_status_t status,
bt_bdaddr_t *bd_addr, int num_properties,
bt_property_t *properties)
{
int i;
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
const bt_property_t prop = test->expected_properties[1].prop;
for (i = 0; i < num_properties; i++)
check_expected_property(properties[i]);
if (g_slist_length(data->expected_properties_list) == 1) {
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
data->cb_count--;
check_cb_count();
data->if_bluetooth->get_remote_device_property(&remote_addr,
prop.type);
}
}
static gboolean remote_device_properties(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid &&
test->expected_hal_cb.remote_device_properties_cb)
test->expected_hal_cb.remote_device_properties_cb(
cb_data->status, &cb_data->bdaddr,
cb_data->num, cb_data->props);
free_properties(cb_data->num, cb_data->props);
g_free(cb_data);
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
return FALSE;
}
static void remote_device_properties_cb(bt_status_t status,
bt_bdaddr_t *bd_addr, int num_properties,
bt_property_t *properties)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->status = status;
cb_data->bdaddr = *bd_addr;
cb_data->num = num_properties;
cb_data->props = copy_properties(num_properties, properties);
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(remote_device_properties, cb_data);
}
static void bond_test_bonded_state_changed_cb(bt_status_t status,
bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
{
struct test_data *data = tester_get_data();
switch (state) {
case BT_BOND_STATE_BONDING:
data->cb_count--;
break;
case BT_BOND_STATE_BONDED:
data->cb_count--;
check_cb_count();
break;
default:
tester_test_failed();
break;
}
}
static void bond_test_none_state_changed_cb(bt_status_t status,
bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
{
struct test_data *data = tester_get_data();
switch (state) {
case BT_BOND_STATE_BONDING:
data->cb_count--;
break;
case BT_BOND_STATE_NONE:
data->cb_count--;
check_cb_count();
break;
default:
tester_test_failed();
break;
}
}
static void bond_remove_success_state_changed_cb(bt_status_t status,
bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
{
struct test_data *data = tester_get_data();
bt_status_t remove_status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
if (state == BT_BOND_STATE_BONDED) {
data->cb_count--;
remove_status = data->if_bluetooth->remove_bond(&remote_addr);
check_expected_status(remove_status);
return;
}
if (state == BT_BOND_STATE_NONE) {
data->cb_count--;
check_cb_count();
}
}
static gboolean bond_state_changed(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid &&
test->expected_hal_cb.bond_state_changed_cb)
test->expected_hal_cb.bond_state_changed_cb(cb_data->status,
&cb_data->bdaddr, cb_data->state);
g_free(cb_data);
return FALSE;
}
static void bond_state_changed_cb(bt_status_t status,
bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->status = status;
cb_data->bdaddr = *remote_bd_addr;
cb_data->state = state;
g_idle_add(bond_state_changed, cb_data);
}
static void bond_create_pin_success_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod)
{
struct test_data *data = tester_get_data();
const bt_bdaddr_t *bdaddr = remote_bd_addr;
bt_pin_code_t pin_code = {
.pin = { 0x30, 0x30, 0x30, 0x30 },
};
uint8_t pin_len = 4;
data->cb_count--;
data->if_bluetooth->pin_reply(bdaddr, TRUE, pin_len, &pin_code);
}
static void bond_create_pin_fail_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod)
{
struct test_data *data = tester_get_data();
const bt_bdaddr_t *bdaddr = remote_bd_addr;
bt_pin_code_t pin_code = {
.pin = { 0x31, 0x31, 0x31, 0x31 },
};
uint8_t pin_len = 4;
data->cb_count--;
data->if_bluetooth->pin_reply(bdaddr, TRUE, pin_len, &pin_code);
}
static gboolean pin_request(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid && test->expected_hal_cb.pin_request_cb)
test->expected_hal_cb.pin_request_cb(&cb_data->bdaddr,
&cb_data->bdname, cb_data->cod);
g_free(cb_data);
return FALSE;
}
static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->bdaddr = *remote_bd_addr;
cb_data->bdname = *bd_name;
cb_data->cod = cod;
g_idle_add(pin_request, cb_data);
}
static void bond_create_ssp_request_cb(const bt_bdaddr_t *remote_bd_addr,
bt_ssp_variant_t pairing_variant,
bool accept, uint32_t pass_key)
{
struct test_data *data = tester_get_data();
data->if_bluetooth->ssp_reply(remote_bd_addr,
BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
accept, pass_key);
data->cb_count--;
}
static void bond_create_ssp_success_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod,
bt_ssp_variant_t pairing_variant,
uint32_t pass_key)
{
bool accept = true;
bond_create_ssp_request_cb(remote_bd_addr, pairing_variant, accept,
pass_key);
}
static void bond_create_ssp_fail_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod,
bt_ssp_variant_t pairing_variant,
uint32_t pass_key)
{
bool accept = false;
bond_create_ssp_request_cb(remote_bd_addr, pairing_variant, accept,
pass_key);
}
static void bond_cancel_success_ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
bt_bdname_t *bd_name, uint32_t cod,
bt_ssp_variant_t pairing_variant,
uint32_t pass_key)
{
struct test_data *data = tester_get_data();
uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
bt_bdaddr_t remote_addr;
bt_status_t status;
bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
data->cb_count--;
status = data->if_bluetooth->cancel_bond(&remote_addr);
check_expected_status(status);
}
static gboolean ssp_request(gpointer user_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
struct bt_cb_data *cb_data = user_data;
if (data->test_checks_valid && test->expected_hal_cb.ssp_request_cb)
test->expected_hal_cb.ssp_request_cb(&cb_data->bdaddr,
&cb_data->bdname, cb_data->cod,
cb_data->ssp_variant, cb_data->passkey);
g_free(cb_data);
return FALSE;
}
static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
uint32_t cod, bt_ssp_variant_t pairing_variant,
uint32_t pass_key)
{
struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
cb_data->bdaddr = *remote_bd_addr;
cb_data->bdname = *bd_name;
cb_data->cod = cod;
cb_data->ssp_variant = pairing_variant;
cb_data->passkey = pass_key;
g_idle_add(ssp_request, cb_data);
}
static bt_bdaddr_t enable_done_bdaddr_val = { {0x00} };
static const char enable_done_bdname_val[] = "BlueZ for Android";
static bt_uuid_t enable_done_uuids_val = {
.uu = { 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb},
};
static bt_device_type_t enable_done_tod_val = BT_DEVICE_DEVTYPE_DUAL;
static bt_scan_mode_t enable_done_scanmode_val = BT_SCAN_MODE_NONE;
static uint32_t enable_done_disctimeout_val = 120;
static struct priority_property enable_done_props[] = {
{
.prop.type = BT_PROPERTY_BDADDR,
.prop.len = sizeof(enable_done_bdaddr_val),
.prop.val = &enable_done_bdaddr_val,
.prio = 1,
},
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.len = sizeof(enable_done_bdname_val) - 1,
.prop.val = &enable_done_bdname_val,
.prio = 2,
},
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.len = sizeof(enable_done_uuids_val),
.prop.val = &enable_done_uuids_val,
.prio = 3,
},
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.len = sizeof(uint32_t),
.prop.val = NULL,
.prio = 4,
},
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.len = sizeof(enable_done_tod_val),
.prop.val = &enable_done_tod_val,
.prio = 5,
},
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.len = sizeof(enable_done_scanmode_val),
.prop.val = &enable_done_scanmode_val,
.prio = 6,
},
{
.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
.prop.len = 0,
.prop.val = NULL,
.prio = 7,
},
{
.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
.prop.len = sizeof(enable_done_disctimeout_val),
.prop.val = &enable_done_disctimeout_val,
.prio = 8,
},
};
static const struct generic_data bluetooth_enable_success_test = {
.expected_hal_cb.adapter_state_changed_cb = enable_success_cb,
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_cb_count = 1,
.expected_properties_num = 8,
.expected_properties = enable_done_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_enable_success2_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_adapter_status = BT_STATUS_SUCCESS,
.expected_properties_num = 8,
.expected_properties = enable_done_props,
};
static const struct generic_data bluetooth_disable_success_test = {
.expected_hal_cb.adapter_state_changed_cb = disable_success_cb,
.expected_cb_count = 1,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static char test_set_bdname[] = "test_bdname_set";
static struct priority_property setprop_bdname_props[] = {
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.val = test_set_bdname,
.prop.len = sizeof(test_set_bdname) - 1,
.prio = 0,
},
};
static const struct generic_data bluetooth_setprop_bdname_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = setprop_bdname_props,
};
static bt_scan_mode_t test_setprop_scanmode_val =
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE;
static struct priority_property setprop_scanmode_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &test_setprop_scanmode_val,
.prop.len = sizeof(bt_scan_mode_t),
},
};
static const struct generic_data bluetooth_setprop_scanmode_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = setprop_scanmode_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static uint32_t test_setprop_disctimeout_val = 120;
static struct priority_property setprop_disctimeout_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
.prop.val = &test_setprop_disctimeout_val,
.prop.len = sizeof(test_setprop_disctimeout_val),
},
};
static const struct generic_data bluetooth_setprop_disctimeout_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = setprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_bdaddr_t test_getprop_bdaddr_val = { {0x00} };
static struct priority_property getprop_bdaddr_props[] = {
{
.prop.type = BT_PROPERTY_BDADDR,
.prop.val = &test_getprop_bdaddr_val,
.prop.len = sizeof(test_getprop_bdaddr_val),
},
};
static const struct generic_data bluetooth_getprop_bdaddr_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_bdaddr_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const char test_bdname[] = "test_bdname_setget";
static struct priority_property getprop_bdname_props[] = {
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.val = &test_bdname,
.prop.len = sizeof(test_bdname) - 1,
},
};
static const struct generic_data bluetooth_getprop_bdname_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_bdname_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static unsigned char setprop_uuids[] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00,
0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
static struct priority_property setprop_uuid_prop[] = {
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.val = &setprop_uuids,
.prop.len = sizeof(setprop_uuids),
},
};
static const struct generic_data bluetooth_setprop_uuid_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static uint32_t setprop_class_of_device = 0;
static struct priority_property setprop_cod_props[] = {
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.val = &setprop_class_of_device,
.prop.len = sizeof(setprop_class_of_device),
},
};
static const struct generic_data bluetooth_setprop_cod_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_device_type_t setprop_type_of_device = BT_DEVICE_DEVTYPE_DUAL;
static struct priority_property setprop_tod_props[] = {
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.val = &setprop_type_of_device,
.prop.len = sizeof(setprop_type_of_device),
},
};
static const struct generic_data bluetooth_setprop_tod_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static int32_t setprop_remote_rssi = 0;
static struct priority_property setprop_remote_rssi_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_RSSI,
.prop.val = &setprop_remote_rssi,
.prop.len = sizeof(setprop_remote_rssi),
},
};
static const struct generic_data bluetooth_setprop_remote_rssi_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_service_record_t setprop_remote_service = {
.uuid = { {0x00} },
.channel = 12,
.name = "bt_name",
};
static struct priority_property setprop_service_record_props[] = {
{
.prop.type = BT_PROPERTY_SERVICE_RECORD,
.prop.val = &setprop_remote_service,
.prop.len = sizeof(setprop_remote_service),
},
};
static const struct generic_data
bluetooth_setprop_service_record_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_bdaddr_t setprop_bdaddr = {
.address = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
};
static struct priority_property setprop_bdaddr_props[] = {
{
.prop.type = BT_PROPERTY_BDADDR,
.prop.val = &setprop_bdaddr,
.prop.len = sizeof(setprop_bdaddr),
},
};
static const struct generic_data bluetooth_setprop_bdaddr_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_scan_mode_t setprop_scanmode_connectable = BT_SCAN_MODE_CONNECTABLE;
static struct priority_property setprop_scanmode_connectable_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &setprop_scanmode_connectable,
.prop.len = sizeof(setprop_scanmode_connectable),
},
};
static const struct generic_data
bluetooth_setprop_scanmode_connectable_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = setprop_scanmode_connectable_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_bdaddr_t setprop_bonded_devices = {
.address = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
};
static struct priority_property setprop_bonded_devices_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
.prop.val = &setprop_bonded_devices,
.prop.len = sizeof(setprop_bonded_devices),
},
};
static const struct generic_data
bluetooth_setprop_bonded_devices_invalid_test = {
.expected_adapter_status = BT_STATUS_FAIL,
};
static uint32_t getprop_cod = 0x00020c;
static struct priority_property getprop_cod_props[] = {
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.val = &getprop_cod,
.prop.len = sizeof(getprop_cod),
},
};
static const struct generic_data bluetooth_getprop_cod_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_cod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_device_type_t getprop_tod = BT_DEVICE_DEVTYPE_DUAL;
static struct priority_property getprop_tod_props[] = {
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.val = &getprop_tod,
.prop.len = sizeof(getprop_tod),
},
};
static const struct generic_data bluetooth_getprop_tod_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_tod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_scan_mode_t getprop_scanmode = BT_SCAN_MODE_NONE;
static struct priority_property getprop_scanmode_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &getprop_scanmode,
.prop.len = sizeof(getprop_scanmode),
},
};
static const struct generic_data bluetooth_getprop_scanmode_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_scanmode_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static uint32_t getprop_disctimeout_val = 120;
static struct priority_property getprop_disctimeout_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
.prop.val = &getprop_disctimeout_val,
.prop.len = sizeof(getprop_disctimeout_val),
},
};
static const struct generic_data bluetooth_getprop_disctimeout_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_uuid_t getprop_uuids = {
.uu = { 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB },
};
static struct priority_property getprop_uuids_props[] = {
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.val = &getprop_uuids,
.prop.len = sizeof(getprop_uuids),
},
};
static const struct generic_data bluetooth_getprop_uuids_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_uuids_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static struct priority_property getprop_bondeddev_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bluetooth_getprop_bondeddev_success_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = getprop_bondeddev_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_scan_mode_t setprop_scanmode_none = BT_SCAN_MODE_NONE;
static struct priority_property setprop_scanmode_none_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &setprop_scanmode_none,
.prop.len = sizeof(setprop_scanmode_none),
},
};
static const struct generic_data
bluetooth_setprop_scanmode_none_success2_test = {
.expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
.expected_properties_num = 1,
.expected_properties = setprop_scanmode_none_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_discovery_start_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
discovery_start_success_cb,
.expected_cb_count = 1,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_discovery_start_success2_test = {
.expected_hal_cb.discovery_state_changed_cb = discovery_start_done_cb,
.expected_cb_count = 1,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_discovery_stop_success2_test = {
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_discovery_stop_success_test = {
.expected_hal_cb.discovery_state_changed_cb = discovery_stop_success_cb,
.expected_cb_count = 2,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bluetooth_discovery_device_found_test = {
.expected_hal_cb.discovery_state_changed_cb =
discovery_device_found_state_changed_cb,
.expected_hal_cb.device_found_cb = discovery_device_found_cb,
.expected_cb_count = 3,
.expected_adapter_status = BT_STATUS_NOT_EXPECTED,
};
static const char remote_get_properties_bdname_val[] = "00:AA:01:01:00:00";
static uint32_t remote_get_properties_cod_val = 0;
static bt_device_type_t remote_get_properties_tod_val = BT_DEVICE_DEVTYPE_BREDR;
static int32_t remote_get_properties_rssi_val = -60;
static struct priority_property remote_getprops_props[] = {
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.val = &remote_get_properties_bdname_val,
.prop.len = sizeof(remote_get_properties_bdname_val) - 1,
.prio = 1,
},
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.val = NULL,
.prop.len = 0,
.prio = 2,
},
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.val = &remote_get_properties_cod_val,
.prop.len = sizeof(remote_get_properties_cod_val),
.prio = 3,
},
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.val = &remote_get_properties_tod_val,
.prop.len = sizeof(remote_get_properties_tod_val),
.prio = 4,
},
{
.prop.type = BT_PROPERTY_REMOTE_RSSI,
.prop.val = &remote_get_properties_rssi_val,
.prop.len = sizeof(remote_get_properties_rssi_val),
.prio = 5,
},
{
.prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
.prop.val = NULL,
.prop.len = 4,
.prio = 6,
},
};
static const struct generic_data bt_dev_getprops_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_getprops_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 6,
.expected_properties = remote_getprops_props,
.expected_adapter_status = BT_STATUS_NOT_EXPECTED,
};
static const char remote_getprop_bdname_val[] = "00:AA:01:01:00:00";
static struct priority_property remote_getprop_bdname_props[] = {
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.val = &remote_getprop_bdname_val,
.prop.len = sizeof(remote_getprop_bdname_val) - 1,
},
};
static const struct generic_data bt_dev_getprop_bdname_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_bdname_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static struct priority_property remote_getprop_uuids_props[] = {
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bt_dev_getprop_uuids_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_uuids_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static uint32_t remote_getprop_cod_val = 0;
static struct priority_property remote_getprop_cod_props[] = {
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.val = &remote_getprop_cod_val,
.prop.len = sizeof(remote_getprop_cod_val),
},
};
static const struct generic_data bt_dev_getprop_cod_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_cod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_device_type_t remote_getprop_tod_val = BT_DEVICE_DEVTYPE_BREDR;
static struct priority_property remote_getprop_tod_props[] = {
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.val = &remote_getprop_tod_val,
.prop.len = sizeof(remote_getprop_tod_val),
},
};
static const struct generic_data bt_dev_getprop_tod_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_tod_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static int32_t remote_getprop_rssi_val = -60;
static struct priority_property remote_getprop_rssi_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_RSSI,
.prop.val = &remote_getprop_rssi_val,
.prop.len = sizeof(remote_getprop_rssi_val),
},
};
static const struct generic_data bt_dev_getprop_rssi_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_rssi_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static struct priority_property remote_getprop_timestamp_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
.prop.val = NULL,
.prop.len = 4,
},
};
static const struct generic_data bt_dev_getprop_timpestamp_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties_num = 1,
.expected_properties = remote_getprop_timestamp_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_bdaddr_t remote_getprop_bdaddr_val = {
.address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
};
static struct priority_property remote_getprop_bdaddr_props[] = {
{
.prop.type = BT_PROPERTY_BDADDR,
.prop.val = &remote_getprop_bdaddr_val,
.prop.len = sizeof(remote_getprop_bdaddr_val),
},
};
static const struct generic_data bt_dev_getprop_bdaddr_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_bdaddr_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_service_record_t remote_getprop_servrec_val = {
.uuid = { {0x00} },
.channel = 12,
.name = "bt_name",
};
static struct priority_property remote_getprop_servrec_props[] = {
{
.prop.type = BT_PROPERTY_SERVICE_RECORD,
.prop.val = &remote_getprop_servrec_val,
.prop.len = sizeof(remote_getprop_servrec_val),
},
};
static const struct generic_data bt_dev_getprop_servrec_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_servrec_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_scan_mode_t remote_getprop_scanmode_val = BT_SCAN_MODE_CONNECTABLE;
static struct priority_property remote_getprop_scanmode_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &remote_getprop_scanmode_val,
.prop.len = sizeof(remote_getprop_scanmode_val),
},
};
static const struct generic_data bt_dev_getprop_scanmode_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_scanmode_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static struct priority_property remote_getprop_bondeddev_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bt_dev_getprop_bondeddev_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_bondeddev_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static uint32_t remote_getprop_disctimeout_val = 120;
static struct priority_property remote_getprop_disctimeout_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
.prop.val = &remote_getprop_disctimeout_val,
.prop.len = sizeof(remote_getprop_disctimeout_val),
},
};
static const struct generic_data bt_dev_getprop_disctimeout_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static struct priority_property remote_getprop_verinfo_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bt_dev_getprop_verinfo_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_verinfo_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static struct priority_property remote_getprop_fname_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bt_dev_getprop_fname_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_test_device_properties_cb,
.expected_cb_count = 3,
.expected_properties = remote_getprop_fname_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static const char remote_setprop_fname_val[] = "set_fname_test";
static struct priority_property remote_setprop_fname_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME,
.prop.val = &remote_setprop_fname_val,
.prop.len = sizeof(remote_setprop_fname_val) - 1,
},
{
.prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME,
.prop.val = &remote_setprop_fname_val,
.prop.len = sizeof(remote_setprop_fname_val) - 1,
},
};
static const struct generic_data bt_dev_setprop_fname_success_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_setprop_disc_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_device_found_cb,
.expected_hal_cb.remote_device_properties_cb =
remote_setprop_device_properties_cb,
.expected_cb_count = 4,
.expected_properties_num = 2,
.expected_properties = remote_setprop_fname_props,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const char remote_setprop_bdname_val[] = "setprop_bdname_fail";
static struct priority_property remote_setprop_bdname_props[] = {
{
.prop.type = BT_PROPERTY_BDNAME,
.prop.val = &remote_setprop_bdname_val,
.prop.len = sizeof(remote_setprop_bdname_val) - 1,
},
};
static const struct generic_data bt_dev_setprop_bdname_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_bdname_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static struct priority_property remote_setprop_uuids_props[] = {
{
.prop.type = BT_PROPERTY_UUIDS,
.prop.val = NULL,
.prop.len = 0,
},
};
static const struct generic_data bt_dev_setprop_uuids_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_uuids_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static uint32_t remote_setprop_cod_val = 0;
static struct priority_property remote_setprop_cod_props[] = {
{
.prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
.prop.val = &remote_setprop_cod_val,
.prop.len = sizeof(remote_setprop_cod_val),
},
};
static const struct generic_data bt_dev_setprop_cod_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_cod_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_device_type_t remote_setprop_tod_val = BT_DEVICE_DEVTYPE_BREDR;
static struct priority_property remote_setprop_tod_props[] = {
{
.prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
.prop.val = &remote_setprop_tod_val,
.prop.len = sizeof(remote_setprop_tod_val),
},
};
static const struct generic_data bt_dev_setprop_tod_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_tod_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static int32_t remote_setprop_rssi_val = -60;
static struct priority_property remote_setprop_rssi_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_RSSI,
.prop.val = &remote_setprop_rssi_val,
.prop.len = sizeof(remote_setprop_rssi_val),
},
};
static const struct generic_data bt_dev_setprop_rssi_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_rssi_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static int32_t remote_setprop_timestamp_val = 0xAB;
static struct priority_property remote_setprop_timestamp_props[] = {
{
.prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
.prop.val = (&remote_setprop_timestamp_val),
.prop.len = sizeof(remote_setprop_timestamp_val),
},
};
static const struct generic_data bt_dev_setprop_timpestamp_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_timestamp_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_bdaddr_t remote_setprop_bdaddr_val = {
.address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
};
static struct priority_property remote_setprop_bdaddr_props[] = {
{
.prop.type = BT_PROPERTY_BDADDR,
.prop.val = &remote_setprop_bdaddr_val,
.prop.len = sizeof(remote_setprop_bdaddr_val),
},
};
static const struct generic_data bt_dev_setprop_bdaddr_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_bdaddr_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_service_record_t remote_setprop_servrec_val = {
.uuid = { {0x00} },
.channel = 12,
.name = "bt_name",
};
static struct priority_property remote_setprop_servrec_props[] = {
{
.prop.type = BT_PROPERTY_SERVICE_RECORD,
.prop.val = &remote_setprop_servrec_val,
.prop.len = sizeof(remote_setprop_servrec_val),
},
};
static const struct generic_data bt_dev_setprop_servrec_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_servrec_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_scan_mode_t remote_setprop_scanmode_val = BT_SCAN_MODE_CONNECTABLE;
static struct priority_property remote_setprop_scanmode_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
.prop.val = &remote_setprop_scanmode_val,
.prop.len = sizeof(remote_setprop_scanmode_val),
},
};
static const struct generic_data bt_dev_setprop_scanmode_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_scanmode_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static bt_bdaddr_t remote_setprop_bondeddev_val = {
.address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
};
static struct priority_property remote_setprop_bondeddev_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
.prop.val = &remote_setprop_bondeddev_val,
.prop.len = sizeof(remote_setprop_bondeddev_val),
},
};
static const struct generic_data bt_dev_setprop_bondeddev_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_bondeddev_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static uint32_t remote_setprop_disctimeout_val = 120;
static struct priority_property remote_setprop_disctimeout_props[] = {
{
.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
.prop.val = &remote_setprop_disctimeout_val,
.prop.len = sizeof(remote_setprop_disctimeout_val),
},
};
static const struct generic_data bt_dev_setprop_disctimeout_fail_test = {
.expected_hal_cb.discovery_state_changed_cb =
remote_discovery_state_changed_cb,
.expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
.expected_cb_count = 3,
.expected_properties = remote_setprop_disctimeout_props,
.expected_adapter_status = BT_STATUS_FAIL,
};
static const struct generic_data bt_bond_create_pin_success_test = {
.expected_hal_cb.device_found_cb = bond_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_test_bonded_state_changed_cb,
.expected_hal_cb.pin_request_cb = bond_create_pin_success_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bt_bond_create_pin_fail_test = {
.expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_test_none_state_changed_cb,
.expected_hal_cb.pin_request_cb = bond_create_pin_fail_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = MGMT_STATUS_AUTH_FAILED,
};
static const struct generic_data bt_bond_create_ssp_success_test = {
.expected_hal_cb.device_found_cb = bond_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_test_bonded_state_changed_cb,
.expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bt_bond_create_ssp_fail_test = {
.expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_test_none_state_changed_cb,
.expected_hal_cb.ssp_request_cb = bond_create_ssp_fail_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = MGMT_STATUS_AUTH_FAILED,
};
static const struct generic_data bt_bond_create_no_disc_success_test = {
.expected_hal_cb.bond_state_changed_cb =
bond_test_bonded_state_changed_cb,
.expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
.expected_cb_count = 3,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bt_bond_create_bad_addr_success_test = {
.expected_adapter_status = MGMT_STATUS_CONNECT_FAILED,
};
static const struct generic_data bt_bond_cancel_success_test = {
.expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_test_none_state_changed_cb,
.expected_hal_cb.ssp_request_cb = bond_cancel_success_ssp_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static const struct generic_data bt_bond_remove_success_test = {
.expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
.expected_hal_cb.bond_state_changed_cb =
bond_remove_success_state_changed_cb,
.expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
.expected_cb_count = 4,
.expected_adapter_status = BT_STATUS_SUCCESS,
};
static bt_callbacks_t bt_callbacks = {
.size = sizeof(bt_callbacks),
.adapter_state_changed_cb = adapter_state_changed_cb,
.adapter_properties_cb = adapter_properties_cb,
.remote_device_properties_cb = remote_device_properties_cb,
.device_found_cb = device_found_cb,
.discovery_state_changed_cb = discovery_state_changed_cb,
.pin_request_cb = pin_request_cb,
.ssp_request_cb = ssp_request_cb,
.bond_state_changed_cb = bond_state_changed_cb,
.acl_state_changed_cb = NULL,
.thread_evt_cb = NULL,
.dut_mode_recv_cb = NULL,
.le_test_mode_cb = NULL
};
static bool setup(struct test_data *data)
{
const hw_module_t *module;
hw_device_t *device;
int signal_fd[2];
char buf[1024];
pid_t pid;
int len;
int err;
if (pipe(signal_fd))
return false;
pid = fork();
if (pid < 0) {
close(signal_fd[0]);
close(signal_fd[1]);
return false;
}
if (pid == 0) {
if (!tester_use_debug())
fclose(stderr);
close(signal_fd[0]);
emulator(signal_fd[1], data->mgmt_index);
exit(0);
}
close(signal_fd[1]);
data->bluetoothd_pid = pid;
len = read(signal_fd[0], buf, sizeof(buf));
if (len <= 0 || strcmp(buf, EMULATOR_SIGNAL)) {
close(signal_fd[0]);
return false;
}
close(signal_fd[0]);
err = hw_get_module(BT_HARDWARE_MODULE_ID, &module);
if (err)
return false;
err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
if (err)
return false;
data->device = device;
data->if_bluetooth = ((bluetooth_device_t *)
device)->get_bluetooth_interface();
if (!data->if_bluetooth)
return false;
return true;
}
static void setup_base(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t status;
if (!setup(data)) {
tester_setup_failed();
return;
}
status = data->if_bluetooth->init(&bt_callbacks);
if (status != BT_STATUS_SUCCESS) {
data->if_bluetooth = NULL;
tester_setup_failed();
return;
}
tester_setup_complete();
}
static void setup_enabled_adapter(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t status;
if (!setup(data)) {
tester_setup_failed();
return;
}
status = data->if_bluetooth->init(&bt_callbacks);
if (status != BT_STATUS_SUCCESS) {
data->if_bluetooth = NULL;
tester_setup_failed();
return;
}
status = data->if_bluetooth->enable();
if (status != BT_STATUS_SUCCESS)
tester_setup_failed();
}
static void teardown(const void *test_data)
{
struct test_data *data = tester_get_data();
if (data->if_hid) {
data->if_hid->cleanup();
data->if_hid = NULL;
}
if (data->if_bluetooth) {
data->if_bluetooth->cleanup();
data->if_bluetooth = NULL;
}
/* Test result already known, no need to check further */
data->test_checks_valid = false;
if (data->expected_properties_list)
g_slist_free(data->expected_properties_list);
data->device->close(data->device);
if (!data->bluetoothd_pid)
tester_teardown_complete();
}
static void test_dummy(const void *test_data)
{
tester_test_passed();
}
static void test_enable(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t adapter_status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
init_test_conditions(data);
bdaddr2android((const bdaddr_t *)bdaddr,
&enable_done_bdaddr_val.address);
adapter_status = data->if_bluetooth->enable();
check_expected_status(adapter_status);
}
static void test_enable_done(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t adapter_status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
init_test_conditions(data);
bdaddr2android((const bdaddr_t *)bdaddr,
&enable_done_bdaddr_val.address);
adapter_status = data->if_bluetooth->enable();
check_expected_status(adapter_status);
}
static void test_disable(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->disable();
check_expected_status(adapter_status);
}
static void test_setprop_bdname_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_bdname_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_scanmode_succes(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_scanmode_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_disctimeout_succes(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_disctimeout_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_getprop_bdaddr_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = setprop_bdaddr_props[0].prop;
bt_status_t adapter_status;
uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
init_test_conditions(data);
bdaddr2android((const bdaddr_t *)bdaddr,
&test_getprop_bdaddr_val.address);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_bdname_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(getprop_bdname_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
if (adapter_status != BT_STATUS_SUCCESS) {
tester_test_failed();
return;
}
adapter_status = data->if_bluetooth->get_adapter_property((*prop).type);
check_expected_status(adapter_status);
}
static void test_setprop_uuid_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_uuid_prop[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_cod_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_cod_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_tod_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const struct generic_data *test = data->test_data;
const bt_property_t *prop = &test->set_property;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_rssi_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_remote_rssi_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_service_record_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_service_record_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_bdaddr_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_bdaddr_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_scanmode_connectable_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop =
&(setprop_scanmode_connectable_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_setprop_bonded_devices_invalid(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_bonded_devices_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_getprop_cod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = setprop_cod_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_tod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = setprop_tod_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_scanmode_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = setprop_scanmode_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_disctimeout_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = setprop_disctimeout_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_uuids_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = getprop_uuids_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_getprop_bondeddev_success(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t prop = getprop_bondeddev_props[0].prop;
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
check_expected_status(adapter_status);
}
static void test_setprop_scanmode_none_done(const void *test_data)
{
struct test_data *data = tester_get_data();
const bt_property_t *prop = &(setprop_scanmode_none_props[0].prop);
bt_status_t adapter_status;
init_test_conditions(data);
adapter_status = data->if_bluetooth->set_adapter_property(prop);
check_expected_status(adapter_status);
}
static void test_discovery_start_success(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t status;
init_test_conditions(data);
status = data->if_bluetooth->start_discovery();
check_expected_status(status);
}
static void test_discovery_stop_done(const void *test_data)
{
struct test_data *data = tester_get_data();
bt_status_t status;
init_test_conditions(data);
status = data->if_bluetooth->cancel_discovery();
check_expected_status(status);
}
static void test_discovery_stop_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_discovery_start_done(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_discovery_device_found(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprops_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_bdname_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_uuids_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_cod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_tod_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_rssi_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_timestamp_success(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_bdaddr_fail(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_servrec_fail(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery();
}
static void test_dev_getprop_scanmode_fail(const void *test_data)
{
struct test_data *data = tester_get_data();
init_test_conditions(data);
data->if_bluetooth->start_discovery