2 * Copyright (C) 2013 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <sys/socket.h>
24 #include <sys/types.h>
27 #include <sys/signalfd.h>
30 #include "lib/bluetooth.h"
33 #include "src/shared/tester.h"
34 #include "src/shared/mgmt.h"
35 #include "src/shared/hciemu.h"
37 #include "emulator/bthost.h"
38 #include "monitor/bt.h"
40 #include <hardware/hardware.h>
41 #include <hardware/bluetooth.h>
42 #include <hardware/bt_sock.h>
43 #include <hardware/bt_hh.h>
47 struct priority_property {
53 int expected_adapter_status;
54 uint32_t expect_settings_set;
55 int expected_cb_count;
56 bt_property_t set_property;
57 bt_callbacks_t expected_hal_cb;
58 struct priority_property *expected_properties;
59 uint8_t expected_properties_num;
63 btsock_type_t sock_type;
64 const char *service_name;
65 const uint8_t *service_uuid;
66 const bt_bdaddr_t *bdaddr;
69 bt_status_t expected_status;
73 struct hidhost_generic_data {
74 bthh_status_t expected_status;
75 int expected_conn_state;
76 int expected_cb_count;
77 bthh_protocol_mode_t expected_protocol_mode;
79 bthh_callbacks_t expected_hal_cb;
80 int expected_report_size;
83 #define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
84 #define EMULATOR_SIGNAL "emulator_started"
86 #define BT_STATUS_NOT_EXPECTED -1
91 unsigned int mgmt_settings_id;
92 struct hciemu *hciemu;
93 enum hciemu_type hciemu_type;
94 const void *test_data;
98 struct hw_device_t *device;
99 const bt_interface_t *if_bluetooth;
100 const btsock_interface_t *if_sock;
101 const bthh_interface_t *if_hid;
105 /* Set to true if test conditions are initialized */
108 bool test_result_set;
111 GSList *expected_properties_list;
116 uint16_t ctrl_handle;
118 uint16_t intr_handle;
130 bt_ssp_variant_t ssp_variant;
134 bt_property_t *props;
140 bthh_status_t status;
141 bthh_hid_info_t hid_info;
142 bthh_protocol_mode_t mode;
143 bthh_connection_state_t state;
149 static char exec_dir[PATH_MAX + 1];
151 static gint scheduled_cbacks_num = 0;
153 static gboolean check_callbacks_called(gpointer user_data)
155 /* Wait for all callbacks scheduled in current test context to execute
156 * in main loop. This will avoid late callback calls after test case has
157 * already failed or timed out.
160 if (g_atomic_int_get(&scheduled_cbacks_num) == 0) {
161 tester_teardown_complete();
167 static void check_daemon_term(void)
171 struct test_data *data = tester_get_data();
176 pid = waitpid(data->bluetoothd_pid, &status, WNOHANG);
177 if (pid != data->bluetoothd_pid)
180 data->bluetoothd_pid = 0;
182 if (WIFEXITED(status) && (WEXITSTATUS(status) == EXIT_SUCCESS)) {
183 g_idle_add(check_callbacks_called, NULL);
187 tester_warn("Unexpected Daemon shutdown with status %d", status);
190 static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
193 struct signalfd_siginfo si;
197 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP))
200 fd = g_io_channel_unix_get_fd(channel);
202 result = read(fd, &si, sizeof(si));
203 if (result != sizeof(si))
206 switch (si.ssi_signo) {
215 static guint setup_signalfd(void)
223 sigaddset(&mask, SIGCHLD);
225 if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
228 fd = signalfd(-1, &mask, 0);
232 channel = g_io_channel_unix_new(fd);
234 g_io_channel_set_close_on_unref(channel, TRUE);
235 g_io_channel_set_encoding(channel, NULL, NULL);
236 g_io_channel_set_buffered(channel, FALSE);
238 source = g_io_add_watch(channel,
239 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
240 signal_handler, NULL);
242 g_io_channel_unref(channel);
247 static void mgmt_debug(const char *str, void *user_data)
249 const char *prefix = user_data;
251 tester_print("%s%s", prefix, str);
254 static void test_update_state(void)
256 struct test_data *data = tester_get_data();
258 if (data->conditions_left == 0 && !data->test_result_set) {
259 data->test_result_set = true;
260 tester_test_passed();
264 static void test_mgmt_settings_set(struct test_data *data)
266 data->conditions_left--;
271 static void command_generic_new_settings(uint16_t index, uint16_t length,
272 const void *param, void *user_data)
274 struct test_data *data = tester_get_data();
275 const struct generic_data *test_data = data->test_data;
279 tester_warn("Invalid parameter size for new settings event");
280 tester_test_failed();
284 settings = bt_get_le32(param);
286 if ((settings & test_data->expect_settings_set) !=
287 test_data->expect_settings_set)
290 test_mgmt_settings_set(data);
291 mgmt_unregister(data->mgmt, data->mgmt_settings_id);
294 static void check_cb_count(void)
296 struct test_data *data = tester_get_data();
298 if (!data->test_init_done)
301 if (data->cb_count == 0) {
302 data->conditions_left--;
307 static void expected_cb_count_init(struct test_data *data)
309 const struct generic_data *test_data = data->test_data;
311 data->cb_count = test_data->expected_cb_count;
316 static void mgmt_cb_init(struct test_data *data)
318 const struct generic_data *test_data = data->test_data;
320 if (!test_data->expect_settings_set)
321 test_mgmt_settings_set(data);
323 data->mgmt_settings_id = mgmt_register(data->mgmt,
324 MGMT_EV_NEW_SETTINGS, data->mgmt_index,
325 command_generic_new_settings, NULL, NULL);
328 static void expected_status_init(struct test_data *data)
330 const struct generic_data *test_data = data->test_data;
332 if (test_data->expected_adapter_status == BT_STATUS_NOT_EXPECTED)
333 data->conditions_left--;
336 static void test_property_init(struct test_data *data)
338 const struct generic_data *test_data = data->test_data;
339 GSList *l = data->expected_properties_list;
342 if (!test_data->expected_properties_num) {
343 data->conditions_left--;
347 for (i = 0; i < test_data->expected_properties_num; i++)
348 l = g_slist_prepend(l, &(test_data->expected_properties[i]));
350 data->expected_properties_list = l;
353 static void init_test_conditions(struct test_data *data)
355 data->test_init_done = true;
357 data->conditions_left = 4;
359 expected_cb_count_init(data);
361 expected_status_init(data);
362 test_property_init(data);
365 static void check_expected_status(uint8_t status)
367 struct test_data *data = tester_get_data();
368 const struct generic_data *test_data = data->test_data;
370 if (test_data->expected_adapter_status == status) {
371 data->conditions_left--;
374 tester_test_failed();
377 static int locate_property(gconstpointer expected_data,
378 gconstpointer received_prop)
380 bt_property_t rec_prop = *((bt_property_t *)received_prop);
381 bt_property_t exp_prop =
382 ((struct priority_property *)expected_data)->prop;
384 if (exp_prop.type && (exp_prop.type != rec_prop.type))
386 if (exp_prop.len && (exp_prop.len != rec_prop.len))
388 if (exp_prop.val && memcmp(exp_prop.val, rec_prop.val, exp_prop.len))
394 static int compare_priorities(gconstpointer prop_list, gconstpointer priority)
396 int prio = GPOINTER_TO_INT(priority);
397 int comp_prio = ((struct priority_property *)prop_list)->prio;
399 if (prio > comp_prio)
405 static bool check_prop_priority(int rec_prop_prio)
407 struct test_data *data = tester_get_data();
408 GSList *l = data->expected_properties_list;
410 if (!rec_prop_prio || !g_slist_length(l))
413 if (g_slist_find_custom(l, GINT_TO_POINTER(rec_prop_prio),
414 &compare_priorities))
420 static void check_expected_property(bt_property_t received_prop)
422 struct test_data *data = tester_get_data();
424 GSList *l = data->expected_properties_list;
425 GSList *found_exp_prop;
427 if (!g_slist_length(l))
430 found_exp_prop = g_slist_find_custom(l, &received_prop,
433 if (found_exp_prop) {
434 rec_prio = ((struct priority_property *)
435 (found_exp_prop->data))->prio;
436 if (check_prop_priority(rec_prio))
437 l = g_slist_remove(l, found_exp_prop->data);
440 data->expected_properties_list = l;
442 if (g_slist_length(l))
445 data->conditions_left--;
449 static bool check_test_property(bt_property_t received_prop,
450 bt_property_t expected_prop)
452 if (expected_prop.type && (expected_prop.type != received_prop.type))
454 if (expected_prop.len && (expected_prop.len != received_prop.len))
456 if (expected_prop.val && memcmp(expected_prop.val, received_prop.val,
463 static void read_info_callback(uint8_t status, uint16_t length,
464 const void *param, void *user_data)
466 struct test_data *data = tester_get_data();
467 const struct mgmt_rp_read_info *rp = param;
469 uint16_t manufacturer;
470 uint32_t supported_settings, current_settings;
472 tester_print("Read Info callback");
473 tester_print(" Status: 0x%02x", status);
475 if (status || !param) {
476 tester_pre_setup_failed();
480 ba2str(&rp->bdaddr, addr);
481 manufacturer = btohs(rp->manufacturer);
482 supported_settings = btohl(rp->supported_settings);
483 current_settings = btohl(rp->current_settings);
485 tester_print(" Address: %s", addr);
486 tester_print(" Version: 0x%02x", rp->version);
487 tester_print(" Manufacturer: 0x%04x", manufacturer);
488 tester_print(" Supported settings: 0x%08x", supported_settings);
489 tester_print(" Current settings: 0x%08x", current_settings);
490 tester_print(" Class: 0x%02x%02x%02x",
491 rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);
492 tester_print(" Name: %s", rp->name);
493 tester_print(" Short name: %s", rp->short_name);
495 if (strcmp(hciemu_get_address(data->hciemu), addr)) {
496 tester_pre_setup_failed();
500 tester_pre_setup_complete();
503 static void index_added_callback(uint16_t index, uint16_t length,
504 const void *param, void *user_data)
506 struct test_data *data = tester_get_data();
508 tester_print("Index Added callback");
509 tester_print(" Index: 0x%04x", index);
511 data->mgmt_index = index;
513 mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
514 read_info_callback, NULL, NULL);
517 static void index_removed_callback(uint16_t index, uint16_t length,
518 const void *param, void *user_data)
520 struct test_data *data = tester_get_data();
522 tester_print("Index Removed callback");
523 tester_print(" Index: 0x%04x", index);
525 if (index != data->mgmt_index)
528 mgmt_unregister_index(data->mgmt, data->mgmt_index);
530 mgmt_unref(data->mgmt);
533 tester_post_teardown_complete();
536 static void read_index_list_callback(uint8_t status, uint16_t length,
537 const void *param, void *user_data)
539 struct test_data *data = tester_get_data();
541 tester_print("Read Index List callback");
542 tester_print(" Status: 0x%02x", status);
544 if (status || !param) {
545 tester_pre_setup_failed();
549 mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE,
550 index_added_callback, NULL, NULL);
552 mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE,
553 index_removed_callback, NULL, NULL);
555 data->hciemu = hciemu_new(data->hciemu_type);
557 tester_warn("Failed to setup HCI emulation");
558 tester_pre_setup_failed();
562 tester_print("New hciemu instance created");
565 static void test_pre_setup(const void *test_data)
567 struct test_data *data = tester_get_data();
569 data->signalfd = setup_signalfd();
570 if (!data->signalfd) {
571 tester_warn("Failed to setup signalfd");
572 tester_pre_setup_failed();
576 data->mgmt = mgmt_new_default();
578 tester_warn("Failed to setup management interface");
579 tester_pre_setup_failed();
583 if (!tester_use_debug())
586 mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL);
588 mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0,
589 NULL, read_index_list_callback, NULL, NULL);
592 static void test_post_teardown(const void *test_data)
594 struct test_data *data = tester_get_data();
596 hciemu_unref(data->hciemu);
599 g_source_remove(data->signalfd);
603 static void bluetoothd_start(int hci_index)
605 char prg_name[PATH_MAX + 1];
609 snprintf(prg_name, sizeof(prg_name), "%s/%s", exec_dir, "bluetoothd");
610 snprintf(index, sizeof(index), "%d", hci_index);
612 prg_argv[0] = prg_name;
617 if (!tester_use_debug())
620 execve(prg_argv[0], prg_argv, NULL);
623 static void emulator(int pipe, int hci_index)
625 static const char SYSTEM_SOCKET_PATH[] = "\0android_system";
627 struct sockaddr_un addr;
632 fd = socket(PF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
636 tv.tv_sec = WAIT_FOR_SIGNAL_TIME;
638 setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
640 memset(&addr, 0, sizeof(addr));
641 addr.sun_family = AF_UNIX;
642 memcpy(addr.sun_path, SYSTEM_SOCKET_PATH, sizeof(SYSTEM_SOCKET_PATH));
644 if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
645 perror("Failed to bind system socket");
649 len = write(pipe, EMULATOR_SIGNAL, sizeof(EMULATOR_SIGNAL));
650 if (len != sizeof(EMULATOR_SIGNAL))
653 memset(buf, 0, sizeof(buf));
655 len = read(fd, buf, sizeof(buf));
656 if (len <= 0 || strcmp(buf, "bluetooth.start=daemon"))
661 return bluetoothd_start(hci_index);
670 static void emu_connectable_complete(uint16_t opcode, uint8_t status,
671 const void *param, uint8_t len,
675 case BT_HCI_CMD_WRITE_SCAN_ENABLE:
676 case BT_HCI_CMD_LE_SET_ADV_ENABLE:
682 tester_print("Emulated remote set connectable status 0x%02x", status);
685 tester_setup_failed();
687 tester_setup_complete();
690 static void setup_powered_emulated_remote(void)
692 struct test_data *data = tester_get_data();
693 struct bthost *bthost;
695 tester_print("Controller powered on");
697 bthost = hciemu_client_get_host(data->hciemu);
698 bthost_set_cmd_complete_cb(bthost, emu_connectable_complete, data);
700 if (data->hciemu_type == HCIEMU_TYPE_LE)
701 bthost_set_adv_enable(bthost, 0x01);
703 bthost_write_scan_enable(bthost, 0x03);
706 static void enable_success_cb(bt_state_t state)
708 struct test_data *data = tester_get_data();
710 if (state == BT_STATE_ON) {
711 setup_powered_emulated_remote();
717 static void disable_success_cb(bt_state_t state)
719 struct test_data *data = tester_get_data();
721 if (state == BT_STATE_OFF) {
727 static gboolean adapter_state_changed(gpointer user_data)
729 struct test_data *data = tester_get_data();
730 const struct generic_data *test = data->test_data;
731 struct bt_cb_data *cb_data = user_data;
733 if (data->test_init_done &&
734 test->expected_hal_cb.adapter_state_changed_cb) {
735 test->expected_hal_cb.adapter_state_changed_cb(cb_data->state);
739 if (!data->test_init_done && cb_data->state == BT_STATE_ON)
740 setup_powered_emulated_remote();
745 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
749 static void adapter_state_changed_cb(bt_state_t state)
751 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
753 cb_data->state = state;
755 g_atomic_int_inc(&scheduled_cbacks_num);
756 g_idle_add(adapter_state_changed, cb_data);
759 static void discovery_start_success_cb(bt_discovery_state_t state)
761 struct test_data *data = tester_get_data();
763 if (state == BT_DISCOVERY_STARTED) {
769 static void discovery_start_done_cb(bt_discovery_state_t state)
771 struct test_data *data = tester_get_data();
774 status = data->if_bluetooth->start_discovery();
778 check_expected_status(status);
781 static void discovery_stop_success_cb(bt_discovery_state_t state)
783 struct test_data *data = tester_get_data();
786 if (state == BT_DISCOVERY_STARTED && data->cb_count == 2) {
787 status = data->if_bluetooth->cancel_discovery();
788 check_expected_status(status);
792 if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
798 static void discovery_device_found_state_changed_cb(bt_discovery_state_t state)
800 struct test_data *data = tester_get_data();
802 if (state == BT_DISCOVERY_STARTED && data->cb_count == 3) {
806 if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
812 static void remote_discovery_state_changed_cb(bt_discovery_state_t state)
814 struct test_data *data = tester_get_data();
816 if (state == BT_DISCOVERY_STARTED && data->cb_count == 3) {
820 if (state == BT_DISCOVERY_STOPPED && data->cb_count == 1) {
826 static void remote_setprop_disc_state_changed_cb(bt_discovery_state_t state)
828 struct test_data *data = tester_get_data();
830 if (state == BT_DISCOVERY_STARTED && data->cb_count == 4) {
834 if (state == BT_DISCOVERY_STOPPED) {
840 static gboolean discovery_state_changed(gpointer user_data)
842 struct test_data *data = tester_get_data();
843 const struct generic_data *test = data->test_data;
844 struct bt_cb_data *cb_data = user_data;
846 if (test && test->expected_hal_cb.discovery_state_changed_cb)
847 test->expected_hal_cb.discovery_state_changed_cb(
852 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
856 static void discovery_state_changed_cb(bt_discovery_state_t state)
858 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
860 cb_data->state = state;
861 g_atomic_int_inc(&scheduled_cbacks_num);
862 g_idle_add(discovery_state_changed, cb_data);
865 static bt_property_t *copy_properties(int num_properties,
866 bt_property_t *properties)
869 bt_property_t *props = g_new0(bt_property_t, num_properties);
871 for (i = 0; i < num_properties; i++) {
872 props[i].type = properties[i].type;
873 props[i].len = properties[i].len;
874 props[i].val = g_memdup(properties[i].val, properties[i].len);
880 static void free_properties(int num_properties, bt_property_t *properties)
884 for (i = 0; i < num_properties; i++)
885 g_free(properties[i].val);
890 static void discovery_device_found_cb(int num_properties,
891 bt_property_t *properties)
893 struct test_data *data = tester_get_data();
894 uint8_t *remote_bdaddr =
895 (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
896 uint32_t emu_remote_type = BT_DEVICE_DEVTYPE_BREDR;
897 int32_t emu_remote_rssi = -60;
898 bt_bdaddr_t emu_remote_bdaddr;
900 bt_property_t expected_prop;
901 bt_property_t received_prop;
906 if (num_properties < 1) {
907 tester_test_failed();
911 bdaddr2android((const bdaddr_t *) remote_bdaddr, &emu_remote_bdaddr);
913 for (i = 0; i < num_properties; i++) {
914 received_prop = properties[i];
916 switch (properties[i].type) {
917 case BT_PROPERTY_BDADDR:
918 expected_prop.type = BT_PROPERTY_BDADDR;
919 expected_prop.len = sizeof(emu_remote_bdaddr);
920 expected_prop.val = &emu_remote_bdaddr;
923 case BT_PROPERTY_TYPE_OF_DEVICE:
924 expected_prop.type = BT_PROPERTY_TYPE_OF_DEVICE;
925 expected_prop.len = sizeof(emu_remote_type);
926 expected_prop.val = &emu_remote_type;
929 case BT_PROPERTY_REMOTE_RSSI:
930 expected_prop.type = BT_PROPERTY_REMOTE_RSSI;
931 expected_prop.len = sizeof(emu_remote_rssi);
932 expected_prop.val = &emu_remote_rssi;
936 expected_prop.type = 0;
937 expected_prop.len = 0;
938 expected_prop.val = NULL;
942 if (!check_test_property(received_prop, expected_prop)) {
943 tester_test_failed();
949 static void remote_getprops_device_found_cb(int num_properties,
950 bt_property_t *properties)
952 struct test_data *data = tester_get_data();
953 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
954 bt_bdaddr_t remote_addr;
956 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
958 if (data->cb_count == 2)
961 data->if_bluetooth->get_remote_device_properties(&remote_addr);
964 static void remote_get_property_device_found_cb(int num_properties,
965 bt_property_t *properties)
967 struct test_data *data = tester_get_data();
968 const struct generic_data *test = data->test_data;
970 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
971 bt_bdaddr_t remote_addr;
973 const bt_property_t prop = test->expected_properties[0].prop;
975 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
977 if (data->cb_count == 2)
980 status = data->if_bluetooth->get_remote_device_property(&remote_addr,
982 check_expected_status(status);
985 static void remote_setprop_device_found_cb(int num_properties,
986 bt_property_t *properties)
988 struct test_data *data = tester_get_data();
989 const struct generic_data *test = data->test_data;
991 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
992 bt_bdaddr_t remote_addr;
994 const bt_property_t prop = test->expected_properties[0].prop;
996 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
998 if (data->cb_count == 3)
1001 status = data->if_bluetooth->set_remote_device_property(&remote_addr,
1003 check_expected_status(status);
1006 static void remote_setprop_fail_device_found_cb(int num_properties,
1007 bt_property_t *properties)
1009 struct test_data *data = tester_get_data();
1010 const struct generic_data *test = data->test_data;
1012 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1013 bt_bdaddr_t remote_addr;
1015 const bt_property_t prop = test->expected_properties[0].prop;
1017 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1019 if (data->cb_count == 2)
1022 status = data->if_bluetooth->set_remote_device_property(&remote_addr,
1024 check_expected_status(status);
1027 static void bond_device_found_cb(int num_properties, bt_property_t *properties)
1029 struct test_data *data = tester_get_data();
1030 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1031 bt_bdaddr_t remote_addr;
1034 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1036 if (data->cb_count == 4) {
1038 status = data->if_bluetooth->create_bond(&remote_addr);
1039 check_expected_status(status);
1043 static void bond_nostatus_device_found_cb(int num_properties,
1044 bt_property_t *properties)
1046 struct test_data *data = tester_get_data();
1047 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1048 bt_bdaddr_t remote_addr;
1050 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1052 if (data->cb_count == 4) {
1054 data->if_bluetooth->create_bond(&remote_addr);
1058 static gboolean device_found(gpointer user_data)
1060 struct test_data *data = tester_get_data();
1061 const struct generic_data *test = data->test_data;
1062 struct bt_cb_data *cb_data = user_data;
1064 if (data->test_init_done && test->expected_hal_cb.device_found_cb)
1065 test->expected_hal_cb.device_found_cb(cb_data->num,
1068 free_properties(cb_data->num, cb_data->props);
1071 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
1075 static void device_found_cb(int num_properties, bt_property_t *properties)
1077 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1079 cb_data->num = num_properties;
1080 cb_data->props = copy_properties(num_properties, properties);
1082 g_atomic_int_inc(&scheduled_cbacks_num);
1083 g_idle_add(device_found, cb_data);
1086 static void check_count_properties_cb(bt_status_t status, int num_properties,
1087 bt_property_t *properties)
1091 for (i = 0; i < num_properties; i++)
1092 check_expected_property(properties[i]);
1095 static gboolean adapter_properties(gpointer user_data)
1097 struct test_data *data = tester_get_data();
1098 const struct generic_data *test = data->test_data;
1099 struct bt_cb_data *cb_data = user_data;
1101 if (data->test_init_done && test->expected_hal_cb.adapter_properties_cb)
1102 test->expected_hal_cb.adapter_properties_cb(cb_data->status,
1103 cb_data->num, cb_data->props);
1105 free_properties(cb_data->num, cb_data->props);
1108 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
1112 static void adapter_properties_cb(bt_status_t status, int num_properties,
1113 bt_property_t *properties)
1115 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1117 cb_data->status = status;
1118 cb_data->num = num_properties;
1119 cb_data->props = copy_properties(num_properties, properties);
1121 g_atomic_int_inc(&scheduled_cbacks_num);
1122 g_idle_add(adapter_properties, cb_data);
1125 static void remote_test_device_properties_cb(bt_status_t status,
1126 bt_bdaddr_t *bd_addr, int num_properties,
1127 bt_property_t *properties)
1131 for (i = 0; i < num_properties; i++)
1132 check_expected_property(properties[i]);
1135 static void remote_setprop_device_properties_cb(bt_status_t status,
1136 bt_bdaddr_t *bd_addr, int num_properties,
1137 bt_property_t *properties)
1140 struct test_data *data = tester_get_data();
1141 const struct generic_data *test = data->test_data;
1142 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1143 bt_bdaddr_t remote_addr;
1144 const bt_property_t prop = test->expected_properties[1].prop;
1146 for (i = 0; i < num_properties; i++)
1147 check_expected_property(properties[i]);
1149 if (g_slist_length(data->expected_properties_list) == 1) {
1150 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1153 data->if_bluetooth->get_remote_device_property(&remote_addr,
1158 static gboolean remote_device_properties(gpointer user_data)
1160 struct test_data *data = tester_get_data();
1161 const struct generic_data *test = data->test_data;
1162 struct bt_cb_data *cb_data = user_data;
1164 if (data->test_init_done &&
1165 test->expected_hal_cb.remote_device_properties_cb)
1166 test->expected_hal_cb.remote_device_properties_cb(
1167 cb_data->status, &cb_data->bdaddr,
1168 cb_data->num, cb_data->props);
1170 free_properties(cb_data->num, cb_data->props);
1173 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
1177 static void remote_device_properties_cb(bt_status_t status,
1178 bt_bdaddr_t *bd_addr, int num_properties,
1179 bt_property_t *properties)
1181 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1183 cb_data->status = status;
1184 cb_data->bdaddr = *bd_addr;
1185 cb_data->num = num_properties;
1186 cb_data->props = copy_properties(num_properties, properties);
1188 g_atomic_int_inc(&scheduled_cbacks_num);
1189 g_idle_add(remote_device_properties, cb_data);
1192 static void bond_test_bonded_state_changed_cb(bt_status_t status,
1193 bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
1195 struct test_data *data = tester_get_data();
1198 case BT_BOND_STATE_BONDING:
1201 case BT_BOND_STATE_BONDED:
1206 tester_test_failed();
1211 static void bond_test_none_state_changed_cb(bt_status_t status,
1212 bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
1214 struct test_data *data = tester_get_data();
1217 case BT_BOND_STATE_BONDING:
1220 case BT_BOND_STATE_NONE:
1225 tester_test_failed();
1230 static void bond_remove_success_state_changed_cb(bt_status_t status,
1231 bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
1233 struct test_data *data = tester_get_data();
1234 bt_status_t remove_status;
1235 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1236 bt_bdaddr_t remote_addr;
1238 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1240 if (state == BT_BOND_STATE_BONDED) {
1242 remove_status = data->if_bluetooth->remove_bond(&remote_addr);
1243 check_expected_status(remove_status);
1247 if (state == BT_BOND_STATE_NONE) {
1253 static gboolean bond_state_changed(gpointer user_data)
1255 struct test_data *data = tester_get_data();
1256 const struct generic_data *test = data->test_data;
1257 struct bt_cb_data *cb_data = user_data;
1259 if (data->test_init_done && test->expected_hal_cb.bond_state_changed_cb)
1260 test->expected_hal_cb.bond_state_changed_cb(cb_data->status,
1261 &cb_data->bdaddr, cb_data->state);
1267 static void bond_state_changed_cb(bt_status_t status,
1268 bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
1270 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1272 cb_data->status = status;
1273 cb_data->bdaddr = *remote_bd_addr;
1274 cb_data->state = state;
1276 g_idle_add(bond_state_changed, cb_data);
1279 static void bond_create_pin_success_request_cb(bt_bdaddr_t *remote_bd_addr,
1280 bt_bdname_t *bd_name, uint32_t cod)
1282 struct test_data *data = tester_get_data();
1283 const bt_bdaddr_t *bdaddr = remote_bd_addr;
1284 bt_pin_code_t pin_code = {
1285 .pin = { 0x30, 0x30, 0x30, 0x30 },
1287 uint8_t pin_len = 4;
1291 data->if_bluetooth->pin_reply(bdaddr, TRUE, pin_len, &pin_code);
1294 static void bond_create_pin_fail_request_cb(bt_bdaddr_t *remote_bd_addr,
1295 bt_bdname_t *bd_name, uint32_t cod)
1297 struct test_data *data = tester_get_data();
1298 const bt_bdaddr_t *bdaddr = remote_bd_addr;
1299 bt_pin_code_t pin_code = {
1300 .pin = { 0x31, 0x31, 0x31, 0x31 },
1302 uint8_t pin_len = 4;
1306 data->if_bluetooth->pin_reply(bdaddr, TRUE, pin_len, &pin_code);
1309 static gboolean pin_request(gpointer user_data)
1311 struct test_data *data = tester_get_data();
1312 const struct generic_data *test = data->test_data;
1313 struct bt_cb_data *cb_data = user_data;
1315 if (data->test_init_done && test->expected_hal_cb.pin_request_cb)
1316 test->expected_hal_cb.pin_request_cb(&cb_data->bdaddr,
1317 &cb_data->bdname, cb_data->cod);
1323 static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
1324 bt_bdname_t *bd_name, uint32_t cod)
1326 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1328 cb_data->bdaddr = *remote_bd_addr;
1329 cb_data->bdname = *bd_name;
1332 g_idle_add(pin_request, cb_data);
1335 static void bond_create_ssp_request_cb(const bt_bdaddr_t *remote_bd_addr,
1336 bt_ssp_variant_t pairing_variant,
1337 bool accept, uint32_t pass_key)
1339 struct test_data *data = tester_get_data();
1341 data->if_bluetooth->ssp_reply(remote_bd_addr,
1342 BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
1348 static void bond_create_ssp_success_request_cb(bt_bdaddr_t *remote_bd_addr,
1349 bt_bdname_t *bd_name, uint32_t cod,
1350 bt_ssp_variant_t pairing_variant,
1355 bond_create_ssp_request_cb(remote_bd_addr, pairing_variant, accept,
1359 static void bond_create_ssp_fail_request_cb(bt_bdaddr_t *remote_bd_addr,
1360 bt_bdname_t *bd_name, uint32_t cod,
1361 bt_ssp_variant_t pairing_variant,
1364 bool accept = false;
1366 bond_create_ssp_request_cb(remote_bd_addr, pairing_variant, accept,
1370 static void bond_cancel_success_ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
1371 bt_bdname_t *bd_name, uint32_t cod,
1372 bt_ssp_variant_t pairing_variant,
1375 struct test_data *data = tester_get_data();
1376 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
1377 bt_bdaddr_t remote_addr;
1380 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
1384 status = data->if_bluetooth->cancel_bond(&remote_addr);
1385 check_expected_status(status);
1388 static gboolean ssp_request(gpointer user_data)
1390 struct test_data *data = tester_get_data();
1391 const struct generic_data *test = data->test_data;
1392 struct bt_cb_data *cb_data = user_data;
1394 if (data->test_init_done &&
1395 test->expected_hal_cb.ssp_request_cb)
1396 test->expected_hal_cb.ssp_request_cb(&cb_data->bdaddr,
1397 &cb_data->bdname, cb_data->cod,
1398 cb_data->ssp_variant, cb_data->passkey);
1404 static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
1405 uint32_t cod, bt_ssp_variant_t pairing_variant,
1408 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
1410 cb_data->bdaddr = *remote_bd_addr;
1411 cb_data->bdname = *bd_name;
1413 cb_data->ssp_variant = pairing_variant;
1414 cb_data->passkey = pass_key;
1416 g_idle_add(ssp_request, cb_data);
1419 static bt_bdaddr_t enable_done_bdaddr_val = { {0x00} };
1420 static const char enable_done_bdname_val[] = "BlueZ for Android";
1421 static bt_uuid_t enable_done_uuids_val = {
1422 .uu = { 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
1423 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb},
1425 static bt_device_type_t enable_done_tod_val = BT_DEVICE_DEVTYPE_BREDR;
1426 static bt_scan_mode_t enable_done_scanmode_val = BT_SCAN_MODE_NONE;
1427 static uint32_t enable_done_disctimeout_val = 120;
1429 static struct priority_property enable_done_props[] = {
1431 .prop.type = BT_PROPERTY_BDADDR,
1432 .prop.len = sizeof(enable_done_bdaddr_val),
1433 .prop.val = &enable_done_bdaddr_val,
1437 .prop.type = BT_PROPERTY_BDNAME,
1438 .prop.len = sizeof(enable_done_bdname_val) - 1,
1439 .prop.val = &enable_done_bdname_val,
1443 .prop.type = BT_PROPERTY_UUIDS,
1444 .prop.len = sizeof(enable_done_uuids_val),
1445 .prop.val = &enable_done_uuids_val,
1449 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
1450 .prop.len = sizeof(uint32_t),
1455 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
1456 .prop.len = sizeof(enable_done_tod_val),
1457 .prop.val = &enable_done_tod_val,
1461 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
1462 .prop.len = sizeof(enable_done_scanmode_val),
1463 .prop.val = &enable_done_scanmode_val,
1467 .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
1473 .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
1474 .prop.len = sizeof(enable_done_disctimeout_val),
1475 .prop.val = &enable_done_disctimeout_val,
1480 static const struct generic_data bluetooth_enable_success_test = {
1481 .expected_hal_cb.adapter_state_changed_cb = enable_success_cb,
1482 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1483 .expected_cb_count = 1,
1484 .expected_properties_num = 8,
1485 .expected_properties = enable_done_props,
1486 .expected_adapter_status = BT_STATUS_SUCCESS,
1489 static const struct generic_data bluetooth_enable_success2_test = {
1490 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1491 .expected_adapter_status = BT_STATUS_SUCCESS,
1492 .expected_properties_num = 8,
1493 .expected_properties = enable_done_props,
1496 static const struct generic_data bluetooth_disable_success_test = {
1497 .expected_hal_cb.adapter_state_changed_cb = disable_success_cb,
1498 .expected_cb_count = 1,
1499 .expected_adapter_status = BT_STATUS_SUCCESS,
1502 static char test_set_bdname[] = "test_bdname_set";
1504 static struct priority_property setprop_bdname_props[] = {
1506 .prop.type = BT_PROPERTY_BDNAME,
1507 .prop.val = test_set_bdname,
1508 .prop.len = sizeof(test_set_bdname) - 1,
1513 static const struct generic_data bluetooth_setprop_bdname_success_test = {
1514 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1515 .expected_properties_num = 1,
1516 .expected_properties = setprop_bdname_props,
1519 static bt_scan_mode_t test_setprop_scanmode_val =
1520 BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE;
1522 static struct priority_property setprop_scanmode_props[] = {
1524 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
1525 .prop.val = &test_setprop_scanmode_val,
1526 .prop.len = sizeof(bt_scan_mode_t),
1530 static const struct generic_data bluetooth_setprop_scanmode_success_test = {
1531 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1532 .expected_properties_num = 1,
1533 .expected_properties = setprop_scanmode_props,
1534 .expected_adapter_status = BT_STATUS_SUCCESS,
1537 static uint32_t test_setprop_disctimeout_val = 120;
1539 static struct priority_property setprop_disctimeout_props[] = {
1541 .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
1542 .prop.val = &test_setprop_disctimeout_val,
1543 .prop.len = sizeof(test_setprop_disctimeout_val),
1547 static const struct generic_data bluetooth_setprop_disctimeout_success_test = {
1548 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1549 .expected_properties_num = 1,
1550 .expected_properties = setprop_disctimeout_props,
1551 .expected_adapter_status = BT_STATUS_SUCCESS,
1554 static bt_bdaddr_t test_getprop_bdaddr_val = { {0x00} };
1556 static struct priority_property getprop_bdaddr_props[] = {
1558 .prop.type = BT_PROPERTY_BDADDR,
1559 .prop.val = &test_getprop_bdaddr_val,
1560 .prop.len = sizeof(test_getprop_bdaddr_val),
1564 static const struct generic_data bluetooth_getprop_bdaddr_success_test = {
1565 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1566 .expected_properties_num = 1,
1567 .expected_properties = getprop_bdaddr_props,
1568 .expected_adapter_status = BT_STATUS_SUCCESS,
1571 static const char test_bdname[] = "test_bdname_setget";
1573 static struct priority_property getprop_bdname_props[] = {
1575 .prop.type = BT_PROPERTY_BDNAME,
1576 .prop.val = &test_bdname,
1577 .prop.len = sizeof(test_bdname) - 1,
1581 static const struct generic_data bluetooth_getprop_bdname_success_test = {
1582 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1583 .expected_properties_num = 1,
1584 .expected_properties = getprop_bdname_props,
1585 .expected_adapter_status = BT_STATUS_SUCCESS,
1588 static unsigned char setprop_uuids[] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00,
1589 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
1592 static struct priority_property setprop_uuid_prop[] = {
1594 .prop.type = BT_PROPERTY_UUIDS,
1595 .prop.val = &setprop_uuids,
1596 .prop.len = sizeof(setprop_uuids),
1600 static const struct generic_data bluetooth_setprop_uuid_invalid_test = {
1601 .expected_adapter_status = BT_STATUS_FAIL,
1604 static uint32_t setprop_class_of_device = 0;
1606 static struct priority_property setprop_cod_props[] = {
1608 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
1609 .prop.val = &setprop_class_of_device,
1610 .prop.len = sizeof(setprop_class_of_device),
1614 static const struct generic_data bluetooth_setprop_cod_invalid_test = {
1615 .expected_adapter_status = BT_STATUS_FAIL,
1618 static bt_device_type_t setprop_type_of_device = BT_DEVICE_DEVTYPE_BREDR;
1620 static struct priority_property setprop_tod_props[] = {
1622 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
1623 .prop.val = &setprop_type_of_device,
1624 .prop.len = sizeof(setprop_type_of_device),
1628 static const struct generic_data bluetooth_setprop_tod_invalid_test = {
1629 .expected_adapter_status = BT_STATUS_FAIL,
1632 static int32_t setprop_remote_rssi = 0;
1634 static struct priority_property setprop_remote_rssi_props[] = {
1636 .prop.type = BT_PROPERTY_REMOTE_RSSI,
1637 .prop.val = &setprop_remote_rssi,
1638 .prop.len = sizeof(setprop_remote_rssi),
1642 static const struct generic_data bluetooth_setprop_remote_rssi_invalid_test = {
1643 .expected_adapter_status = BT_STATUS_FAIL,
1646 static bt_service_record_t setprop_remote_service = {
1652 static struct priority_property setprop_service_record_props[] = {
1654 .prop.type = BT_PROPERTY_SERVICE_RECORD,
1655 .prop.val = &setprop_remote_service,
1656 .prop.len = sizeof(setprop_remote_service),
1660 static const struct generic_data
1661 bluetooth_setprop_service_record_invalid_test = {
1662 .expected_adapter_status = BT_STATUS_FAIL,
1665 static bt_bdaddr_t setprop_bdaddr = {
1666 .address = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1669 static struct priority_property setprop_bdaddr_props[] = {
1671 .prop.type = BT_PROPERTY_BDADDR,
1672 .prop.val = &setprop_bdaddr,
1673 .prop.len = sizeof(setprop_bdaddr),
1677 static const struct generic_data bluetooth_setprop_bdaddr_invalid_test = {
1678 .expected_adapter_status = BT_STATUS_FAIL,
1681 static bt_scan_mode_t setprop_scanmode_connectable = BT_SCAN_MODE_CONNECTABLE;
1683 static struct priority_property setprop_scanmode_connectable_props[] = {
1685 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
1686 .prop.val = &setprop_scanmode_connectable,
1687 .prop.len = sizeof(setprop_scanmode_connectable),
1691 static const struct generic_data
1692 bluetooth_setprop_scanmode_connectable_success_test = {
1693 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1694 .expected_properties_num = 1,
1695 .expected_properties = setprop_scanmode_connectable_props,
1696 .expected_adapter_status = BT_STATUS_SUCCESS,
1699 static bt_bdaddr_t setprop_bonded_devices = {
1700 .address = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 },
1703 static struct priority_property setprop_bonded_devices_props[] = {
1705 .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
1706 .prop.val = &setprop_bonded_devices,
1707 .prop.len = sizeof(setprop_bonded_devices),
1711 static const struct generic_data
1712 bluetooth_setprop_bonded_devices_invalid_test = {
1713 .expected_adapter_status = BT_STATUS_FAIL,
1716 static uint32_t getprop_cod = 0x00020c;
1718 static struct priority_property getprop_cod_props[] = {
1720 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
1721 .prop.val = &getprop_cod,
1722 .prop.len = sizeof(getprop_cod),
1726 static const struct generic_data bluetooth_getprop_cod_success_test = {
1727 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1728 .expected_properties_num = 1,
1729 .expected_properties = getprop_cod_props,
1730 .expected_adapter_status = BT_STATUS_SUCCESS,
1733 static bt_device_type_t getprop_tod = BT_DEVICE_DEVTYPE_BREDR;
1735 static struct priority_property getprop_tod_props[] = {
1737 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
1738 .prop.val = &getprop_tod,
1739 .prop.len = sizeof(getprop_tod),
1743 static const struct generic_data bluetooth_getprop_tod_success_test = {
1744 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1745 .expected_properties_num = 1,
1746 .expected_properties = getprop_tod_props,
1747 .expected_adapter_status = BT_STATUS_SUCCESS,
1750 static bt_scan_mode_t getprop_scanmode = BT_SCAN_MODE_NONE;
1752 static struct priority_property getprop_scanmode_props[] = {
1754 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
1755 .prop.val = &getprop_scanmode,
1756 .prop.len = sizeof(getprop_scanmode),
1760 static const struct generic_data bluetooth_getprop_scanmode_success_test = {
1761 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1762 .expected_properties_num = 1,
1763 .expected_properties = getprop_scanmode_props,
1764 .expected_adapter_status = BT_STATUS_SUCCESS,
1767 static uint32_t getprop_disctimeout_val = 120;
1769 static struct priority_property getprop_disctimeout_props[] = {
1771 .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
1772 .prop.val = &getprop_disctimeout_val,
1773 .prop.len = sizeof(getprop_disctimeout_val),
1777 static const struct generic_data bluetooth_getprop_disctimeout_success_test = {
1778 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1779 .expected_properties_num = 1,
1780 .expected_properties = getprop_disctimeout_props,
1781 .expected_adapter_status = BT_STATUS_SUCCESS,
1784 static bt_uuid_t getprop_uuids = {
1785 .uu = { 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00,
1786 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB },
1789 static struct priority_property getprop_uuids_props[] = {
1791 .prop.type = BT_PROPERTY_UUIDS,
1792 .prop.val = &getprop_uuids,
1793 .prop.len = sizeof(getprop_uuids),
1797 static const struct generic_data bluetooth_getprop_uuids_success_test = {
1798 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1799 .expected_properties_num = 1,
1800 .expected_properties = getprop_uuids_props,
1801 .expected_adapter_status = BT_STATUS_SUCCESS,
1804 static struct priority_property getprop_bondeddev_props[] = {
1806 .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
1812 static const struct generic_data bluetooth_getprop_bondeddev_success_test = {
1813 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1814 .expected_properties_num = 1,
1815 .expected_properties = getprop_bondeddev_props,
1816 .expected_adapter_status = BT_STATUS_SUCCESS,
1819 static bt_scan_mode_t setprop_scanmode_none = BT_SCAN_MODE_NONE;
1821 static struct priority_property setprop_scanmode_none_props[] = {
1823 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
1824 .prop.val = &setprop_scanmode_none,
1825 .prop.len = sizeof(setprop_scanmode_none),
1829 static const struct generic_data
1830 bluetooth_setprop_scanmode_none_success2_test = {
1831 .expected_hal_cb.adapter_properties_cb = check_count_properties_cb,
1832 .expected_properties_num = 1,
1833 .expected_properties = setprop_scanmode_none_props,
1834 .expected_adapter_status = BT_STATUS_SUCCESS,
1837 static const struct generic_data bluetooth_discovery_start_success_test = {
1838 .expected_hal_cb.discovery_state_changed_cb =
1839 discovery_start_success_cb,
1840 .expected_cb_count = 1,
1841 .expected_adapter_status = BT_STATUS_SUCCESS,
1844 static const struct generic_data bluetooth_discovery_start_success2_test = {
1845 .expected_hal_cb.discovery_state_changed_cb = discovery_start_done_cb,
1846 .expected_cb_count = 1,
1847 .expected_adapter_status = BT_STATUS_SUCCESS,
1850 static const struct generic_data bluetooth_discovery_stop_success2_test = {
1851 .expected_adapter_status = BT_STATUS_SUCCESS,
1854 static const struct generic_data bluetooth_discovery_stop_success_test = {
1855 .expected_hal_cb.discovery_state_changed_cb = discovery_stop_success_cb,
1856 .expected_cb_count = 2,
1857 .expected_adapter_status = BT_STATUS_SUCCESS,
1860 static const struct generic_data bluetooth_discovery_device_found_test = {
1861 .expected_hal_cb.discovery_state_changed_cb =
1862 discovery_device_found_state_changed_cb,
1863 .expected_hal_cb.device_found_cb = discovery_device_found_cb,
1864 .expected_cb_count = 3,
1865 .expected_adapter_status = BT_STATUS_NOT_EXPECTED,
1868 static const char remote_get_properties_bdname_val[] = "00:AA:01:01:00:00";
1869 static uint32_t remote_get_properties_cod_val = 0;
1870 static bt_device_type_t remote_get_properties_tod_val = BT_DEVICE_DEVTYPE_BREDR;
1871 static int32_t remote_get_properties_rssi_val = -60;
1873 static struct priority_property remote_getprops_props[] = {
1875 .prop.type = BT_PROPERTY_BDNAME,
1876 .prop.val = &remote_get_properties_bdname_val,
1877 .prop.len = sizeof(remote_get_properties_bdname_val) - 1,
1881 .prop.type = BT_PROPERTY_UUIDS,
1887 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
1888 .prop.val = &remote_get_properties_cod_val,
1889 .prop.len = sizeof(remote_get_properties_cod_val),
1893 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
1894 .prop.val = &remote_get_properties_tod_val,
1895 .prop.len = sizeof(remote_get_properties_tod_val),
1899 .prop.type = BT_PROPERTY_REMOTE_RSSI,
1900 .prop.val = &remote_get_properties_rssi_val,
1901 .prop.len = sizeof(remote_get_properties_rssi_val),
1905 .prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
1912 static const struct generic_data bt_dev_getprops_success_test = {
1913 .expected_hal_cb.discovery_state_changed_cb =
1914 remote_discovery_state_changed_cb,
1915 .expected_hal_cb.device_found_cb = remote_getprops_device_found_cb,
1916 .expected_hal_cb.remote_device_properties_cb =
1917 remote_test_device_properties_cb,
1918 .expected_cb_count = 3,
1919 .expected_properties_num = 6,
1920 .expected_properties = remote_getprops_props,
1921 .expected_adapter_status = BT_STATUS_NOT_EXPECTED,
1924 static const char remote_getprop_bdname_val[] = "00:AA:01:01:00:00";
1926 static struct priority_property remote_getprop_bdname_props[] = {
1928 .prop.type = BT_PROPERTY_BDNAME,
1929 .prop.val = &remote_getprop_bdname_val,
1930 .prop.len = sizeof(remote_getprop_bdname_val) - 1,
1934 static const struct generic_data bt_dev_getprop_bdname_success_test = {
1935 .expected_hal_cb.discovery_state_changed_cb =
1936 remote_discovery_state_changed_cb,
1937 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
1938 .expected_hal_cb.remote_device_properties_cb =
1939 remote_test_device_properties_cb,
1940 .expected_cb_count = 3,
1941 .expected_properties_num = 1,
1942 .expected_properties = remote_getprop_bdname_props,
1943 .expected_adapter_status = BT_STATUS_SUCCESS,
1946 static struct priority_property remote_getprop_uuids_props[] = {
1948 .prop.type = BT_PROPERTY_UUIDS,
1954 static const struct generic_data bt_dev_getprop_uuids_success_test = {
1955 .expected_hal_cb.discovery_state_changed_cb =
1956 remote_discovery_state_changed_cb,
1957 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
1958 .expected_hal_cb.remote_device_properties_cb =
1959 remote_test_device_properties_cb,
1960 .expected_cb_count = 3,
1961 .expected_properties_num = 1,
1962 .expected_properties = remote_getprop_uuids_props,
1963 .expected_adapter_status = BT_STATUS_SUCCESS,
1966 static uint32_t remote_getprop_cod_val = 0;
1968 static struct priority_property remote_getprop_cod_props[] = {
1970 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
1971 .prop.val = &remote_getprop_cod_val,
1972 .prop.len = sizeof(remote_getprop_cod_val),
1976 static const struct generic_data bt_dev_getprop_cod_success_test = {
1977 .expected_hal_cb.discovery_state_changed_cb =
1978 remote_discovery_state_changed_cb,
1979 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
1980 .expected_hal_cb.remote_device_properties_cb =
1981 remote_test_device_properties_cb,
1982 .expected_cb_count = 3,
1983 .expected_properties_num = 1,
1984 .expected_properties = remote_getprop_cod_props,
1985 .expected_adapter_status = BT_STATUS_SUCCESS,
1988 static bt_device_type_t remote_getprop_tod_val = BT_DEVICE_DEVTYPE_BREDR;
1990 static struct priority_property remote_getprop_tod_props[] = {
1992 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
1993 .prop.val = &remote_getprop_tod_val,
1994 .prop.len = sizeof(remote_getprop_tod_val),
1998 static const struct generic_data bt_dev_getprop_tod_success_test = {
1999 .expected_hal_cb.discovery_state_changed_cb =
2000 remote_discovery_state_changed_cb,
2001 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2002 .expected_hal_cb.remote_device_properties_cb =
2003 remote_test_device_properties_cb,
2004 .expected_cb_count = 3,
2005 .expected_properties_num = 1,
2006 .expected_properties = remote_getprop_tod_props,
2007 .expected_adapter_status = BT_STATUS_SUCCESS,
2010 static int32_t remote_getprop_rssi_val = -60;
2012 static struct priority_property remote_getprop_rssi_props[] = {
2014 .prop.type = BT_PROPERTY_REMOTE_RSSI,
2015 .prop.val = &remote_getprop_rssi_val,
2016 .prop.len = sizeof(remote_getprop_rssi_val),
2020 static const struct generic_data bt_dev_getprop_rssi_success_test = {
2021 .expected_hal_cb.discovery_state_changed_cb =
2022 remote_discovery_state_changed_cb,
2023 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2024 .expected_hal_cb.remote_device_properties_cb =
2025 remote_test_device_properties_cb,
2026 .expected_cb_count = 3,
2027 .expected_properties_num = 1,
2028 .expected_properties = remote_getprop_rssi_props,
2029 .expected_adapter_status = BT_STATUS_SUCCESS,
2032 static struct priority_property remote_getprop_timestamp_props[] = {
2034 .prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
2040 static const struct generic_data bt_dev_getprop_timpestamp_success_test = {
2041 .expected_hal_cb.discovery_state_changed_cb =
2042 remote_discovery_state_changed_cb,
2043 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2044 .expected_hal_cb.remote_device_properties_cb =
2045 remote_test_device_properties_cb,
2046 .expected_cb_count = 3,
2047 .expected_properties_num = 1,
2048 .expected_properties = remote_getprop_timestamp_props,
2049 .expected_adapter_status = BT_STATUS_SUCCESS,
2052 static bt_bdaddr_t remote_getprop_bdaddr_val = {
2053 .address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
2056 static struct priority_property remote_getprop_bdaddr_props[] = {
2058 .prop.type = BT_PROPERTY_BDADDR,
2059 .prop.val = &remote_getprop_bdaddr_val,
2060 .prop.len = sizeof(remote_getprop_bdaddr_val),
2064 static const struct generic_data bt_dev_getprop_bdaddr_fail_test = {
2065 .expected_hal_cb.discovery_state_changed_cb =
2066 remote_discovery_state_changed_cb,
2067 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2068 .expected_hal_cb.remote_device_properties_cb =
2069 remote_test_device_properties_cb,
2070 .expected_cb_count = 3,
2071 .expected_properties = remote_getprop_bdaddr_props,
2072 .expected_adapter_status = BT_STATUS_FAIL,
2075 static bt_service_record_t remote_getprop_servrec_val = {
2081 static struct priority_property remote_getprop_servrec_props[] = {
2083 .prop.type = BT_PROPERTY_SERVICE_RECORD,
2084 .prop.val = &remote_getprop_servrec_val,
2085 .prop.len = sizeof(remote_getprop_servrec_val),
2089 static const struct generic_data bt_dev_getprop_servrec_fail_test = {
2090 .expected_hal_cb.discovery_state_changed_cb =
2091 remote_discovery_state_changed_cb,
2092 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2093 .expected_hal_cb.remote_device_properties_cb =
2094 remote_test_device_properties_cb,
2095 .expected_cb_count = 3,
2096 .expected_properties = remote_getprop_servrec_props,
2097 .expected_adapter_status = BT_STATUS_FAIL,
2100 static bt_scan_mode_t remote_getprop_scanmode_val = BT_SCAN_MODE_CONNECTABLE;
2102 static struct priority_property remote_getprop_scanmode_props[] = {
2104 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
2105 .prop.val = &remote_getprop_scanmode_val,
2106 .prop.len = sizeof(remote_getprop_scanmode_val),
2110 static const struct generic_data bt_dev_getprop_scanmode_fail_test = {
2111 .expected_hal_cb.discovery_state_changed_cb =
2112 remote_discovery_state_changed_cb,
2113 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2114 .expected_hal_cb.remote_device_properties_cb =
2115 remote_test_device_properties_cb,
2116 .expected_cb_count = 3,
2117 .expected_properties = remote_getprop_scanmode_props,
2118 .expected_adapter_status = BT_STATUS_FAIL,
2121 static struct priority_property remote_getprop_bondeddev_props[] = {
2123 .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
2129 static const struct generic_data bt_dev_getprop_bondeddev_fail_test = {
2130 .expected_hal_cb.discovery_state_changed_cb =
2131 remote_discovery_state_changed_cb,
2132 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2133 .expected_hal_cb.remote_device_properties_cb =
2134 remote_test_device_properties_cb,
2135 .expected_cb_count = 3,
2136 .expected_properties = remote_getprop_bondeddev_props,
2137 .expected_adapter_status = BT_STATUS_FAIL,
2140 static uint32_t remote_getprop_disctimeout_val = 120;
2142 static struct priority_property remote_getprop_disctimeout_props[] = {
2144 .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
2145 .prop.val = &remote_getprop_disctimeout_val,
2146 .prop.len = sizeof(remote_getprop_disctimeout_val),
2150 static const struct generic_data bt_dev_getprop_disctimeout_fail_test = {
2151 .expected_hal_cb.discovery_state_changed_cb =
2152 remote_discovery_state_changed_cb,
2153 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2154 .expected_hal_cb.remote_device_properties_cb =
2155 remote_test_device_properties_cb,
2156 .expected_cb_count = 3,
2157 .expected_properties = remote_getprop_disctimeout_props,
2158 .expected_adapter_status = BT_STATUS_FAIL,
2161 static struct priority_property remote_getprop_verinfo_props[] = {
2163 .prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
2169 static const struct generic_data bt_dev_getprop_verinfo_fail_test = {
2170 .expected_hal_cb.discovery_state_changed_cb =
2171 remote_discovery_state_changed_cb,
2172 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2173 .expected_hal_cb.remote_device_properties_cb =
2174 remote_test_device_properties_cb,
2175 .expected_cb_count = 3,
2176 .expected_properties = remote_getprop_verinfo_props,
2177 .expected_adapter_status = BT_STATUS_FAIL,
2180 static struct priority_property remote_getprop_fname_props[] = {
2182 .prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
2188 static const struct generic_data bt_dev_getprop_fname_fail_test = {
2189 .expected_hal_cb.discovery_state_changed_cb =
2190 remote_discovery_state_changed_cb,
2191 .expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
2192 .expected_hal_cb.remote_device_properties_cb =
2193 remote_test_device_properties_cb,
2194 .expected_cb_count = 3,
2195 .expected_properties = remote_getprop_fname_props,
2196 .expected_adapter_status = BT_STATUS_FAIL,
2199 static const char remote_setprop_fname_val[] = "set_fname_test";
2201 static struct priority_property remote_setprop_fname_props[] = {
2203 .prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME,
2204 .prop.val = &remote_setprop_fname_val,
2205 .prop.len = sizeof(remote_setprop_fname_val) - 1,
2208 .prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME,
2209 .prop.val = &remote_setprop_fname_val,
2210 .prop.len = sizeof(remote_setprop_fname_val) - 1,
2214 static const struct generic_data bt_dev_setprop_fname_success_test = {
2215 .expected_hal_cb.discovery_state_changed_cb =
2216 remote_setprop_disc_state_changed_cb,
2217 .expected_hal_cb.device_found_cb = remote_setprop_device_found_cb,
2218 .expected_hal_cb.remote_device_properties_cb =
2219 remote_setprop_device_properties_cb,
2220 .expected_cb_count = 4,
2221 .expected_properties_num = 2,
2222 .expected_properties = remote_setprop_fname_props,
2223 .expected_adapter_status = BT_STATUS_SUCCESS,
2226 static const char remote_setprop_bdname_val[] = "setprop_bdname_fail";
2228 static struct priority_property remote_setprop_bdname_props[] = {
2230 .prop.type = BT_PROPERTY_BDNAME,
2231 .prop.val = &remote_setprop_bdname_val,
2232 .prop.len = sizeof(remote_setprop_bdname_val) - 1,
2236 static const struct generic_data bt_dev_setprop_bdname_fail_test = {
2237 .expected_hal_cb.discovery_state_changed_cb =
2238 remote_discovery_state_changed_cb,
2239 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2240 .expected_cb_count = 3,
2241 .expected_properties = remote_setprop_bdname_props,
2242 .expected_adapter_status = BT_STATUS_FAIL,
2245 static struct priority_property remote_setprop_uuids_props[] = {
2247 .prop.type = BT_PROPERTY_UUIDS,
2253 static const struct generic_data bt_dev_setprop_uuids_fail_test = {
2254 .expected_hal_cb.discovery_state_changed_cb =
2255 remote_discovery_state_changed_cb,
2256 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2257 .expected_cb_count = 3,
2258 .expected_properties = remote_setprop_uuids_props,
2259 .expected_adapter_status = BT_STATUS_FAIL,
2262 static uint32_t remote_setprop_cod_val = 0;
2264 static struct priority_property remote_setprop_cod_props[] = {
2266 .prop.type = BT_PROPERTY_CLASS_OF_DEVICE,
2267 .prop.val = &remote_setprop_cod_val,
2268 .prop.len = sizeof(remote_setprop_cod_val),
2272 static const struct generic_data bt_dev_setprop_cod_fail_test = {
2273 .expected_hal_cb.discovery_state_changed_cb =
2274 remote_discovery_state_changed_cb,
2275 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2276 .expected_cb_count = 3,
2277 .expected_properties = remote_setprop_cod_props,
2278 .expected_adapter_status = BT_STATUS_FAIL,
2281 static bt_device_type_t remote_setprop_tod_val = BT_DEVICE_DEVTYPE_BREDR;
2283 static struct priority_property remote_setprop_tod_props[] = {
2285 .prop.type = BT_PROPERTY_TYPE_OF_DEVICE,
2286 .prop.val = &remote_setprop_tod_val,
2287 .prop.len = sizeof(remote_setprop_tod_val),
2291 static const struct generic_data bt_dev_setprop_tod_fail_test = {
2292 .expected_hal_cb.discovery_state_changed_cb =
2293 remote_discovery_state_changed_cb,
2294 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2295 .expected_cb_count = 3,
2296 .expected_properties = remote_setprop_tod_props,
2297 .expected_adapter_status = BT_STATUS_FAIL,
2300 static int32_t remote_setprop_rssi_val = -60;
2302 static struct priority_property remote_setprop_rssi_props[] = {
2304 .prop.type = BT_PROPERTY_REMOTE_RSSI,
2305 .prop.val = &remote_setprop_rssi_val,
2306 .prop.len = sizeof(remote_setprop_rssi_val),
2310 static const struct generic_data bt_dev_setprop_rssi_fail_test = {
2311 .expected_hal_cb.discovery_state_changed_cb =
2312 remote_discovery_state_changed_cb,
2313 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2314 .expected_cb_count = 3,
2315 .expected_properties = remote_setprop_rssi_props,
2316 .expected_adapter_status = BT_STATUS_FAIL,
2319 static int32_t remote_setprop_timestamp_val = 0xAB;
2321 static struct priority_property remote_setprop_timestamp_props[] = {
2323 .prop.type = BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP,
2324 .prop.val = (&remote_setprop_timestamp_val),
2325 .prop.len = sizeof(remote_setprop_timestamp_val),
2329 static const struct generic_data bt_dev_setprop_timpestamp_fail_test = {
2330 .expected_hal_cb.discovery_state_changed_cb =
2331 remote_discovery_state_changed_cb,
2332 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2333 .expected_cb_count = 3,
2334 .expected_properties = remote_setprop_timestamp_props,
2335 .expected_adapter_status = BT_STATUS_FAIL,
2338 static bt_bdaddr_t remote_setprop_bdaddr_val = {
2339 .address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
2342 static struct priority_property remote_setprop_bdaddr_props[] = {
2344 .prop.type = BT_PROPERTY_BDADDR,
2345 .prop.val = &remote_setprop_bdaddr_val,
2346 .prop.len = sizeof(remote_setprop_bdaddr_val),
2350 static const struct generic_data bt_dev_setprop_bdaddr_fail_test = {
2351 .expected_hal_cb.discovery_state_changed_cb =
2352 remote_discovery_state_changed_cb,
2353 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2354 .expected_cb_count = 3,
2355 .expected_properties = remote_setprop_bdaddr_props,
2356 .expected_adapter_status = BT_STATUS_FAIL,
2359 static bt_service_record_t remote_setprop_servrec_val = {
2365 static struct priority_property remote_setprop_servrec_props[] = {
2367 .prop.type = BT_PROPERTY_SERVICE_RECORD,
2368 .prop.val = &remote_setprop_servrec_val,
2369 .prop.len = sizeof(remote_setprop_servrec_val),
2373 static const struct generic_data bt_dev_setprop_servrec_fail_test = {
2374 .expected_hal_cb.discovery_state_changed_cb =
2375 remote_discovery_state_changed_cb,
2376 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2377 .expected_cb_count = 3,
2378 .expected_properties = remote_setprop_servrec_props,
2379 .expected_adapter_status = BT_STATUS_FAIL,
2382 static bt_scan_mode_t remote_setprop_scanmode_val = BT_SCAN_MODE_CONNECTABLE;
2384 static struct priority_property remote_setprop_scanmode_props[] = {
2386 .prop.type = BT_PROPERTY_ADAPTER_SCAN_MODE,
2387 .prop.val = &remote_setprop_scanmode_val,
2388 .prop.len = sizeof(remote_setprop_scanmode_val),
2392 static const struct generic_data bt_dev_setprop_scanmode_fail_test = {
2393 .expected_hal_cb.discovery_state_changed_cb =
2394 remote_discovery_state_changed_cb,
2395 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2396 .expected_cb_count = 3,
2397 .expected_properties = remote_setprop_scanmode_props,
2398 .expected_adapter_status = BT_STATUS_FAIL,
2401 static bt_bdaddr_t remote_setprop_bondeddev_val = {
2402 .address = { 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00 }
2405 static struct priority_property remote_setprop_bondeddev_props[] = {
2407 .prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
2408 .prop.val = &remote_setprop_bondeddev_val,
2409 .prop.len = sizeof(remote_setprop_bondeddev_val),
2413 static const struct generic_data bt_dev_setprop_bondeddev_fail_test = {
2414 .expected_hal_cb.discovery_state_changed_cb =
2415 remote_discovery_state_changed_cb,
2416 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2417 .expected_cb_count = 3,
2418 .expected_properties = remote_setprop_bondeddev_props,
2419 .expected_adapter_status = BT_STATUS_FAIL,
2422 static uint32_t remote_setprop_disctimeout_val = 120;
2424 static struct priority_property remote_setprop_disctimeout_props[] = {
2426 .prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
2427 .prop.val = &remote_setprop_disctimeout_val,
2428 .prop.len = sizeof(remote_setprop_disctimeout_val),
2432 static const struct generic_data bt_dev_setprop_disctimeout_fail_test = {
2433 .expected_hal_cb.discovery_state_changed_cb =
2434 remote_discovery_state_changed_cb,
2435 .expected_hal_cb.device_found_cb = remote_setprop_fail_device_found_cb,
2436 .expected_cb_count = 3,
2437 .expected_properties = remote_setprop_disctimeout_props,
2438 .expected_adapter_status = BT_STATUS_FAIL,
2441 static const struct generic_data bt_bond_create_pin_success_test = {
2442 .expected_hal_cb.device_found_cb = bond_device_found_cb,
2443 .expected_hal_cb.bond_state_changed_cb =
2444 bond_test_bonded_state_changed_cb,
2445 .expected_hal_cb.pin_request_cb = bond_create_pin_success_request_cb,
2446 .expected_cb_count = 4,
2447 .expected_adapter_status = BT_STATUS_SUCCESS,
2450 static const struct generic_data bt_bond_create_pin_fail_test = {
2451 .expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
2452 .expected_hal_cb.bond_state_changed_cb =
2453 bond_test_none_state_changed_cb,
2454 .expected_hal_cb.pin_request_cb = bond_create_pin_fail_request_cb,
2455 .expected_cb_count = 4,
2456 .expected_adapter_status = MGMT_STATUS_AUTH_FAILED,
2459 static const struct generic_data bt_bond_create_ssp_success_test = {
2460 .expected_hal_cb.device_found_cb = bond_device_found_cb,
2461 .expected_hal_cb.bond_state_changed_cb =
2462 bond_test_bonded_state_changed_cb,
2463 .expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
2464 .expected_cb_count = 4,
2465 .expected_adapter_status = BT_STATUS_SUCCESS,
2468 static const struct generic_data bt_bond_create_ssp_fail_test = {
2469 .expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
2470 .expected_hal_cb.bond_state_changed_cb =
2471 bond_test_none_state_changed_cb,
2472 .expected_hal_cb.ssp_request_cb = bond_create_ssp_fail_request_cb,
2473 .expected_cb_count = 4,
2474 .expected_adapter_status = MGMT_STATUS_AUTH_FAILED,
2477 static const struct generic_data bt_bond_create_no_disc_success_test = {
2478 .expected_hal_cb.bond_state_changed_cb =
2479 bond_test_bonded_state_changed_cb,
2480 .expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
2481 .expected_cb_count = 3,
2482 .expected_adapter_status = BT_STATUS_SUCCESS,
2485 static const struct generic_data bt_bond_create_bad_addr_success_test = {
2486 .expected_adapter_status = MGMT_STATUS_CONNECT_FAILED,
2489 static const struct generic_data bt_bond_cancel_success_test = {
2490 .expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
2491 .expected_hal_cb.bond_state_changed_cb =
2492 bond_test_none_state_changed_cb,
2493 .expected_hal_cb.ssp_request_cb = bond_cancel_success_ssp_request_cb,
2494 .expected_cb_count = 4,
2495 .expected_adapter_status = BT_STATUS_SUCCESS,
2498 static const struct generic_data bt_bond_remove_success_test = {
2499 .expected_hal_cb.device_found_cb = bond_nostatus_device_found_cb,
2500 .expected_hal_cb.bond_state_changed_cb =
2501 bond_remove_success_state_changed_cb,
2502 .expected_hal_cb.ssp_request_cb = bond_create_ssp_success_request_cb,
2503 .expected_cb_count = 4,
2504 .expected_adapter_status = BT_STATUS_SUCCESS,
2507 static bt_callbacks_t bt_callbacks = {
2508 .size = sizeof(bt_callbacks),
2509 .adapter_state_changed_cb = adapter_state_changed_cb,
2510 .adapter_properties_cb = adapter_properties_cb,
2511 .remote_device_properties_cb = remote_device_properties_cb,
2512 .device_found_cb = device_found_cb,
2513 .discovery_state_changed_cb = discovery_state_changed_cb,
2514 .pin_request_cb = pin_request_cb,
2515 .ssp_request_cb = ssp_request_cb,
2516 .bond_state_changed_cb = bond_state_changed_cb,
2517 .acl_state_changed_cb = NULL,
2518 .thread_evt_cb = NULL,
2519 .dut_mode_recv_cb = NULL,
2520 .le_test_mode_cb = NULL
2523 static bool setup(struct test_data *data)
2525 const hw_module_t *module;
2526 hw_device_t *device;
2533 if (pipe(signal_fd))
2539 close(signal_fd[0]);
2540 close(signal_fd[1]);
2545 if (!tester_use_debug())
2548 close(signal_fd[0]);
2549 emulator(signal_fd[1], data->mgmt_index);
2553 close(signal_fd[1]);
2554 data->bluetoothd_pid = pid;
2556 len = read(signal_fd[0], buf, sizeof(buf));
2557 if (len <= 0 || strcmp(buf, EMULATOR_SIGNAL)) {
2558 close(signal_fd[0]);
2562 close(signal_fd[0]);
2564 err = hw_get_module(BT_HARDWARE_MODULE_ID, &module);
2568 err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
2572 data->device = device;
2574 data->if_bluetooth = ((bluetooth_device_t *)
2575 device)->get_bluetooth_interface();
2576 if (!data->if_bluetooth)
2582 static void setup_base(const void *test_data)
2584 struct test_data *data = tester_get_data();
2588 tester_setup_failed();
2592 status = data->if_bluetooth->init(&bt_callbacks);
2593 if (status != BT_STATUS_SUCCESS) {
2594 data->if_bluetooth = NULL;
2595 tester_setup_failed();
2599 tester_setup_complete();
2602 static void setup_enabled_adapter(const void *test_data)
2604 struct test_data *data = tester_get_data();
2608 tester_setup_failed();
2612 status = data->if_bluetooth->init(&bt_callbacks);
2613 if (status != BT_STATUS_SUCCESS) {
2614 data->if_bluetooth = NULL;
2615 tester_setup_failed();
2619 status = data->if_bluetooth->enable();
2620 if (status != BT_STATUS_SUCCESS)
2621 tester_setup_failed();
2624 static void teardown(const void *test_data)
2626 struct test_data *data = tester_get_data();
2629 data->if_hid->cleanup();
2630 data->if_hid = NULL;
2633 if (data->if_bluetooth) {
2634 data->if_bluetooth->cleanup();
2635 data->if_bluetooth = NULL;
2638 if (data->expected_properties_list)
2639 g_slist_free(data->expected_properties_list);
2641 data->device->close(data->device);
2643 if (!data->bluetoothd_pid)
2644 tester_teardown_complete();
2647 static void test_dummy(const void *test_data)
2649 tester_test_passed();
2652 static void test_enable(const void *test_data)
2654 struct test_data *data = tester_get_data();
2655 bt_status_t adapter_status;
2657 uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
2659 init_test_conditions(data);
2661 bdaddr2android((const bdaddr_t *)bdaddr,
2662 &enable_done_bdaddr_val.address);
2664 adapter_status = data->if_bluetooth->enable();
2665 check_expected_status(adapter_status);
2668 static void test_enable_done(const void *test_data)
2670 struct test_data *data = tester_get_data();
2671 bt_status_t adapter_status;
2673 uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
2675 init_test_conditions(data);
2677 bdaddr2android((const bdaddr_t *)bdaddr,
2678 &enable_done_bdaddr_val.address);
2680 adapter_status = data->if_bluetooth->enable();
2681 check_expected_status(adapter_status);
2684 static void test_disable(const void *test_data)
2686 struct test_data *data = tester_get_data();
2687 bt_status_t adapter_status;
2689 init_test_conditions(data);
2691 adapter_status = data->if_bluetooth->disable();
2692 check_expected_status(adapter_status);
2695 static void test_setprop_bdname_success(const void *test_data)
2697 struct test_data *data = tester_get_data();
2698 const bt_property_t *prop = &(setprop_bdname_props[0].prop);
2699 bt_status_t adapter_status;
2701 init_test_conditions(data);
2703 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2704 check_expected_status(adapter_status);
2707 static void test_setprop_scanmode_succes(const void *test_data)
2709 struct test_data *data = tester_get_data();
2710 const bt_property_t *prop = &(setprop_scanmode_props[0].prop);
2711 bt_status_t adapter_status;
2713 init_test_conditions(data);
2715 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2716 check_expected_status(adapter_status);
2719 static void test_setprop_disctimeout_succes(const void *test_data)
2721 struct test_data *data = tester_get_data();
2722 const bt_property_t *prop = &(setprop_disctimeout_props[0].prop);
2723 bt_status_t adapter_status;
2725 init_test_conditions(data);
2727 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2728 check_expected_status(adapter_status);
2731 static void test_getprop_bdaddr_success(const void *test_data)
2733 struct test_data *data = tester_get_data();
2734 const bt_property_t prop = setprop_bdaddr_props[0].prop;
2735 bt_status_t adapter_status;
2736 uint8_t *bdaddr = (uint8_t *)hciemu_get_master_bdaddr(data->hciemu);
2738 init_test_conditions(data);
2740 bdaddr2android((const bdaddr_t *)bdaddr,
2741 &test_getprop_bdaddr_val.address);
2743 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2744 check_expected_status(adapter_status);
2747 static void test_getprop_bdname_success(const void *test_data)
2749 struct test_data *data = tester_get_data();
2750 const bt_property_t *prop = &(getprop_bdname_props[0].prop);
2751 bt_status_t adapter_status;
2753 init_test_conditions(data);
2755 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2756 if (adapter_status != BT_STATUS_SUCCESS) {
2757 tester_test_failed();
2761 adapter_status = data->if_bluetooth->get_adapter_property((*prop).type);
2762 check_expected_status(adapter_status);
2764 static void test_setprop_uuid_invalid(const void *test_data)
2766 struct test_data *data = tester_get_data();
2767 const bt_property_t *prop = &(setprop_uuid_prop[0].prop);
2768 bt_status_t adapter_status;
2770 init_test_conditions(data);
2772 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2773 check_expected_status(adapter_status);
2776 static void test_setprop_cod_invalid(const void *test_data)
2778 struct test_data *data = tester_get_data();
2779 const bt_property_t *prop = &(setprop_cod_props[0].prop);
2780 bt_status_t adapter_status;
2782 init_test_conditions(data);
2784 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2785 check_expected_status(adapter_status);
2788 static void test_setprop_tod_invalid(const void *test_data)
2790 struct test_data *data = tester_get_data();
2791 const struct generic_data *test = data->test_data;
2792 const bt_property_t *prop = &test->set_property;
2793 bt_status_t adapter_status;
2795 init_test_conditions(data);
2797 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2798 check_expected_status(adapter_status);
2801 static void test_setprop_rssi_invalid(const void *test_data)
2803 struct test_data *data = tester_get_data();
2804 const bt_property_t *prop = &(setprop_remote_rssi_props[0].prop);
2805 bt_status_t adapter_status;
2807 init_test_conditions(data);
2809 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2810 check_expected_status(adapter_status);
2813 static void test_setprop_service_record_invalid(const void *test_data)
2815 struct test_data *data = tester_get_data();
2816 const bt_property_t *prop = &(setprop_service_record_props[0].prop);
2817 bt_status_t adapter_status;
2819 init_test_conditions(data);
2821 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2822 check_expected_status(adapter_status);
2825 static void test_setprop_bdaddr_invalid(const void *test_data)
2827 struct test_data *data = tester_get_data();
2828 const bt_property_t *prop = &(setprop_bdaddr_props[0].prop);
2829 bt_status_t adapter_status;
2831 init_test_conditions(data);
2833 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2834 check_expected_status(adapter_status);
2837 static void test_setprop_scanmode_connectable_success(const void *test_data)
2839 struct test_data *data = tester_get_data();
2840 const bt_property_t *prop =
2841 &(setprop_scanmode_connectable_props[0].prop);
2842 bt_status_t adapter_status;
2844 init_test_conditions(data);
2846 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2847 check_expected_status(adapter_status);
2850 static void test_setprop_bonded_devices_invalid(const void *test_data)
2852 struct test_data *data = tester_get_data();
2853 const bt_property_t *prop = &(setprop_bonded_devices_props[0].prop);
2854 bt_status_t adapter_status;
2856 init_test_conditions(data);
2858 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2859 check_expected_status(adapter_status);
2862 static void test_getprop_cod_success(const void *test_data)
2864 struct test_data *data = tester_get_data();
2865 const bt_property_t prop = setprop_cod_props[0].prop;
2866 bt_status_t adapter_status;
2868 init_test_conditions(data);
2870 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2871 check_expected_status(adapter_status);
2874 static void test_getprop_tod_success(const void *test_data)
2876 struct test_data *data = tester_get_data();
2877 const bt_property_t prop = setprop_tod_props[0].prop;
2878 bt_status_t adapter_status;
2880 init_test_conditions(data);
2882 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2883 check_expected_status(adapter_status);
2886 static void test_getprop_scanmode_success(const void *test_data)
2888 struct test_data *data = tester_get_data();
2889 const bt_property_t prop = setprop_scanmode_props[0].prop;
2890 bt_status_t adapter_status;
2892 init_test_conditions(data);
2894 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2895 check_expected_status(adapter_status);
2898 static void test_getprop_disctimeout_success(const void *test_data)
2900 struct test_data *data = tester_get_data();
2901 const bt_property_t prop = setprop_disctimeout_props[0].prop;
2902 bt_status_t adapter_status;
2904 init_test_conditions(data);
2906 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2907 check_expected_status(adapter_status);
2910 static void test_getprop_uuids_success(const void *test_data)
2912 struct test_data *data = tester_get_data();
2913 const bt_property_t prop = getprop_uuids_props[0].prop;
2914 bt_status_t adapter_status;
2916 init_test_conditions(data);
2918 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2919 check_expected_status(adapter_status);
2922 static void test_getprop_bondeddev_success(const void *test_data)
2924 struct test_data *data = tester_get_data();
2925 const bt_property_t prop = getprop_bondeddev_props[0].prop;
2926 bt_status_t adapter_status;
2928 init_test_conditions(data);
2930 adapter_status = data->if_bluetooth->get_adapter_property(prop.type);
2931 check_expected_status(adapter_status);
2934 static void test_setprop_scanmode_none_done(const void *test_data)
2936 struct test_data *data = tester_get_data();
2937 const bt_property_t *prop = &(setprop_scanmode_none_props[0].prop);
2938 bt_status_t adapter_status;
2940 init_test_conditions(data);
2942 adapter_status = data->if_bluetooth->set_adapter_property(prop);
2943 check_expected_status(adapter_status);
2946 static void test_discovery_start_success(const void *test_data)
2948 struct test_data *data = tester_get_data();
2951 init_test_conditions(data);
2953 status = data->if_bluetooth->start_discovery();
2954 check_expected_status(status);
2957 static void test_discovery_stop_done(const void *test_data)
2959 struct test_data *data = tester_get_data();
2962 init_test_conditions(data);
2964 status = data->if_bluetooth->cancel_discovery();
2965 check_expected_status(status);
2968 static bool pre_inq_compl_hook(const void *dummy, uint16_t len, void *user_data)
2970 struct test_data *data = tester_get_data();
2972 /* Make sure Inquiry Command Complete is not called */
2974 hciemu_del_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY);
2979 static void test_discovery_stop_success(const void *test_data)
2981 struct test_data *data = tester_get_data();
2983 init_test_conditions(data);
2985 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY,
2986 pre_inq_compl_hook, data);
2988 data->if_bluetooth->start_discovery();
2991 static void test_discovery_start_done(const void *test_data)
2993 struct test_data *data = tester_get_data();
2995 init_test_conditions(data);
2997 hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY,
2998 pre_inq_compl_hook, data);
3000 data->if_bluetooth->start_discovery();
3003 static void test_discovery_device_found(const void *test_data)
3005 struct test_data *data = tester_get_data();
3007 init_test_conditions(data);
3009 data->if_bluetooth->start_discovery();
3012 static void test_dev_getprops_success(const void *test_data)
3014 struct test_data *data = tester_get_data();
3016 init_test_conditions(data);
3018 data->if_bluetooth->start_discovery();
3021 static void test_dev_getprop_bdname_success(const void *test_data)
3023 struct test_data *data = tester_get_data();
3025 init_test_conditions(data);
3027 data->if_bluetooth->start_discovery();
3030 static void test_dev_getprop_uuids_success(const void *test_data)
3032 struct test_data *data = tester_get_data();
3034 init_test_conditions(data);
3036 data->if_bluetooth->start_discovery();
3039 static void test_dev_getprop_cod_success(const void *test_data)
3041 struct test_data *data = tester_get_data();
3043 init_test_conditions(data);
3045 data->if_bluetooth->start_discovery();
3048 static void test_dev_getprop_tod_success(const void *test_data)
3050 struct test_data *data = tester_get_data();
3052 init_test_conditions(data);
3054 data->if_bluetooth->start_discovery();
3057 static void test_dev_getprop_rssi_success(const void *test_data)
3059 struct test_data *data = tester_get_data();
3061 init_test_conditions(data);
3063 data->if_bluetooth->start_discovery();
3066 static void test_dev_getprop_timestamp_success(const void *test_data)
3068 struct test_data *data = tester_get_data();
3070 init_test_conditions(data);
3072 data->if_bluetooth->start_discovery();
3075 static void test_dev_getprop_bdaddr_fail(const void *test_data)
3077 struct test_data *data = tester_get_data();
3079 init_test_conditions(data);
3081 data->if_bluetooth->start_discovery();
3084 static void test_dev_getprop_servrec_fail(const void *test_data)
3086 struct test_data *data = tester_get_data();
3088 init_test_conditions(data);
3090 data->if_bluetooth->start_discovery();
3093 static void test_dev_getprop_scanmode_fail(const void *test_data)
3095 struct test_data *data = tester_get_data();
3097 init_test_conditions(data);
3099 data->if_bluetooth->start_discovery();
3102 static void test_dev_getprop_bondeddev_fail(const void *test_data)
3104 struct test_data *data = tester_get_data();
3106 init_test_conditions(data);
3108 data->if_bluetooth->start_discovery();
3111 static void test_dev_getprop_disctimeout_fail(const void *test_data)
3113 struct test_data *data = tester_get_data();
3115 init_test_conditions(data);
3117 data->if_bluetooth->start_discovery();
3120 static void test_dev_getprop_verinfo_fail(const void *test_data)
3122 struct test_data *data = tester_get_data();
3124 init_test_conditions(data);
3126 data->if_bluetooth->start_discovery();
3129 static void test_dev_getprop_fname_fail(const void *test_data)
3131 struct test_data *data = tester_get_data();
3133 init_test_conditions(data);
3135 data->if_bluetooth->start_discovery();
3138 static void test_dev_setprop_fname_success(const void *test_data)
3140 struct test_data *data = tester_get_data();
3142 init_test_conditions(data);
3144 data->if_bluetooth->start_discovery();
3147 static void test_dev_setprop_bdname_fail(const void *test_data)
3149 struct test_data *data = tester_get_data();
3151 init_test_conditions(data);
3153 data->if_bluetooth->start_discovery();
3156 static void test_dev_setprop_uuids_fail(const void *test_data)
3158 struct test_data *data = tester_get_data();
3160 init_test_conditions(data);
3162 data->if_bluetooth->start_discovery();
3165 static void test_dev_setprop_cod_fail(const void *test_data)
3167 struct test_data *data = tester_get_data();
3169 init_test_conditions(data);
3171 data->if_bluetooth->start_discovery();
3174 static void test_dev_setprop_tod_fail(const void *test_data)
3176 struct test_data *data = tester_get_data();
3178 init_test_conditions(data);
3180 data->if_bluetooth->start_discovery();
3183 static void test_dev_setprop_rssi_fail(const void *test_data)
3185 struct test_data *data = tester_get_data();
3187 init_test_conditions(data);
3189 data->if_bluetooth->start_discovery();
3192 static void test_dev_setprop_timestamp_fail(const void *test_data)
3194 struct test_data *data = tester_get_data();
3196 init_test_conditions(data);
3198 data->if_bluetooth->start_discovery();
3201 static void test_dev_setprop_bdaddr_fail(const void *test_data)
3203 struct test_data *data = tester_get_data();
3205 init_test_conditions(data);
3207 data->if_bluetooth->start_discovery();
3210 static void test_dev_setprop_servrec_fail(const void *test_data)
3212 struct test_data *data = tester_get_data();
3214 init_test_conditions(data);
3216 data->if_bluetooth->start_discovery();
3219 static void test_dev_setprop_scanmode_fail(const void *test_data)
3221 struct test_data *data = tester_get_data();
3223 init_test_conditions(data);
3225 data->if_bluetooth->start_discovery();
3228 static void test_dev_setprop_bondeddev_fail(const void *test_data)
3230 struct test_data *data = tester_get_data();
3232 init_test_conditions(data);
3234 data->if_bluetooth->start_discovery();
3237 static void test_dev_setprop_disctimeout_fail(const void *test_data)
3239 struct test_data *data = tester_get_data();
3241 init_test_conditions(data);
3243 data->if_bluetooth->start_discovery();
3246 static void bond_device_auth_fail_callback(uint16_t index, uint16_t length,
3250 const struct mgmt_ev_auth_failed *ev = param;
3252 check_expected_status(ev->status);
3255 static void test_bond_create_pin_success(const void *test_data)
3257 struct test_data *data = tester_get_data();
3258 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3260 static uint8_t pair_device_pin[] = { 0x30, 0x30, 0x30, 0x30 };
3261 const void *pin = pair_device_pin;
3262 uint8_t pin_len = 4;
3264 init_test_conditions(data);
3266 bthost_set_pin_code(bthost, pin, pin_len);
3268 data->if_bluetooth->start_discovery();
3271 static void test_bond_create_pin_fail(const void *test_data)
3273 struct test_data *data = tester_get_data();
3274 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3276 static uint8_t pair_device_pin[] = { 0x30, 0x30, 0x30, 0x30 };
3277 const void *pin = pair_device_pin;
3278 uint8_t pin_len = 4;
3280 init_test_conditions(data);
3282 mgmt_register(data->mgmt, MGMT_EV_AUTH_FAILED, data->mgmt_index,
3283 bond_device_auth_fail_callback, data,
3286 bthost_set_pin_code(bthost, pin, pin_len);
3288 data->if_bluetooth->start_discovery();
3291 static void test_bond_create_ssp_success(const void *test_data)
3293 struct test_data *data = tester_get_data();
3294 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3296 init_test_conditions(data);
3298 bthost_write_ssp_mode(bthost, 0x01);
3300 data->if_bluetooth->start_discovery();
3303 static void test_bond_create_ssp_fail(const void *test_data)
3305 struct test_data *data = tester_get_data();
3306 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3308 init_test_conditions(data);
3310 mgmt_register(data->mgmt, MGMT_EV_AUTH_FAILED, data->mgmt_index,
3311 bond_device_auth_fail_callback, data,
3314 bthost_write_ssp_mode(bthost, 0x01);
3316 data->if_bluetooth->start_discovery();
3319 static void test_bond_create_no_disc_success(const void *test_data)
3321 struct test_data *data = tester_get_data();
3322 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3324 uint8_t *bdaddr = (uint8_t *)hciemu_get_client_bdaddr(data->hciemu);
3325 bt_bdaddr_t remote_addr;
3328 init_test_conditions(data);
3330 bdaddr2android((const bdaddr_t *)bdaddr, &remote_addr.address);
3332 bthost_write_ssp_mode(bthost, 0x01);
3334 status = data->if_bluetooth->create_bond(&remote_addr);
3335 check_expected_status(status);
3338 static void test_bond_create_bad_addr_success(const void *test_data)
3340 struct test_data *data = tester_get_data();
3341 bt_bdaddr_t bad_addr = {
3342 .address = { 0x12, 0x34, 0x56, 0x78, 0x90, 0x12 }
3345 init_test_conditions(data);
3347 mgmt_register(data->mgmt, MGMT_EV_CONNECT_FAILED, data->mgmt_index,
3348 bond_device_auth_fail_callback, data,
3351 data->if_bluetooth->create_bond(&bad_addr);
3354 static void test_bond_cancel_success(const void *test_data)
3356 struct test_data *data = tester_get_data();
3357 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3359 init_test_conditions(data);
3361 bthost_write_ssp_mode(bthost, 0x01);
3363 data->if_bluetooth->start_discovery();
3366 static void test_bond_remove_success(const void *test_data)
3368 struct test_data *data = tester_get_data();
3369 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3371 init_test_conditions(data);
3373 bthost_write_ssp_mode(bthost, 0x01);
3375 data->if_bluetooth->start_discovery();
3378 /* Test Socket HAL */
3380 static gboolean adapter_socket_state_changed(gpointer user_data)
3382 struct bt_cb_data *cb_data = user_data;
3384 switch (cb_data->state) {
3386 setup_powered_emulated_remote();
3389 tester_setup_failed();
3397 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3401 static void adapter_socket_state_changed_cb(bt_state_t state)
3403 struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
3405 cb_data->state = state;
3407 g_atomic_int_inc(&scheduled_cbacks_num);
3408 g_idle_add(adapter_socket_state_changed, cb_data);
3411 const bt_bdaddr_t bdaddr_dummy = {
3412 .address = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
3415 static const struct socket_data btsock_inv_param_socktype = {
3416 .bdaddr = &bdaddr_dummy,
3419 .service_uuid = NULL,
3420 .service_name = "Test service",
3422 .expected_status = BT_STATUS_PARM_INVALID,
3425 static const struct socket_data btsock_inv_param_socktype_l2cap = {
3426 .bdaddr = &bdaddr_dummy,
3427 .sock_type = BTSOCK_L2CAP,
3429 .service_uuid = NULL,
3430 .service_name = "Test service",
3432 .expected_status = BT_STATUS_UNSUPPORTED,
3435 /* Test invalid: channel & uuid are both zeroes */
3436 static const struct socket_data btsock_inv_params_chan_uuid = {
3437 .bdaddr = &bdaddr_dummy,
3438 .sock_type = BTSOCK_RFCOMM,
3440 .service_uuid = NULL,
3441 .service_name = "Test service",
3443 .expected_status = BT_STATUS_PARM_INVALID,
3446 static const struct socket_data btsock_success = {
3447 .bdaddr = &bdaddr_dummy,
3448 .sock_type = BTSOCK_RFCOMM,
3450 .service_uuid = NULL,
3451 .service_name = "Test service",
3453 .expected_status = BT_STATUS_SUCCESS,
3454 .test_channel = false
3457 static const struct socket_data btsock_success_check_chan = {
3458 .sock_type = BTSOCK_RFCOMM,
3460 .service_uuid = NULL,
3461 .service_name = "Test service",
3463 .expected_status = BT_STATUS_SUCCESS,
3464 .test_channel = true,
3467 static const struct socket_data btsock_inv_param_bdaddr = {
3469 .sock_type = BTSOCK_RFCOMM,
3471 .service_uuid = NULL,
3472 .service_name = "Test service",
3474 .expected_status = BT_STATUS_PARM_INVALID,
3477 static const struct socket_data btsock_inv_listen_listen = {
3478 .sock_type = BTSOCK_RFCOMM,
3480 .service_uuid = NULL,
3481 .service_name = "Test service",
3483 .expected_status = BT_STATUS_BUSY,
3484 .test_channel = true,
3487 static bt_callbacks_t bt_socket_callbacks = {
3488 .size = sizeof(bt_callbacks),
3489 .adapter_state_changed_cb = adapter_socket_state_changed_cb,
3490 .adapter_properties_cb = NULL,
3491 .remote_device_properties_cb = NULL,
3492 .device_found_cb = NULL,
3493 .discovery_state_changed_cb = NULL,
3494 .pin_request_cb = NULL,
3495 .ssp_request_cb = NULL,
3496 .bond_state_changed_cb = NULL,
3497 .acl_state_changed_cb = NULL,
3498 .thread_evt_cb = NULL,
3499 .dut_mode_recv_cb = NULL,
3500 .le_test_mode_cb = NULL
3503 static void setup_socket_interface(const void *test_data)
3505 struct test_data *data = tester_get_data();
3510 tester_setup_failed();
3514 status = data->if_bluetooth->init(&bt_socket_callbacks);
3515 if (status != BT_STATUS_SUCCESS) {
3516 data->if_bluetooth = NULL;
3517 tester_setup_failed();
3521 sock = data->if_bluetooth->get_profile_interface(BT_PROFILE_SOCKETS_ID);
3523 tester_setup_failed();
3527 data->if_sock = sock;
3529 tester_setup_complete();
3532 static void setup_socket_interface_enabled(const void *test_data)
3534 struct test_data *data = tester_get_data();
3539 tester_setup_failed();
3543 status = data->if_bluetooth->init(&bt_socket_callbacks);
3544 if (status != BT_STATUS_SUCCESS) {
3545 data->if_bluetooth = NULL;
3546 tester_setup_failed();
3550 sock = data->if_bluetooth->get_profile_interface(BT_PROFILE_SOCKETS_ID);
3552 tester_setup_failed();
3556 data->if_sock = sock;
3558 status = data->if_bluetooth->enable();
3559 if (status != BT_STATUS_SUCCESS)
3560 tester_setup_failed();
3563 static void test_generic_listen(const void *test_data)
3565 struct test_data *data = tester_get_data();
3566 const struct socket_data *test = data->test_data;
3570 status = data->if_sock->listen(test->sock_type,
3571 test->service_name, test->service_uuid,
3572 test->channel, &sock_fd, test->flags);
3573 if (status != test->expected_status) {
3574 tester_test_failed();
3578 /* Check that file descriptor is valid */
3579 if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) {
3580 tester_test_failed();
3584 if (status == BT_STATUS_SUCCESS && test->test_channel) {
3587 len = read(sock_fd, &channel, sizeof(channel));
3588 if (len != sizeof(channel) || channel != test->channel) {
3589 tester_test_failed();
3593 tester_print("read correct channel: %d", channel);
3596 tester_test_passed();
3603 static void test_listen_close(const void *test_data)
3605 struct test_data *data = tester_get_data();
3606 const struct socket_data *test = data->test_data;
3610 status = data->if_sock->listen(test->sock_type,
3611 test->service_name, test->service_uuid,
3612 test->channel, &sock_fd, test->flags);
3613 if (status != test->expected_status) {
3614 tester_warn("sock->listen() failed");
3615 tester_test_failed();
3619 /* Check that file descriptor is valid */
3620 if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) {
3621 tester_warn("sock_fd %d is not valid", sock_fd);
3622 tester_test_failed();
3626 tester_print("Got valid sock_fd: %d", sock_fd);
3628 /* Now close sock_fd */
3632 /* Try to listen again */
3633 status = data->if_sock->listen(test->sock_type,
3634 test->service_name, test->service_uuid,
3635 test->channel, &sock_fd, test->flags);
3636 if (status != test->expected_status) {
3637 tester_warn("sock->listen() failed");
3638 tester_test_failed();
3642 /* Check that file descriptor is valid */
3643 if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) {
3644 tester_warn("sock_fd %d is not valid", sock_fd);
3645 tester_test_failed();
3649 tester_print("Got valid sock_fd: %d", sock_fd);
3651 tester_test_passed();
3658 static void test_listen_listen(const void *test_data)
3660 struct test_data *data = tester_get_data();
3661 const struct socket_data *test = data->test_data;
3663 int sock_fd1 = -1, sock_fd2 = -1;
3665 status = data->if_sock->listen(test->sock_type,
3666 test->service_name, test->service_uuid,
3667 test->channel, &sock_fd1, test->flags);
3668 if (status != BT_STATUS_SUCCESS) {
3669 tester_warn("sock->listen() failed");
3670 tester_test_failed();
3674 status = data->if_sock->listen(test->sock_type,
3675 test->service_name, test->service_uuid,
3676 test->channel, &sock_fd2, test->flags);
3677 if (status != test->expected_status) {
3678 tester_warn("sock->listen() failed, status %d", status);
3679 tester_test_failed();
3683 tester_print("status after second listen(): %d", status);
3685 tester_test_passed();
3695 static void test_generic_connect(const void *test_data)
3697 struct test_data *data = tester_get_data();
3698 const struct socket_data *test = data->test_data;
3702 status = data->if_sock->connect(test->bdaddr, test->sock_type,
3703 test->service_uuid, test->channel,
3704 &sock_fd, test->flags);
3705 if (status != test->expected_status) {
3706 tester_test_failed();
3710 /* Check that file descriptor is valid */
3711 if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) {
3712 tester_test_failed();
3716 tester_test_passed();
3723 static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
3726 int sock_fd = g_io_channel_unix_get_fd(io);
3727 struct test_data *data = tester_get_data();
3728 const struct socket_data *test = data->test_data;
3731 tester_print("%s", __func__);
3733 if (cond & G_IO_HUP) {
3734 tester_warn("Socket %d hang up", sock_fd);
3738 if (cond & (G_IO_ERR | G_IO_NVAL)) {
3739 tester_warn("Socket error: sock %d cond %d", sock_fd, cond);
3743 if (test->test_channel) {
3744 len = read(sock_fd, &channel, sizeof(channel));
3745 if (len != sizeof(channel) || channel != test->channel)
3748 tester_print("read correct channel: %d", channel);
3749 tester_test_passed();
3754 tester_test_failed();
3758 static void test_socket_real_connect(const void *test_data)
3760 struct test_data *data = tester_get_data();
3761 const struct socket_data *test = data->test_data;
3762 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
3763 const uint8_t *client_bdaddr;
3764 bt_bdaddr_t emu_bdaddr;
3768 client_bdaddr = hciemu_get_client_bdaddr(data->hciemu);
3769 if (!client_bdaddr) {
3770 tester_warn("No client bdaddr");
3771 tester_test_failed();
3775 bdaddr2android((bdaddr_t *) client_bdaddr, &emu_bdaddr);
3777 bthost_add_l2cap_server(bthost, 0x0003, NULL, NULL);
3779 status = data->if_sock->connect(&emu_bdaddr, test->sock_type,
3780 test->service_uuid, test->channel,
3781 &sock_fd, test->flags);
3782 if (status != test->expected_status) {
3783 tester_test_failed();
3787 /* Check that file descriptor is valid */
3788 if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) {
3789 tester_test_failed();
3793 tester_print("status %d sock_fd %d", status, sock_fd);
3795 if (status == BT_STATUS_SUCCESS) {
3798 io = g_io_channel_unix_new(sock_fd);
3799 g_io_channel_set_close_on_unref(io, TRUE);
3801 g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
3802 socket_chan_cb, NULL);
3804 g_io_channel_unref(io);
3814 static gboolean hidhost_connection_state(gpointer user_data)
3816 struct test_data *data = tester_get_data();
3817 const struct hidhost_generic_data *test = data->test_data;
3818 struct hh_cb_data *cb_data = user_data;
3822 if (cb_data->state == BTHH_CONN_STATE_CONNECTED)
3823 tester_setup_complete();
3825 if (test && test->expected_hal_cb.connection_state_cb)
3826 test->expected_hal_cb.connection_state_cb(&cb_data->bdaddr,
3831 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3835 static void hidhost_connection_state_cb(bt_bdaddr_t *bd_addr,
3836 bthh_connection_state_t state)
3838 struct hh_cb_data *cb_data = g_new0(struct hh_cb_data, 1);
3840 cb_data->state = state;
3841 cb_data->bdaddr = *bd_addr;
3843 g_atomic_int_inc(&scheduled_cbacks_num);
3844 g_idle_add(hidhost_connection_state, cb_data);
3847 static gboolean hidhost_virual_unplug(gpointer user_data)
3849 struct test_data *data = tester_get_data();
3850 const struct hidhost_generic_data *test = data->test_data;
3851 struct hh_cb_data *cb_data = user_data;
3855 if (test && test->expected_hal_cb.virtual_unplug_cb)
3856 test->expected_hal_cb.virtual_unplug_cb(&cb_data->bdaddr,
3861 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3865 static void hidhost_virual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t status)
3867 struct hh_cb_data *cb_data = g_new0(struct hh_cb_data, 1);
3869 cb_data->bdaddr = *bd_addr;
3870 cb_data->status = status;
3872 g_atomic_int_inc(&scheduled_cbacks_num);
3873 g_idle_add(hidhost_virual_unplug, cb_data);
3876 static gboolean hidhost_hid_info(gpointer user_data)
3878 struct test_data *data = tester_get_data();
3879 const struct hidhost_generic_data *test = data->test_data;
3880 struct hh_cb_data *cb_data = user_data;
3884 if (test && test->expected_hal_cb.hid_info_cb)
3885 test->expected_hal_cb.hid_info_cb(&cb_data->bdaddr,
3890 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3894 static void hidhost_hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid)
3896 struct hh_cb_data *cb_data = g_new0(struct hh_cb_data, 1);
3898 cb_data->bdaddr = *bd_addr;
3899 cb_data->hid_info = hid;
3901 g_atomic_int_inc(&scheduled_cbacks_num);
3902 g_idle_add(hidhost_hid_info, cb_data);
3905 static gboolean hidhost_protocol_mode(gpointer user_data)
3907 struct test_data *data = tester_get_data();
3908 const struct hidhost_generic_data *test = data->test_data;
3909 struct hh_cb_data *cb_data = user_data;
3913 if (test && test->expected_hal_cb.protocol_mode_cb)
3914 test->expected_hal_cb.protocol_mode_cb(&cb_data->bdaddr,
3915 cb_data->status, cb_data->mode);
3919 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3923 static void hidhost_protocol_mode_cb(bt_bdaddr_t *bd_addr,
3924 bthh_status_t status,
3925 bthh_protocol_mode_t mode)
3927 struct hh_cb_data *cb_data = g_new0(struct hh_cb_data, 1);
3929 cb_data->bdaddr = *bd_addr;
3930 cb_data->status = status;
3931 cb_data->mode = mode;
3933 g_atomic_int_inc(&scheduled_cbacks_num);
3934 g_idle_add(hidhost_protocol_mode, cb_data);
3937 static gboolean hidhost_get_report(gpointer user_data)
3939 struct test_data *data = tester_get_data();
3940 const struct hidhost_generic_data *test = data->test_data;
3941 struct hh_cb_data *cb_data = user_data;
3945 if (test && test->expected_hal_cb.get_report_cb)
3946 test->expected_hal_cb.get_report_cb(&cb_data->bdaddr,
3947 cb_data->status, cb_data->report, cb_data->size);
3949 g_free(cb_data->report);
3952 g_atomic_int_dec_and_test(&scheduled_cbacks_num);
3956 static void hidhost_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
3957 uint8_t *report, int size)
3959 struct hh_cb_data *cb_data = g_new0(struct hh_cb_data, 1);
3961 cb_data->bdaddr = *bd_addr;
3962 cb_data->status = status;
3963 cb_data->report = g_memdup(report, size);
3964 cb_data->size = size;
3966 g_atomic_int_inc(&scheduled_cbacks_num);
3967 g_idle_add(hidhost_get_report, cb_data);
3970 static bthh_callbacks_t bthh_callbacks = {
3971 .size = sizeof(bthh_callbacks),
3972 .connection_state_cb = hidhost_connection_state_cb,
3973 .hid_info_cb = hidhost_hid_info_cb,
3974 .protocol_mode_cb = hidhost_protocol_mode_cb,
3975 .idle_time_cb = NULL,
3976 .get_report_cb = hidhost_get_report_cb,
3977 .virtual_unplug_cb = hidhost_virual_unplug_cb
3980 static bool setup_hidhost(const void *test_data)
3982 struct test_data *data = tester_get_data();
3989 status = data->if_bluetooth->init(&bt_callbacks);
3990 if (status != BT_STATUS_SUCCESS) {
3991 data->if_bluetooth = NULL;
3995 hid = data->if_bluetooth->get_profile_interface(BT_PROFILE_HIDHOST_ID);
4001 status = data->if_hid->init(&bthh_callbacks);
4002 if (status != BT_STATUS_SUCCESS) {
4003 data->if_hid = NULL;
4010 static void setup_hidhost_interface(const void *test_data)
4012 if (setup_hidhost(test_data))
4013 tester_setup_complete();
4015 tester_setup_failed();
4018 #define HID_GET_REPORT_PROTOCOL 0x60
4019 #define HID_GET_BOOT_PROTOCOL 0x61
4020 #define HID_SET_REPORT_PROTOCOL 0x70
4021 #define HID_SET_BOOT_PROTOCOL 0x71
4023 #define HID_SET_INPUT_REPORT 0x51
4024 #define HID_SET_OUTPUT_REPORT 0x52
4025 #define HID_SET_FEATURE_REPORT 0x53
4027 #define HID_SEND_DATA 0xa2
4029 #define HID_GET_INPUT_REPORT 0x49
4030 #define HID_GET_OUTPUT_REPORT 0x4a
4031 #define HID_GET_FEATURE_REPORT 0x4b
4033 static void hid_prepare_reply_protocol_mode(const void *data, uint16_t len)
4035 struct test_data *t_data = tester_get_data();
4036 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
4037 uint8_t pdu[2] = { 0, 0 };
4038 uint16_t pdu_len = 0;
4044 bthost_send_cid(bthost, t_data->ctrl_handle, t_data->ctrl_cid,
4045 (void *)pdu, pdu_len);
4048 static void hid_prepare_reply_report(const void *data, uint16_t len)
4050 struct test_data *t_data = tester_get_data();
4051 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
4052 uint8_t pdu[3] = { 0, 0, 0 };
4053 uint16_t pdu_len = 0;
4060 bthost_send_cid(bthost, t_data->ctrl_handle, t_data->ctrl_cid,
4061 (void *)pdu, pdu_len);
4064 static void hid_intr_cid_hook_cb(const void *data, uint16_t len,
4067 uint8_t header = ((uint8_t *) data)[0];
4071 tester_test_passed();
4076 static void hid_intr_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
4078 struct test_data *data = tester_get_data();
4079 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
4081 data->intr_handle = handle;
4082 data->intr_cid = cid;
4084 bthost_add_cid_hook(bthost, handle, cid, hid_intr_cid_hook_cb, NULL);
4087 static void hid_ctrl_cid_hook_cb(const void *data, uint16_t len,
4090 uint8_t header = ((uint8_t *) data)[0];
4093 case HID_GET_REPORT_PROTOCOL:
4094 case HID_GET_BOOT_PROTOCOL:
4095 case HID_SET_REPORT_PROTOCOL:
4096 case HID_SET_BOOT_PROTOCOL:
4097 hid_prepare_reply_protocol_mode(data, len);
4099 case HID_GET_INPUT_REPORT:
4100 case HID_GET_OUTPUT_REPORT:
4101 case HID_GET_FEATURE_REPORT:
4102 hid_prepare_reply_report(data, len);
4104 /* HID device doesnot reply for this commads, so reaching pdu's
4105 * to hid device means assuming test passed */
4106 case HID_SET_INPUT_REPORT:
4107 case HID_SET_OUTPUT_REPORT:
4108 case HID_SET_FEATURE_REPORT:
4110 tester_test_passed();
4115 static void hid_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
4117 struct test_data *data = tester_get_data();
4118 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
4120 data->ctrl_handle = handle;
4121 data->ctrl_cid = cid;
4123 bthost_add_cid_hook(bthost, handle, cid, hid_ctrl_cid_hook_cb, NULL);
4126 static const uint8_t did_req_pdu[] = { 0x06, /* PDU id */
4127 0x00, 0x00, /* Transaction id */
4128 0x00, 0x0f, /* Req length */
4129 0x35, 0x03, /* Attributes length */
4130 0x19, 0x12, 0x00, 0xff, 0xff, 0x35, 0x05, 0x0a, 0x00,
4131 0x00, 0xff, 0xff, 0x00 }; /* no continuation */
4133 static const uint8_t did_rsp_pdu[] = { 0x07, /* PDU id */
4134 0x00, 0x00, /* Transaction id */
4135 0x00, 0x4f, /* Response length */
4136 0x00, 0x4c, /* Attributes length */
4137 0x35, 0x4a, 0x35, 0x48, 0x09, 0x00, 0x00, 0x0a, 0x00,
4138 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19,
4139 0x12, 0x00, 0x09, 0x00, 0x05, 0x35, 0x03, 0x19, 0x10,
4140 0x02, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19,
4141 0x12, 0x00, 0x09, 0x01, 0x03, 0x09, 0x02, 0x00, 0x09,
4142 0x01, 0x03, 0x09, 0x02, 0x01, 0x09, 0x1d, 0x6b, 0x09,
4143 0x02, 0x02, 0x09, 0x02, 0x46, 0x09, 0x02, 0x03, 0x09,
4144 0x05, 0x0e, 0x09, 0x02, 0x04, 0x28, 0x01, 0x09, 0x02,
4145 0x05, 0x09, 0x00, 0x02,
4146 0x00 }; /* no continuation */
4148 static const uint8_t hid_rsp_pdu[] = { 0x07, /* PDU id */
4149 0x00, 0x01, /* Transaction id */
4150 0x01, 0x71, /* Response length */
4151 0x01, 0x6E, /* Attributes length */
4152 0x36, 0x01, 0x6b, 0x36, 0x01, 0x68, 0x09, 0x00, 0x00,
4153 0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35,
4154 0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d,
4155 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35,
4156 0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x05, 0x35, 0x03,
4157 0x19, 0x10, 0x02, 0x09, 0x00, 0x06, 0x35, 0x09, 0x09,
4158 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, 0x09,
4159 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, 0x24,
4160 0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, 0x35,
4161 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x13,
4162 0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, 0x25,
4163 0x1e, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63, 0x68,
4164 0x20, 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74,
4165 0x68, 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x20, 0x4d,
4166 0x35, 0x35, 0x35, 0x62, 0x09, 0x01, 0x01, 0x25, 0x0f,
4167 0x42, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68,
4168 0x20, 0x4d, 0x6f, 0x75, 0x73, 0x65, 0x09, 0x01, 0x02,
4169 0x25, 0x08, 0x4c, 0x6f, 0x67, 0x69, 0x74, 0x65, 0x63,
4170 0x68, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02,
4171 0x01, 0x09, 0x01, 0x11, 0x09, 0x02, 0x02, 0x08, 0x80,
4172 0x09, 0x02, 0x03, 0x08, 0x21, 0x09, 0x02, 0x04, 0x28,
4173 0x01, 0x09, 0x02, 0x05, 0x28, 0x01, 0x09, 0x02, 0x06,
4174 0x35, 0x74, 0x35, 0x72, 0x08, 0x22, 0x25, 0x6e, 0x05,
4175 0x01, 0x09, 0x02, 0xa1, 0x01, 0x85, 0x02, 0x09, 0x01,
4176 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x08, 0x15,
4177 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02,
4178 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x16, 0x01, 0xf8,
4179 0x26, 0xff, 0x07, 0x75, 0x0c, 0x95, 0x02, 0x81, 0x06,
4180 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95,
4181 0x01, 0x81, 0x06, 0x05, 0x0c, 0x0a, 0x38, 0x02, 0x81,
4182 0x06, 0x05, 0x09, 0x19, 0x09, 0x29, 0x10, 0x15, 0x00,
4183 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0xc0,
4184 0xc0, 0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85,
4185 0x10, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff,
4186 0x00, 0x09, 0x01, 0x81, 0x00, 0x09, 0x01, 0x91, 0x00,
4187 0xc0, 0x09, 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09,
4188 0x04, 0x09, 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28,
4189 0x00, 0x09, 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a,
4190 0x28, 0x01, 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09,
4191 0x02, 0x0c, 0x09, 0x0c, 0x80, 0x09, 0x02, 0x0d, 0x28,
4192 0x00, 0x09, 0x02, 0x0e, 0x28, 0x01,
4193 0x00 }; /* no continuation */
4195 static void hid_sdp_cid_hook_cb(const void *data, uint16_t len, void *user_data)
4197 struct test_data *t_data = tester_get_data();
4198 struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
4200 if (!memcmp(did_req_pdu, data, len)) {
4201 bthost_send_cid(bthost, t_data->sdp_handle, t_data->sdp_cid,
4202 did_rsp_pdu, sizeof(did_rsp_pdu));
4206 bthost_send_cid(bthost, t_data->sdp_handle, t_data->sdp_cid,
4207 hid_rsp_pdu, sizeof(hid_rsp_pdu));
4210 static void hid_sdp_search_cb(uint16_t handle, uint16_t cid, void *user_data)
4212 struct test_data *data = tester_get_data();
4213 struct bthost *bthost = hciemu_client_get_host(data->hciemu);
4215 data->sdp_handle = handle;
4216 data->sdp_cid = cid;
4218 bthost_add_cid_hook(bthost, handle, cid, hid_sdp_cid_hook_cb, NULL);
4221 static void emu_powered_complete(uint16_t opcode, uint8_t status,
4222 const void *param, uint8_t len,
4225 struct test_data *data = tester_get_data();
4226 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4228 bt_status_t bt_status;
4231 case BT_HCI_CMD_WRITE_SCAN_ENABLE:
4232 case BT_HCI_CMD_LE_SET_ADV_ENABLE:
4239 tester_setup_failed();
4244 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4245 bt_status = data->if_hid->connect(&bdaddr);
4246 if (bt_status != BT_STATUS_SUCCESS)
4247 tester_setup_failed();
4250 static void setup_hidhost_connect(const void *test_data)
4252 struct test_data *data = tester_get_data();
4253 struct bthost *bthost;
4255 if (!setup_hidhost(test_data)) {
4256 tester_setup_failed();
4260 bthost = hciemu_client_get_host(data->hciemu);
4262 /* Emulate SDP (PSM = 1) */
4263 bthost_add_l2cap_server(bthost, 1, hid_sdp_search_cb, NULL);
4264 /* Emulate Control Channel (PSM = 17) */
4265 bthost_add_l2cap_server(bthost, 17, hid_ctrl_connect_cb, NULL);
4266 /* Emulate Interrupt Channel (PSM = 19) */
4267 bthost_add_l2cap_server(bthost, 19, hid_intr_connect_cb, NULL);
4269 bthost_set_cmd_complete_cb(bthost, emu_powered_complete, data);
4270 bthost_write_scan_enable(bthost, 0x03);
4273 static void hid_discon_cb(bt_bdaddr_t *bd_addr, bthh_connection_state_t state)
4275 if (state == BTHH_CONN_STATE_DISCONNECTED)
4276 tester_test_passed();
4279 static const struct hidhost_generic_data hidhost_test_disconnect = {
4280 .expected_hal_cb.connection_state_cb = hid_discon_cb,
4283 static void test_hidhost_disconnect(const void *test_data)
4285 struct test_data *data = tester_get_data();
4286 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4288 bt_status_t bt_status;
4291 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4292 bt_status = data->if_hid->disconnect(&bdaddr);
4293 if (bt_status != BT_STATUS_SUCCESS)
4294 tester_test_failed();
4297 static void test_hidhost_virtual_unplug(const void *test_data)
4299 struct test_data *data = tester_get_data();
4300 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4302 bt_status_t bt_status;
4305 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4306 bt_status = data->if_hid->virtual_unplug(&bdaddr);
4307 if (bt_status != BT_STATUS_SUCCESS)
4308 tester_test_failed();
4311 static void hid_protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
4312 bthh_protocol_mode_t mode)
4314 struct test_data *data = tester_get_data();
4315 const struct hidhost_generic_data *test = data->test_data;
4317 if (data->cb_count == test->expected_cb_count &&
4318 status == test->expected_status &&
4319 mode == test->expected_protocol_mode)
4320 tester_test_passed();
4322 tester_test_failed();
4325 static const struct hidhost_generic_data hidhost_test_get_protocol = {
4326 .expected_hal_cb.protocol_mode_cb = hid_protocol_mode_cb,
4327 .expected_cb_count = 1,
4328 .expected_protocol_mode = BTHH_BOOT_MODE,
4329 .expected_status = BTHH_OK,
4332 static void test_hidhost_get_protocol(const void *test_data)
4334 struct test_data *data = tester_get_data();
4335 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4337 bt_status_t bt_status;
4340 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4341 bt_status = data->if_hid->get_protocol(&bdaddr, BTHH_REPORT_MODE);
4342 if (bt_status != BT_STATUS_SUCCESS)
4343 tester_test_failed();
4346 static void test_hidhost_set_protocol(const void *test_data)
4348 struct test_data *data = tester_get_data();
4349 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4351 bt_status_t bt_status;
4354 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4355 bt_status = data->if_hid->set_protocol(&bdaddr, BTHH_REPORT_MODE);
4356 if (bt_status != BT_STATUS_SUCCESS)
4357 tester_test_failed();
4360 static void test_hidhost_set_report(const void *test_data)
4362 struct test_data *data = tester_get_data();
4363 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4365 bt_status_t bt_status;
4366 char *buf = "010101";
4369 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4370 bt_status = data->if_hid->set_report(&bdaddr, BTHH_INPUT_REPORT, buf);
4371 if (bt_status != BT_STATUS_SUCCESS)
4372 tester_test_failed();
4375 static void test_hidhost_send_data(const void *test_data)
4377 struct test_data *data = tester_get_data();
4378 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4380 bt_status_t bt_status;
4381 char *buf = "fe0201";
4384 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4385 bt_status = data->if_hid->send_data(&bdaddr, buf);
4386 if (bt_status != BT_STATUS_SUCCESS)
4387 tester_test_failed();
4390 static void hid_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
4391 uint8_t *report, int size)
4393 struct test_data *data = tester_get_data();
4394 const struct hidhost_generic_data *test = data->test_data;
4396 if (data->cb_count == test->expected_cb_count &&
4397 status == test->expected_status &&
4398 size == test->expected_report_size)
4399 tester_test_passed();
4401 tester_test_failed();
4404 static const struct hidhost_generic_data hidhost_test_get_report = {
4405 .expected_hal_cb.get_report_cb = hid_get_report_cb,
4406 .expected_cb_count = 1,
4407 .expected_status = BTHH_OK,
4408 .expected_report_size = 2,
4411 static void test_hidhost_get_report(const void *test_data)
4413 struct test_data *data = tester_get_data();
4414 const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
4416 bt_status_t bt_status;
4419 bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);
4420 bt_status = data->if_hid->get_report(&bdaddr, BTHH_INPUT_REPORT, 1, 20);
4421 if (bt_status != BT_STATUS_SUCCESS)
4422 tester_test_failed();
4425 #define test_bredrle(name, data, test_setup, test, test_teardown) \
4427 struct test_data *user; \
4428 user = g_malloc0(sizeof(struct test_data)); \
4431 user->hciemu_type = HCIEMU_TYPE_BREDRLE; \
4432 user->test_data = data; \
4433 tester_add_full(name, data, test_pre_setup, test_setup, \
4434 test, test_teardown, test_post_teardown, \
4438 int main(int argc, char *argv[])
4440 snprintf(exec_dir, sizeof(exec_dir), "%s", dirname(argv[0]));
4442 tester_init(&argc, &argv);
4444 test_bredrle("Bluetooth Init", NULL, setup_base, test_dummy, teardown);
4446 test_bredrle("Bluetooth Enable - Success",
4447 &bluetooth_enable_success_test,
4448 setup_base, test_enable,
4451 test_bredrle("Bluetooth Enable - Success 2",
4452 &bluetooth_enable_success2_test,
4453 setup_enabled_adapter,
4454 test_enable_done, teardown);
4456 test_bredrle("Bluetooth Disable - Success",
4457 &bluetooth_disable_success_test,
4458 setup_enabled_adapter,
4459 test_disable, teardown);
4461 test_bredrle("Bluetooth Set BDNAME - Success",
4462 &bluetooth_setprop_bdname_success_test,
4463 setup_enabled_adapter,
4464 test_setprop_bdname_success, teardown);
4466 test_bredrle("Bluetooth Set SCAN_MODE - Success",
4467 &bluetooth_setprop_scanmode_success_test,
4468 setup_enabled_adapter,
4469 test_setprop_scanmode_succes, teardown);
4471 test_bredrle("Bluetooth Set DISCOVERY_TIMEOUT - Success",
4472 &bluetooth_setprop_disctimeout_success_test,
4473 setup_enabled_adapter,
4474 test_setprop_disctimeout_succes, teardown);
4476 test_bredrle("Bluetooth Get BDADDR - Success",
4477 &bluetooth_getprop_bdaddr_success_test,
4478 setup_enabled_adapter,
4479 test_getprop_bdaddr_success, teardown);
4481 test_bredrle("Bluetooth Get BDNAME - Success",
4482 &bluetooth_getprop_bdname_success_test,
4483 setup_enabled_adapter,
4484 test_getprop_bdname_success, teardown);
4486 test_bredrle("Bluetooth Set UUID - Invalid",
4487 &bluetooth_setprop_uuid_invalid_test,
4488 setup_enabled_adapter,
4489 test_setprop_uuid_invalid, teardown);
4491 test_bredrle("Bluetooth Set CLASS_OF_DEVICE - Invalid",
4492 &bluetooth_setprop_cod_invalid_test,
4493 setup_enabled_adapter,
4494 test_setprop_cod_invalid, teardown);
4496 test_bredrle("Bluetooth Set TYPE_OF_DEVICE - Invalid",
4497 &bluetooth_setprop_tod_invalid_test,
4498 setup_enabled_adapter,
4499 test_setprop_tod_invalid, teardown);
4501 test_bredrle("Bluetooth Set REMOTE_RSSI - Invalid",
4502 &bluetooth_setprop_remote_rssi_invalid_test,
4503 setup_enabled_adapter,
4504 test_setprop_rssi_invalid, teardown);
4506 test_bredrle("Bluetooth Set SERVICE_RECORD - Invalid",
4507 &bluetooth_setprop_service_record_invalid_test,
4508 setup_enabled_adapter,
4509 test_setprop_service_record_invalid, teardown);
4511 test_bredrle("Bluetooth Set BDADDR - Invalid",
4512 &bluetooth_setprop_bdaddr_invalid_test,
4513 setup_enabled_adapter,
4514 test_setprop_bdaddr_invalid, teardown);
4516 test_bredrle("Bluetooth Set SCAN_MODE CONNECTABLE - Success",
4517 &bluetooth_setprop_scanmode_connectable_success_test,
4518 setup_enabled_adapter,
4519 test_setprop_scanmode_connectable_success, teardown);
4521 test_bredrle("Bluetooth Set BONDED_DEVICES - Invalid",
4522 &bluetooth_setprop_bonded_devices_invalid_test,
4523 setup_enabled_adapter,
4524 test_setprop_bonded_devices_invalid, teardown);
4526 test_bredrle("Bluetooth Get CLASS_OF_DEVICE - Success",
4527 &bluetooth_getprop_cod_success_test,
4528 setup_enabled_adapter,
4529 test_getprop_cod_success, teardown);
4531 test_bredrle("Bluetooth Get TYPE_OF_DEVICE - Success",
4532 &bluetooth_getprop_tod_success_test,
4533 setup_enabled_adapter,
4534 test_getprop_tod_success, teardown);
4536 test_bredrle("Bluetooth Get SCAN_MODE - Success",
4537 &bluetooth_getprop_scanmode_success_test,
4538 setup_enabled_adapter,
4539 test_getprop_scanmode_success, teardown);
4541 test_bredrle("Bluetooth Get DISCOVERY_TIMEOUT - Success",
4542 &bluetooth_getprop_disctimeout_success_test,
4543 setup_enabled_adapter,
4544 test_getprop_disctimeout_success, teardown);
4546 test_bredrle("Bluetooth Get UUIDS - Success",
4547 &bluetooth_getprop_uuids_success_test,
4548 setup_enabled_adapter,
4549 test_getprop_uuids_success, teardown);
4551 test_bredrle("Bluetooth Get BONDED_DEVICES - Success",
4552 &bluetooth_getprop_bondeddev_success_test,
4553 setup_enabled_adapter,
4554 test_getprop_bondeddev_success, teardown);
4556 test_bredrle("Bluetooth Set SCAN_MODE NONE - Success 2",
4557 &bluetooth_setprop_scanmode_none_success2_test,
4558 setup_enabled_adapter,
4559 test_setprop_scanmode_none_done, teardown);
4561 test_bredrle("Bluetooth BR/EDR Discovery Start - Success",
4562 &bluetooth_discovery_start_success_test,
4563 setup_enabled_adapter,
4564 test_discovery_start_success, teardown);
4566 test_bredrle("Bluetooth BR/EDR Discovery Start - Success 2",
4567 &bluetooth_discovery_start_success2_test,
4568 setup_enabled_adapter,
4569 test_discovery_start_done, teardown);
4571 test_bredrle("Bluetooth BR/EDR Discovery Stop - Success",
4572 &bluetooth_discovery_stop_success_test,
4573 setup_enabled_adapter,
4574 test_discovery_stop_success, teardown);
4576 test_bredrle("Bluetooth BR/EDR Discovery Stop - Success 2",
4577 &bluetooth_discovery_stop_success2_test,
4578 setup_enabled_adapter,
4579 test_discovery_stop_done, teardown);
4581 test_bredrle("Bluetooth BR/EDR Discovery Device Found",
4582 &bluetooth_discovery_device_found_test,
4583 setup_enabled_adapter,
4584 test_discovery_device_found, teardown);
4586 test_bredrle("Bluetooth Device Get Props - Success",
4587 &bt_dev_getprops_success_test,
4588 setup_enabled_adapter,
4589 test_dev_getprops_success, teardown);
4591 test_bredrle("Bluetooth Device Get BDNAME - Success",
4592 &bt_dev_getprop_bdname_success_test,
4593 setup_enabled_adapter,
4594 test_dev_getprop_bdname_success, teardown);
4596 test_bredrle("Bluetooth Device Get UUIDS - Success",
4597 &bt_dev_getprop_uuids_success_test,
4598 setup_enabled_adapter,
4599 test_dev_getprop_uuids_success, teardown);
4601 test_bredrle("Bluetooth Device Get COD - Success",
4602 &bt_dev_getprop_cod_success_test,
4603 setup_enabled_adapter,
4604 test_dev_getprop_cod_success, teardown);
4606 test_bredrle("Bluetooth Device Get TOD - Success",
4607 &bt_dev_getprop_tod_success_test,
4608 setup_enabled_adapter,
4609 test_dev_getprop_tod_success, teardown);
4611 test_bredrle("Bluetooth Device Get RSSI - Success",
4612 &bt_dev_getprop_rssi_success_test,
4613 setup_enabled_adapter,
4614 test_dev_getprop_rssi_success, teardown);
4616 test_bredrle("Bluetooth Device Get TIMESTAMP - Success",
4617 &bt_dev_getprop_timpestamp_success_test,
4618 setup_enabled_adapter,
4619 test_dev_getprop_timestamp_success, teardown);
4621 test_bredrle("Bluetooth Device Get BDADDR - Fail",
4622 &bt_dev_getprop_bdaddr_fail_test,
4623 setup_enabled_adapter,
4624 test_dev_getprop_bdaddr_fail, teardown);
4626 test_bredrle("Bluetooth Device Get SERVICE_RECORD - Fail",
4627 &bt_dev_getprop_servrec_fail_test,
4628 setup_enabled_adapter,
4629 test_dev_getprop_servrec_fail, teardown);
4631 test_bredrle("Bluetooth Device Get SCAN_MODE - Fail",
4632 &bt_dev_getprop_scanmode_fail_test,
4633 setup_enabled_adapter,
4634 test_dev_getprop_scanmode_fail, teardown);
4636 test_bredrle("Bluetooth Device Get BONDED_DEVICES - Fail",
4637 &bt_dev_getprop_bondeddev_fail_test,
4638 setup_enabled_adapter,
4639 test_dev_getprop_bondeddev_fail, teardown);
4641 test_bredrle("Bluetooth Device Get DISCOVERY_TIMEOUT - Fail",
4642 &bt_dev_getprop_disctimeout_fail_test,
4643 setup_enabled_adapter,
4644 test_dev_getprop_disctimeout_fail, teardown);
4646 test_bredrle("Bluetooth Device Get VERSION_INFO - Fail",
4647 &bt_dev_getprop_verinfo_fail_test,
4648 setup_enabled_adapter,
4649 test_dev_getprop_verinfo_fail, teardown);
4651 test_bredrle("Bluetooth Device Get FRIENDLY_NAME - Fail",
4652 &bt_dev_getprop_fname_fail_test,
4653 setup_enabled_adapter,
4654 test_dev_getprop_fname_fail, teardown);
4656 test_bredrle("Bluetooth Device Set FRIENDLY_NAME - Success",
4657 &bt_dev_setprop_fname_success_test,
4658 setup_enabled_adapter,
4659 test_dev_setprop_fname_success, teardown);
4661 test_bredrle("Bluetooth Device Set BDNAME - Fail",
4662 &bt_dev_setprop_bdname_fail_test,
4663 setup_enabled_adapter,
4664 test_dev_setprop_bdname_fail, teardown);
4666 test_bredrle("Bluetooth Device Set UUIDS - Fail",
4667 &bt_dev_setprop_uuids_fail_test,
4668 setup_enabled_adapter,
4669 test_dev_setprop_uuids_fail, teardown);
4671 test_bredrle("Bluetooth Device Set COD - Fail",
4672 &bt_dev_setprop_cod_fail_test,
4673 setup_enabled_adapter,
4674 test_dev_setprop_cod_fail, teardown);
4676 test_bredrle("Bluetooth Device Set TOD - Fail",
4677 &bt_dev_setprop_tod_fail_test,
4678 setup_enabled_adapter,
4679 test_dev_setprop_tod_fail, teardown);
4681 test_bredrle("Bluetooth Device Set RSSI - Fail",
4682 &bt_dev_setprop_rssi_fail_test,
4683 setup_enabled_adapter,
4684 test_dev_setprop_rssi_fail, teardown);
4686 test_bredrle("Bluetooth Device Set TIMESTAMP - Fail",
4687 &bt_dev_setprop_timpestamp_fail_test,
4688 setup_enabled_adapter,
4689 test_dev_setprop_timestamp_fail, teardown);
4691 test_bredrle("Bluetooth Device Set BDADDR - Fail",
4692 &bt_dev_setprop_bdaddr_fail_test,
4693 setup_enabled_adapter,
4694 test_dev_setprop_bdaddr_fail, teardown);
4696 test_bredrle("Bluetooth Device Set SERVICE_RECORD - Fail",
4697 &bt_dev_setprop_servrec_fail_test,
4698 setup_enabled_adapter,
4699 test_dev_setprop_servrec_fail, teardown);
4701 test_bredrle("Bluetooth Device Set SCAN_MODE - Fail",
4702 &bt_dev_setprop_scanmode_fail_test,
4703 setup_enabled_adapter,
4704 test_dev_setprop_scanmode_fail, teardown);
4706 test_bredrle("Bluetooth Device Set BONDED_DEVICES - Fail",
4707 &bt_dev_setprop_bondeddev_fail_test,
4708 setup_enabled_adapter,
4709 test_dev_setprop_bondeddev_fail, teardown);
4711 test_bredrle("Bluetooth Device Set DISCOVERY_TIMEOUT - Fail",
4712 &bt_dev_setprop_disctimeout_fail_test,
4713 setup_enabled_adapter,
4714 test_dev_setprop_disctimeout_fail, teardown);
4716 test_bredrle("Bluetooth Create Bond PIN - Success",
4717 &bt_bond_create_pin_success_test,
4718 setup_enabled_adapter,
4719 test_bond_create_pin_success, teardown);
4721 test_bredrle("Bluetooth Create Bond PIN - Bad PIN",
4722 &bt_bond_create_pin_fail_test,
4723 setup_enabled_adapter,
4724 test_bond_create_pin_fail, teardown);
4726 test_bredrle("Bluetooth Create Bond SSP - Success",
4727 &bt_bond_create_ssp_success_test,
4728 setup_enabled_adapter,
4729 test_bond_create_ssp_success, teardown);
4731 test_bredrle("Bluetooth Create Bond SSP - Negative reply",
4732 &bt_bond_create_ssp_fail_test,
4733 setup_enabled_adapter,
4734 test_bond_create_ssp_fail, teardown);
4736 test_bredrle("Bluetooth Create Bond - No Discovery",
4737 &bt_bond_create_no_disc_success_test,
4738 setup_enabled_adapter,
4739 test_bond_create_no_disc_success, teardown);
4741 test_bredrle("Bluetooth Create Bond - Bad Address",
4742 &bt_bond_create_bad_addr_success_test,
4743 setup_enabled_adapter,
4744 test_bond_create_bad_addr_success, teardown);
4746 test_bredrle("Bluetooth Cancel Bonding - Success",
4747 &bt_bond_cancel_success_test,
4748 setup_enabled_adapter,
4749 test_bond_cancel_success, teardown);
4751 test_bredrle("Bluetooth Remove Bond - Success",
4752 &bt_bond_remove_success_test,
4753 setup_enabled_adapter,
4754 test_bond_remove_success, teardown);
4756 test_bredrle("Socket Init", NULL, setup_socket_interface,
4757 test_dummy, teardown);
4759 test_bredrle("Socket Listen - Invalid: sock_type 0",
4760 &btsock_inv_param_socktype, setup_socket_interface,
4761 test_generic_listen, teardown);
4763 test_bredrle("Socket Listen - Invalid: sock_type L2CAP",
4764 &btsock_inv_param_socktype_l2cap,
4765 setup_socket_interface, test_generic_listen, teardown);
4767 test_bredrle("Socket Listen - Invalid: chan, uuid",
4768 &btsock_inv_params_chan_uuid,
4769 setup_socket_interface, test_generic_listen, teardown);
4771 test_bredrle("Socket Listen - Check returned fd valid",
4773 setup_socket_interface, test_generic_listen, teardown);
4775 test_bredrle("Socket Listen - Check returned channel",
4776 &btsock_success_check_chan,
4777 setup_socket_interface, test_generic_listen, teardown);
4779 test_bredrle("Socket Listen - Close and Listen again",
4780 &btsock_success_check_chan,
4781 setup_socket_interface, test_listen_close, teardown);
4783 test_bredrle("Socket Listen - Invalid: double Listen",
4784 &btsock_inv_listen_listen,
4785 setup_socket_interface, test_listen_listen, teardown);
4787 test_bredrle("Socket Connect - Check returned fd valid",
4788 &btsock_success, setup_socket_interface,
4789 test_generic_connect, teardown);
4791 test_bredrle("Socket Connect - Invalid: sock_type 0",
4792 &btsock_inv_param_socktype, setup_socket_interface,
4793 test_generic_connect, teardown);
4795 test_bredrle("Socket Connect - Invalid: sock_type L2CAP",
4796 &btsock_inv_param_socktype_l2cap,
4797 setup_socket_interface, test_generic_connect, teardown);
4799 test_bredrle("Socket Connect - Invalid: chan, uuid",
4800 &btsock_inv_params_chan_uuid,
4801 setup_socket_interface, test_generic_connect, teardown);
4803 test_bredrle("Socket Connect - Invalid: bdaddr",
4804 &btsock_inv_param_bdaddr,
4805 setup_socket_interface, test_generic_connect, teardown);
4807 test_bredrle("Socket Connect - Check returned chan",
4808 &btsock_success_check_chan,
4809 setup_socket_interface_enabled,
4810 test_socket_real_connect, teardown);
4812 test_bredrle("HIDHost Init", NULL, setup_hidhost_interface,
4813 test_dummy, teardown);
4815 test_bredrle("HIDHost Connect Success",
4816 NULL, setup_hidhost_connect,
4817 test_dummy, teardown);
4819 test_bredrle("HIDHost Disconnect Success",
4820 &hidhost_test_disconnect, setup_hidhost_connect,
4821 test_hidhost_disconnect, teardown);
4823 test_bredrle("HIDHost VirtualUnplug Success",
4824 &hidhost_test_disconnect, setup_hidhost_connect,
4825 test_hidhost_virtual_unplug, teardown);
4827 test_bredrle("HIDHost GetProtocol Success",
4828 &hidhost_test_get_protocol, setup_hidhost_connect,
4829 test_hidhost_get_protocol, teardown);
4831 test_bredrle("HIDHost SetProtocol Success",
4832 &hidhost_test_get_protocol, setup_hidhost_connect,
4833 test_hidhost_set_protocol, teardown);
4835 test_bredrle("HIDHost GetReport Success",
4836 &hidhost_test_get_report, setup_hidhost_connect,
4837 test_hidhost_get_report, teardown);
4839 test_bredrle("HIDHost SetReport Success",
4840 NULL, setup_hidhost_connect,
4841 test_hidhost_set_report, teardown);
4843 test_bredrle("HIDHost SendData Success",
4844 NULL, setup_hidhost_connect,
4845 test_hidhost_send_data, teardown);
4846 return tester_run();