Exemple #1
1
static void test_pre_setup(const void *test_data)
{
	struct user_data *user = tester_get_data();

	user->hci_ut = bt_hci_new_user_channel(user->index_ut);
	if (!user->hci_ut) {
		tester_warn("Failed to setup upper tester user channel");
		tester_pre_setup_failed();
		return;
	}

	if (!bt_hci_send(user->hci_ut, BT_HCI_CMD_RESET, NULL, 0,
				test_pre_setup_ut_complete, NULL, NULL)) {
		tester_warn("Failed to reset upper tester");
		tester_pre_setup_failed();
		return;
	}
}
Exemple #2
0
static void test_pre_setup_ut_address(const void *data, uint8_t size,
							void *user_data)
{
	struct user_data *user = tester_get_data();
	const struct bt_hci_rsp_read_bd_addr *rsp = data;

	if (rsp->status) {
		tester_warn("Read upper tester address failed (0x%02x)",
								rsp->status);
		tester_pre_setup_failed();
		return;
	}

	memcpy(user->bdaddr_ut, rsp->bdaddr, 6);

	user->hci_lt = bt_hci_new_user_channel(user->index_lt);
	if (!user->hci_lt) {
		tester_warn("Failed to setup lower tester user channel");
		tester_pre_setup_failed();
		return;
	}

	if (!bt_hci_send(user->hci_lt, BT_HCI_CMD_RESET, NULL, 0,
				test_pre_setup_lt_complete, NULL, NULL)) {
		tester_warn("Failed to reset lower tester");
		tester_pre_setup_failed();
		return;
	}
}
Exemple #3
0
static int attach_proto(const char *path, unsigned int proto,
			unsigned int speed, bool flowctl, unsigned int flags)
{
	int fd, dev_id;

	fd = open_serial(path, speed, flowctl);
	if (fd < 0)
		return -1;

	if (ioctl(fd, HCIUARTSETFLAGS, flags) < 0) {
		perror("Failed to set flags");
		close(fd);
		return -1;
	}

	if (ioctl(fd, HCIUARTSETPROTO, proto) < 0) {
		perror("Failed to set protocol");
		close(fd);
		return -1;
	}

	dev_id = ioctl(fd, HCIUARTGETDEVICE);
	if (dev_id < 0) {
		perror("Failed to get device id");
		close(fd);
		return -1;
	}

	printf("Device index %d attached\n", dev_id);

	if (flags & (1 << HCI_UART_RAW_DEVICE)) {
		unsigned int attempts = 6;
		struct bt_hci *hci;

		while (attempts-- > 0) {
			hci = bt_hci_new_user_channel(dev_id);
			if (hci)
				break;

			usleep(250 * 1000);
		}

		if (!hci) {
			fprintf(stderr, "Failed to open HCI user channel\n");
			close(fd);
			return -1;
		}

		bt_hci_send(hci, BT_HCI_CMD_READ_LOCAL_VERSION, NULL, 0,
					local_version_callback, hci,
					(bt_hci_destroy_func_t) bt_hci_unref);
	}

	return fd;
}
static void test_open_failed(const void *test_data)
{
	struct test_data *data = tester_get_data();
	struct bt_hci *hci;

	hci = bt_hci_new_user_channel(data->mgmt_index);
	if (!hci) {
		tester_test_passed();
		return;
	}

	bt_hci_unref(hci);
	tester_test_failed();
}
static void test_open_success(const void *test_data)
{
	struct test_data *data = tester_get_data();
	struct bt_hci *hci;

	data->remove_id = mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED,
					data->mgmt_index,
					index_removed_callback,
					NULL, NULL);

	hci = bt_hci_new_user_channel(data->mgmt_index);
	if (hci) {
		bt_hci_unref(hci);
		return;
	}

	mgmt_unregister(data->mgmt, data->remove_id);
	data->remove_id = 0;

	tester_test_failed();
}
Exemple #6
0
int main(int argc, char *argv[])
{
	bool display_role = false, glasses_role = false;
	uint16_t index = 0;
	const char *str;
	bool use_raw = false;
	int exit_status;

	for (;;) {
		int opt;

		opt = getopt_long(argc, argv, "DGi:rvh", main_options, NULL);
		if (opt < 0)
			break;

		switch (opt) {
		case 'D':
			display_role = true;
			break;
		case 'G':
			glasses_role = true;
			break;
		case 'i':
			if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
				str = optarg + 3;
			else
				str = optarg;
			if (!isdigit(*str)) {
				usage();
				return EXIT_FAILURE;
			}
			index = atoi(str);
			break;
		case 'r':
			use_raw = true;
			break;
		case 'v':
			printf("%s\n", VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage();
			return EXIT_SUCCESS;
		default:
			return EXIT_FAILURE;
		}
	}

	if (argc - optind > 0) {
		fprintf(stderr, "Invalid command line parameters\n");
		return EXIT_FAILURE;
	}

	if (display_role == glasses_role) {
		fprintf(stderr, "Specify either display or glasses role\n");
		return EXIT_FAILURE;
	}

	mainloop_init();

	printf("3D Synchronization Profile testing ver %s\n", VERSION);

	if (use_raw) {
		hci_dev = bt_hci_new_raw_device(index);
		if (!hci_dev) {
			fprintf(stderr, "Failed to open HCI raw device\n");
			return EXIT_FAILURE;
		}
	} else {
		hci_dev = bt_hci_new_user_channel(index);
		if (!hci_dev) {
			fprintf(stderr, "Failed to open HCI user channel\n");
			return EXIT_FAILURE;
		}

		reset_on_init = true;
		reset_on_shutdown = true;
	}

	if (display_role)
		start_display();
	else if (glasses_role)
		start_glasses();

	exit_status = mainloop_run_with_signal(signal_callback, NULL);

	bt_hci_unref(hci_dev);

	return exit_status;
}
Exemple #7
0
static void read_index_list(uint8_t status, uint16_t len, const void *param,
							void *user_data)
{
	const struct mgmt_rp_read_index_list *rp = param;
	uint16_t count;
	int i;

	if (status) {
		fprintf(stderr, "Reading index list failed: %s\n",
						mgmt_errstr(status));
		mainloop_exit_failure();
		return;
	}

	count = le16_to_cpu(rp->num_controllers);

	if (count < 2) {
		fprintf(stderr, "At least 2 controllers are required\n");
		mainloop_exit_failure();
		return;
	}

	for (i = 0; i < count; i++) {
		uint16_t index = cpu_to_le16(rp->index[i]);

		if (index < index1)
			index1 = index;
	}

	for (i = 0; i < count; i++) {
		uint16_t index = cpu_to_le16(rp->index[i]);

		if (index < index2 && index > index1)
			index2 = index;
	}

	printf("Selecting index %u for advertiser\n", index1);
	printf("Selecting index %u for scanner\n", index2);

	crypto = bt_crypto_new();
	if (!crypto) {
		fprintf(stderr, "Failed to open crypto interface\n");
		mainloop_exit_failure();
		return;
	}

	adv_dev = bt_hci_new_user_channel(index1);
	if (!adv_dev) {
		fprintf(stderr, "Failed to open HCI for advertiser\n");
		mainloop_exit_failure();
		return;
	}

	scan_dev = bt_hci_new_user_channel(index2);
	if (!scan_dev) {
		fprintf(stderr, "Failed to open HCI for scanner\n");
		mainloop_exit_failure();
		return;
	}

	bt_hci_register(scan_dev, BT_HCI_EVT_LE_META_EVENT,
					scan_le_meta_event, NULL, NULL);

	bt_hci_send(scan_dev, BT_HCI_CMD_RESET, NULL, 0, NULL, NULL, NULL);

	bt_hci_send(scan_dev, BT_HCI_CMD_READ_LOCAL_FEATURES, NULL, 0,
					scan_features_callback, NULL, NULL);
}
int main(int argc, char *argv[])
{
	uint16_t index = 0;
	const char *str;
	sigset_t mask;
	int exit_status;

	for (;;) {
		int opt;

		opt = getopt_long(argc, argv, "i:vh", main_options, NULL);
		if (opt < 0)
			break;

		switch (opt) {
		case 'i':
			if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
				str = optarg + 3;
			else
				str = optarg;
			if (!isdigit(*str)) {
				usage();
				return EXIT_FAILURE;
			}
			index = atoi(str);
			break;
		case 'v':
			printf("%s\n", VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage();
			return EXIT_SUCCESS;
		default:
			return EXIT_FAILURE;
		}
	}

	if (argc - optind > 0) {
		fprintf(stderr, "Invalid command line parameters\n");
		return EXIT_FAILURE;
	}

	urandom_fd = open("/dev/urandom", O_RDONLY);
	if (urandom_fd < 0) {
		fprintf(stderr, "Failed to open /dev/urandom device\n");
		return EXIT_FAILURE;
	}

	mainloop_init();

	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGTERM);

	mainloop_set_signal(&mask, signal_callback, NULL, NULL);

	printf("Low Energy iBeacon utility ver %s\n", VERSION);

	hci_dev = bt_hci_new_user_channel(index);
	if (!hci_dev) {
		fprintf(stderr, "Failed to open HCI user channel\n");
		exit_status = EXIT_FAILURE;
		goto done;
	}

	start_ibeacon();

	exit_status = mainloop_run();

	bt_hci_unref(hci_dev);

done:
	close(urandom_fd);

	return exit_status;
}
int main(int argc, char *argv[])
{
	cmd_func_t func = NULL;
	uint16_t index = 0;
	const char *str;
	bool use_raw = false;
	bool power_down = false;
	sigset_t mask;
	int fd, i, exit_status;

	for (;;) {
		int opt;

		opt = getopt_long(argc, argv, "i:rRvh", main_options, NULL);
		if (opt < 0)
			break;

		switch (opt) {
		case 'i':
			if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
				str = optarg + 3;
			else
				str = optarg;
			if (!isdigit(*str)) {
				usage();
				return EXIT_FAILURE;
			}
			index = atoi(str);
			break;
		case 'r':
			reset_on_init = true;
			break;
		case 'R':
			use_raw = true;
			break;
		case 'v':
			printf("%s\n", VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage();
			return EXIT_SUCCESS;
		default:
			return EXIT_FAILURE;
		}
	}

	if (argc - optind < 1) {
		fprintf(stderr, "Missing command argument\n");
		return EXIT_FAILURE;
	}

	for (i = 0; cmd_table[i].name; i++) {
		if (!strcmp(cmd_table[i].name, argv[optind])) {
			func = cmd_table[i].func;
			break;
		}
	}

	if (!func) {
		fprintf(stderr, "Unsupported command specified\n");
		return EXIT_FAILURE;
	}

	mainloop_init();

	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGTERM);

	mainloop_set_signal(&mask, signal_callback, NULL, NULL);

	printf("Bluetooth information utility ver %s\n", VERSION);

	fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
	if (fd < 0) {
		perror("Failed to open HCI raw socket");
		return EXIT_FAILURE;
	}

	memset(&hci_info, 0, sizeof(hci_info));
	hci_info.dev_id = index;

	if (ioctl(fd, HCIGETDEVINFO, (void *) &hci_info) < 0) {
		perror("Failed to get HCI device information");
		close(fd);
		return EXIT_FAILURE;
	}

	if (use_raw && !(hci_info.flags & HCI_UP)) {
		printf("Powering on controller\n");

		if (ioctl(fd, HCIDEVUP, hci_info.dev_id) < 0) {
			perror("Failed to power on controller");
			close(fd);
			return EXIT_FAILURE;
		}

		power_down = true;
	}

	close(fd);

	hci_type = (hci_info.type & 0x30) >> 4;

	if (use_raw) {
		hci_dev = bt_hci_new_raw_device(index);
		if (!hci_dev) {
			fprintf(stderr, "Failed to open HCI raw device\n");
			return EXIT_FAILURE;
		}
	} else {
		hci_dev = bt_hci_new_user_channel(index);
		if (!hci_dev) {
			fprintf(stderr, "Failed to open HCI user channel\n");
			return EXIT_FAILURE;
		}

		reset_on_init = true;
		reset_on_shutdown = true;
	}

	if (!func(argc - optind - 1, argv + optind + 1)) {
		bt_hci_unref(hci_dev);
		return EXIT_FAILURE;
	}

	exit_status = mainloop_run();

	bt_hci_unref(hci_dev);

	if (use_raw && power_down) {
		fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
		if (fd >= 0) {
			printf("Powering down controller\n");

			if (ioctl(fd, HCIDEVDOWN, hci_info.dev_id) < 0)
				perror("Failed to power down controller");

			close(fd);
		}
	}

	return exit_status;
}
Exemple #10
0
int main(int argc, char *argv[])
{
    const char *str;
    sigset_t mask;
    int exit_status;

    for (;;) {
        int opt;

        opt = getopt_long(argc, argv, "A::DF::TRi:vh",
                          main_options, NULL);
        if (opt < 0)
            break;

        switch (opt) {
        case 'A':
            if (optarg)
                set_bdaddr_value = optarg;
            set_bdaddr = true;
            break;
        case 'D':
            use_manufacturer_mode = true;
            get_bddata = true;
            break;
        case 'F':
            use_manufacturer_mode = true;
            if (optarg)
                load_firmware_value = optarg;
            load_firmware = true;
            break;
        case 'T':
            use_manufacturer_mode = true;
            set_traces = true;
            break;
        case 'R':
            reset_on_exit = true;
            break;
        case 'i':
            if (strlen(optarg) > 3 && !strncmp(optarg, "hci", 3))
                str = optarg + 3;
            else
                str = optarg;
            if (!isdigit(*str)) {
                usage();
                return EXIT_FAILURE;
            }
            hci_index = atoi(str);
            break;
        case 'v':
            printf("%s\n", VERSION);
            return EXIT_SUCCESS;
        case 'h':
            usage();
            return EXIT_SUCCESS;
        default:
            return EXIT_FAILURE;
        }
    }

    if (argc - optind > 0) {
        fprintf(stderr, "Invalid command line parameters\n");
        return EXIT_FAILURE;
    }

    mainloop_init();

    sigemptyset(&mask);
    sigaddset(&mask, SIGINT);
    sigaddset(&mask, SIGTERM);

    mainloop_set_signal(&mask, signal_callback, NULL, NULL);

    printf("Bluemoon configuration utility ver %s\n", VERSION);

    hci_dev = bt_hci_new_user_channel(hci_index);
    if (!hci_dev) {
        fprintf(stderr, "Failed to open HCI user channel\n");
        return EXIT_FAILURE;
    }

    bt_hci_send(hci_dev, CMD_READ_VERSION, NULL, 0,
                read_version_complete, NULL, NULL);

    exit_status = mainloop_run();

    bt_hci_unref(hci_dev);

    return exit_status;
}