return source;
}
-static void create_vhci(struct hciemu *hciemu)
+static bool create_vhci(struct hciemu *hciemu)
{
struct btdev *btdev;
uint8_t bdaddr[6];
btdev = btdev_create(BTDEV_TYPE_BREDR, 0x00);
if (!btdev)
- return;
+ return false;
str = hciemu_get_address(hciemu);
fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
btdev_destroy(btdev);
- return;
+ return false;
}
hciemu->master_dev = btdev;
hciemu->master_source = create_source_btdev(fd, btdev);
+
+ return true;
}
-static void create_stack(struct hciemu *hciemu)
+static bool create_stack(struct hciemu *hciemu)
{
struct btdev *btdev;
struct bthost *bthost;
btdev = btdev_create(BTDEV_TYPE_BREDR, 0x00);
if (!btdev)
- return;
+ return false;
bthost = bthost_create();
if (!bthost) {
btdev_destroy(btdev);
- return;
+ return false;
}
btdev_set_command_handler(btdev, client_command_callback, hciemu);
0, sv) < 0) {
bthost_destroy(bthost);
btdev_destroy(btdev);
- return;
+ return false;
}
hciemu->client_dev = btdev;
hciemu->client_source = create_source_btdev(sv[0], btdev);
hciemu->host_source = create_source_bthost(sv[1], bthost);
+
+ return true;
}
static gboolean start_stack(gpointer user_data)
if (!hciemu)
return NULL;
- create_vhci(hciemu);
- create_stack(hciemu);
+ if (!create_vhci(hciemu)) {
+ g_free(hciemu);
+ return NULL;
+ }
+
+ if (!create_stack(hciemu)) {
+ g_source_remove(hciemu->master_source);
+ btdev_destroy(hciemu->master_dev);
+ g_free(hciemu);
+ return NULL;
+ }
g_idle_add(start_stack, hciemu);
index_removed_callback, NULL, NULL);
data->hciemu = hciemu_new();
+ if (!data->hciemu) {
+ tester_warn("Failed to setup HCI emulation");
+ tester_pre_setup_failed();
+ }
}
static void test_pre_setup(const void *test_data)