static void index_removed_callback(uint16_t index, uint16_t length,
					const void *param, void *user_data)
{
	struct test_data *data = tester_get_data();

	tester_print("Index Removed callback");
	tester_print("  Index: 0x%04x", index);

	if (index != data->mgmt_index)
		return;

	if (data->remove_id) {
		mgmt_unregister(data->mgmt, data->remove_id);
		data->remove_id = 0;
		tester_test_passed();
		return;
	}

	mgmt_unregister_index(data->mgmt, data->mgmt_index);

	mgmt_unref(data->mgmt);
	data->mgmt = NULL;

	tester_post_teardown_complete();
}
Beispiel #2
0
struct bt_gap *bt_gap_new_index(uint16_t index)
{
	struct bt_gap *gap;

	if (index == MGMT_INDEX_NONE)
		return NULL;

	gap = new0(struct bt_gap, 1);
	gap->index = index;

	gap->mgmt = mgmt_new_default();
	if (!gap->mgmt) {
		free(gap);
		return NULL;
	}

	gap->irk_list = queue_new();
	gap->mgmt_ready = false;

	if (!mgmt_send(gap->mgmt, MGMT_OP_READ_VERSION,
					MGMT_INDEX_NONE, 0, NULL,
					read_version_complete, gap, NULL)) {
		mgmt_unref(gap->mgmt);
		return NULL;
	}

	return bt_gap_ref(gap);
}
Beispiel #3
0
struct bt_gap *bt_gap_new(void)
{
	struct bt_gap *gap;

	gap = new0(struct bt_gap, 1);
	if (!gap)
		return NULL;

	gap->mgmt = mgmt_new_default();
	if (!gap->mgmt) {
		free(gap);
		return NULL;
	}

	gap->mgmt_ready = false;

	if (!mgmt_send(gap->mgmt, MGMT_OP_READ_VERSION,
					MGMT_INDEX_NONE, 0, NULL,
					read_version_complete, gap, NULL)) {
		mgmt_unref(gap->mgmt);
		return NULL;
	}

	return bt_gap_ref(gap);
}
Beispiel #4
0
int main(int argc ,char *argv[])
{
	int exit_status;

	for (;;) {
		int opt;

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

		switch (opt) {
		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();

	mgmt = mgmt_new_default();
	if (!mgmt) {
		fprintf(stderr, "Failed to open management socket\n");
		return EXIT_FAILURE;
	}

	if (!mgmt_send(mgmt, MGMT_OP_READ_INDEX_LIST,
					MGMT_INDEX_NONE, 0, NULL,
					read_index_list, NULL, NULL)) {
		fprintf(stderr, "Failed to read index list\n");
		exit_status = EXIT_FAILURE;
		goto done;
	}

	exit_status = mainloop_run_with_signal(signal_callback, NULL);

	bt_hci_unref(adv_dev);
	bt_hci_unref(scan_dev);

	bt_crypto_unref(crypto);

done:
	mgmt_unref(mgmt);

	return exit_status;
}
Beispiel #5
0
static void advertising_manager_destroy(void *user_data)
{
	struct btd_advertising *manager = user_data;

	queue_destroy(manager->ads, advertisement_destroy);

	mgmt_unref(manager->mgmt);

	free(manager);
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    GIOChannel *pchan;
    gint events;
    const char *hci = "hci0";

    opt_sec_level = g_strdup("low");

    if (argc > 1)
        hci = argv[1];

    if (parse_dev_src(hci, &opt_src, &opt_src_idx)) {
        fprintf(stderr,"%s: expected optional argument 'hciX' valid and up\n", argv[0]);
        resp_error(err_BAD_HCI);
        return EXIT_FAILURE;
    }

    DBG("Using controller hci%d  addr:%s", opt_src_idx, opt_src);

    opt_dst = NULL;
    opt_dst_type = g_strdup("public");

    DBG(__FILE__ " built at " __TIME__ " on " __DATE__);

    mgmt_setup();

    event_loop = g_main_loop_new(NULL, FALSE);

    pchan = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_close_on_unref(pchan, TRUE);
    events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
    g_io_add_watch(pchan, events, prompt_read, NULL);

    DBG("Starting loop");
    g_main_loop_run(event_loop);

    DBG("Exiting loop");
    cmd_disconnect(0, NULL);
    fflush(stdout);
    g_io_channel_unref(pchan);
    g_main_loop_unref(event_loop);

    g_free(opt_src);
    g_free(opt_dst);
    g_free(opt_dst_type);
    g_free(opt_sec_level);

    mgmt_unregister_index(mgmt_master, opt_src_idx);
    mgmt_cancel_index(mgmt_master, opt_src_idx);
    mgmt_unref(mgmt_master);
    mgmt_master = NULL;

    return EXIT_SUCCESS;
}
Beispiel #7
0
int main(int argc, char *argv[])
{

    GIOChannel *pchan;
    gint events;

    opt_sec_level = g_strdup("low");

    opt_src = NULL;
    //opt_dst = NULL;
    opt_dst_type = g_strdup("public");

    event_loop = g_main_loop_new(NULL, FALSE);

    pchan = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_close_on_unref(pchan, TRUE);
    events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
    g_io_add_watch(pchan, events, prompt_read, NULL);
    GError *gerr = NULL;
    printf("Connecting to.. %s\n", argv[1]);
    iochannel = gatt_connect(opt_src, argv[1], opt_dst_type, opt_sec_level, opt_psm, opt_mtu, connect_cb, &gerr);
       if (iochannel == NULL)
    {
        g_error_free(gerr);
        }
    else
        g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL);
    g_main_loop_run(event_loop);

    fflush(stdout);
    g_io_channel_unref(pchan);
    g_main_loop_unref(event_loop);

    g_free(opt_src);
    //g_free(opt_dst);
    g_free(opt_sec_level);

    mgmt_unregister_index(mgmt_master, mgmt_ind);
    mgmt_cancel_index(mgmt_master, mgmt_ind);
    mgmt_unref(mgmt_master);
    mgmt_master = NULL;

    return EXIT_SUCCESS;
}
Beispiel #8
0
void bt_gap_unref(struct bt_gap *gap)
{
	if (!gap)
		return;

	if (__sync_sub_and_fetch(&gap->ref_count, 1))
		return;

	gap->mgmt_ready = false;

	mgmt_cancel_all(gap->mgmt);
	mgmt_unregister_all(gap->mgmt);

	if (gap->ready_destroy)
		gap->ready_destroy(gap->ready_data);

	mgmt_unref(gap->mgmt);

	free(gap);
}