Example #1
0
static gboolean system_bus_reconnect(void *data)
{
    DBusConnection *conn = get_dbus_connection();
    struct hci_dev_list_req *dl = NULL;
    struct hci_dev_req *dr;
    int sk, i;
    gboolean ret_val = TRUE;

    if (conn) {
        if (dbus_connection_get_is_connected(conn))
            return FALSE;
    }

    if (hcid_dbus_init() < 0)
        return TRUE;

    /* Create and bind HCI socket */
    sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
    if (sk < 0) {
        error("Can't open HCI socket: %s (%d)",
              strerror(errno), errno);
        return TRUE;
    }

    dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));

    dl->dev_num = HCI_MAX_DEV;
    dr = dl->dev_req;

    if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
        info("Can't get device list: %s (%d)",
             strerror(errno), errno);
        goto failed;
    }

    /* reset the default device */
    manager_set_default_adapter(-1);

    /* FIXME: it shouldn't be needed to register adapters again */
    for (i = 0; i < dl->dev_num; i++, dr++)
        manager_register_adapter(dr->dev_id, TRUE);

    ret_val = FALSE;

failed:
    if (sk >= 0)
        close(sk);

    g_free(dl);

    return ret_val;
}
Example #2
0
static void device_devreg_setup(int index)
{
	struct hci_dev_info di;
	gboolean devup;

	init_device(index);

	memset(&di, 0, sizeof(di));

	if (hci_devinfo(index, &di) < 0)
		return;

	devup = hci_test_bit(HCI_UP, &di.flags);

	if (!hci_test_bit(HCI_RAW, &di.flags))
		manager_register_adapter(index, devup);
}