int
linux_bluez_register_psmove(char *addr)
{
    int errors = 0;

    addr = _psmove_normalize_btaddr(addr, 0, ':');
    if (addr == NULL) {
        printf("Cannot parse bluetooth address!\n");
        return 0;
    }

    char *base = get_bluez_config_base_path();
    if (base == NULL) {
        printf("Can't find Bluetooth directory in '" BLUEZ_CONFIG_DIR "'\n");
        return 0;
    }

    // First, let's check if the entries are already okay..
    errors = for_all_entries(check_entry_in_file, base, addr);

    if (errors) {
        // In this case, we have missing or invalid values and need to update
        // the Bluetooth configuration files and restart Bluez' bluetoothd

        // FIXME: This is Ubuntu-specific
        if (system("service bluetooth stop") != 0) {
            printf("Automatic stopping of bluetoothd failed.\n"
                   "You might have to stop it manually before pairing.\n");
        }

        errors = for_all_entries(write_entry_to_file, base, addr);

        // FIXME: This is Ubuntu-specific
        if (system("service bluetooth start") != 0) {
            printf("Automatic starting of bluetoothd failed.\n"
                   "You might have to start it manually after pairing.\n");
        }

        free(base);
        free(addr);
    }

    return (errors == 0);
}
示例#2
0
static int
linux_bluez_register_psmove(const char *addr, const char *host)
{
    int errors = 0;
    char *base = NULL;
    struct linux_info_t linux_info;

    linux_info_init(&linux_info);

    char *controller_addr = _psmove_normalize_btaddr(addr, 0, ':');
    char *host_addr = _psmove_normalize_btaddr(host, 0, ':');

    if (controller_addr == NULL) {
        LINUXPAIR_DEBUG("Cannot parse controller address: '%s'\n", addr);
        errors++;
        goto cleanup;
    }

    if (host_addr == NULL) {
        LINUXPAIR_DEBUG("Cannot parse host address: '%s'\n", host);
        errors++;
        goto cleanup;
    }

    base = malloc(strlen(BLUEZ_CONFIG_DIR) + strlen(host_addr) + 1);
    strcpy(base, BLUEZ_CONFIG_DIR);
    strcat(base, host_addr);

    struct stat st;
    if (stat(base, &st) != 0 || !S_ISDIR(st.st_mode)) {
        LINUXPAIR_DEBUG("Not a directory: %s\n", base);
        errors++;
        goto cleanup;
    }

#ifdef PSMOVE_BLUEZ5_SUPPORT
    errors = linux_bluez5_register_psmove(&linux_info, controller_addr, base);
    goto cleanup;
#endif

    // First, let's check if the entries are already okay..
    errors = for_all_entries(check_entry_in_file, base, controller_addr);

    if (errors) {
        // In this case, we have missing or invalid values and need to update
        // the Bluetooth configuration files and restart Bluez' bluetoothd

        linux_bluetoothd_control(&linux_info, 0);

        errors = for_all_entries(write_entry_to_file, base, controller_addr);

        linux_bluetoothd_control(&linux_info, 1);
    }

cleanup:
    free(base);
    free(host_addr);
    free(controller_addr);

    return (errors == 0);
}
示例#3
0
int
linux_bluez_register_psmove(char *addr, char *host)
{
    int errors = 0;
    char *base = NULL;

    char *controller_addr = _psmove_normalize_btaddr(addr, 0, ':');
    char *host_addr = _psmove_normalize_btaddr(host, 0, ':');

    if (controller_addr == NULL) {
        LINUXPAIR_DEBUG("Cannot parse controller address: '%s'\n", addr);
        errors++;
        goto cleanup;
    }

    if (host_addr == NULL) {
        LINUXPAIR_DEBUG("Cannot parse host address: '%s'\n", host);
        errors++;
        goto cleanup;
    }

    base = malloc(strlen(BLUEZ_CONFIG_DIR) + strlen(host_addr) + 1);
    strcpy(base, BLUEZ_CONFIG_DIR);
    strcat(base, host_addr);

    struct stat st;
    if (stat(base, &st) != 0 || !S_ISDIR(st.st_mode)) {
        LINUXPAIR_DEBUG("Not a directory: %s\n", base);
        errors++;
        goto cleanup;
    }

    // First, let's check if the entries are already okay..
    errors = for_all_entries(check_entry_in_file, base, controller_addr);

    if (errors) {
        // In this case, we have missing or invalid values and need to update
        // the Bluetooth configuration files and restart Bluez' bluetoothd

        // FIXME: This is Ubuntu-specific
        if (system("service bluetooth stop") != 0) {
            LINUXPAIR_DEBUG("Automatic stopping of bluetoothd failed.\n"
                   "You might have to stop it manually before pairing.\n");
        }

        errors = for_all_entries(write_entry_to_file, base, controller_addr);

        // FIXME: This is Ubuntu-specific
        if (system("service bluetooth start") != 0) {
            LINUXPAIR_DEBUG("Automatic starting of bluetoothd failed.\n"
                   "You might have to start it manually after pairing.\n");
        }
    }

cleanup:
    free(base);
    free(host_addr);
    free(controller_addr);

    return (errors == 0);
}