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); }
static void test_pre_setup(const void *test_data) { struct test_data *data = tester_get_data(); data->crypto = bt_crypto_new(); if (!data->crypto) { tester_warn("Failed to setup crypto"); tester_pre_setup_failed(); return; } data->mgmt = mgmt_new_default(); if (!data->mgmt) { tester_warn("Failed to setup management interface"); bt_crypto_unref(data->crypto); tester_pre_setup_failed(); return; } if (tester_use_debug()) mgmt_set_debug(data->mgmt, mgmt_debug, "mgmt: ", NULL); mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL, read_index_list_callback, NULL, NULL); }
static struct btd_advertising * advertising_manager_create(struct btd_adapter *adapter) { struct btd_advertising *manager; manager = new0(struct btd_advertising, 1); if (!manager) return NULL; manager->adapter = adapter; manager->mgmt = mgmt_new_default(); if (!manager->mgmt) { error("Failed to access management interface"); free(manager); return NULL; } manager->mgmt_index = btd_adapter_get_index(adapter); if (!mgmt_send(manager->mgmt, MGMT_OP_READ_ADV_FEATURES, manager->mgmt_index, 0, NULL, read_adv_features_callback, manager, NULL)) { error("Failed to read advertising features"); advertising_manager_destroy(manager); return NULL; } manager->ads = queue_new(); return manager; }
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); }
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; }
static void test_pre_setup(const void *data) { struct test_data *test_data = tester_get_data(); if (!tester_use_debug()) fclose(stderr); test_data->mgmt = mgmt_new_default(); if (!test_data->mgmt) { tester_warn("Failed to setup management interface"); tester_pre_setup_failed(); return; } mgmt_send(test_data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL, read_index_list_callback, NULL, NULL); }
static void mgmt_setup(void) { mgmt_master = mgmt_new_default(); if (!mgmt_master) { DBG("Could not connect to the BT management interface, try with su rights"); } else { mgmt_set_debug(mgmt_master, mgmt_debug, "mgmt: ", NULL); /* For READ_VERSION, it is mandatory to use INDEX_NONE */ if (!mgmt_send(mgmt_master, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL, read_version_complete, NULL, NULL)) { DBG("mgmt_send(MGMT_OP_READ_VERSION) failed"); } if (!mgmt_register(mgmt_master, MGMT_EV_DEVICE_CONNECTED, opt_src_idx, mgmt_device_connected, NULL, NULL)) { DBG("mgmt_register(MGMT_EV_DEVICE_CONNECTED) failed"); } if (!mgmt_register(mgmt_master, MGMT_EV_DEVICE_DISCONNECTED, opt_src_idx, mgmt_device_disconnected, NULL, NULL)) { DBG("mgmt_register(MGMT_EV_DEVICE_DISCONNECTED) failed"); } if (!mgmt_register(mgmt_master, MGMT_EV_DISCOVERING, opt_src_idx, mgmt_scanning, NULL, NULL)) { DBG("mgmt_register(MGMT_EV_DISCOVERING) failed"); } if (!mgmt_register(mgmt_master, MGMT_EV_DEVICE_FOUND, opt_src_idx, mgmt_device_found, NULL, NULL)) { DBG("mgmt_register(MGMT_EV_DEVICE_FOUND) failed"); } } }