static void manager_remove_adapter(struct btd_adapter *adapter) { uint16_t dev_id = adapter_get_dev_id(adapter); const gchar *path = adapter_get_path(adapter); adapters = g_slist_remove(adapters, adapter); manager_update_adapters(); if (default_adapter_id == dev_id || default_adapter_id < 0) { int new_default = hci_get_route(NULL); manager_set_default_adapter(new_default); } g_dbus_emit_signal(connection, "/", MANAGER_INTERFACE, "AdapterRemoved", DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); adapter_remove(adapter); btd_adapter_unref(adapter); if (adapters == NULL) btd_start_exit_timer(); }
static void hid_server_remove(struct btd_profile *p, struct btd_adapter *adapter) { server_stop(adapter_get_address(adapter)); adapters = g_slist_remove(adapters, adapter); btd_adapter_unref(adapter); }
static void adapter_free(struct network_adapter *na) { if (na->io != NULL) { g_io_channel_shutdown(na->io, TRUE, NULL); g_io_channel_unref(na->io); } setup_destroy(na); btd_adapter_unref(na->adapter); g_free(na); }
static void hid_server_remove(struct btd_adapter *adapter) { bdaddr_t src; adapter_get_address(adapter, &src); server_stop(&src); adapters = g_slist_remove(adapters, adapter); btd_adapter_unref(adapter); }
static void audio_adapter_unref(struct audio_adapter *adp) { adp->ref--; DBG("%p: ref=%d", adp, adp->ref); if (adp->ref > 0) return; adapters = g_slist_remove(adapters, adp); btd_adapter_unref(adp->btd_adapter); g_free(adp); }
void manager_cleanup(DBusConnection *conn, const char *path) { while (adapters) { struct btd_adapter *adapter = adapters->data; adapters = g_slist_remove(adapters, adapter); adapter_remove(adapter); btd_adapter_unref(adapter); } btd_start_exit_timer(); g_dbus_unregister_interface(conn, "/", MANAGER_INTERFACE); }
static void alert_server_remove(struct btd_profile *p, struct btd_adapter *adapter) { struct alert_adapter *al_adapter; al_adapter = find_alert_adapter(adapter); if (!al_adapter) return; alert_adapters = g_slist_remove(alert_adapters, al_adapter); btd_adapter_unref(al_adapter->adapter); g_free(al_adapter); }
static void gatt_example_adapter_free(struct gatt_example_adapter *gadapter) { while (gadapter->sdp_handles != NULL) { uint32_t handle = GPOINTER_TO_UINT(gadapter->sdp_handles->data); attrib_free_sdp(handle); gadapter->sdp_handles = g_slist_remove(gadapter->sdp_handles, gadapter->sdp_handles->data); } if (gadapter->adapter != NULL) btd_adapter_unref(gadapter->adapter); g_free(gadapter); }
static void path_free(void *data) { struct media_adapter *adapter = data; while (adapter->endpoints) release_endpoint(adapter->endpoints->data); while (adapter->players) media_player_destroy(adapter->players->data); adapters = g_slist_remove(adapters, adapter); btd_adapter_unref(adapter->btd_adapter); g_free(adapter); }
struct btd_adapter *btd_manager_register_adapter(int id, gboolean up) { struct btd_adapter *adapter; const char *path; adapter = manager_find_adapter_by_id(id); if (adapter) { error("Unable to register adapter: hci%d already exist", id); return NULL; } adapter = adapter_create(connection, id); if (!adapter) return NULL; adapters = g_slist_append(adapters, adapter); if (!adapter_init(adapter, up)) { adapters = g_slist_remove(adapters, adapter); btd_adapter_unref(adapter); return NULL; } path = adapter_get_path(adapter); g_dbus_emit_signal(connection, "/", MANAGER_INTERFACE, "AdapterAdded", DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); manager_update_adapters(); btd_stop_exit_timer(); if (default_adapter_id < 0) manager_set_default_adapter(id); if (main_opts.did_source) btd_adapter_set_did(adapter, main_opts.did_vendor, main_opts.did_product, main_opts.did_version, main_opts.did_source); DBG("Adapter %s registered", path); return btd_adapter_ref(adapter); }
static void server_remove(struct sap_server *server) { if (!server) return; sap_server_remove_conn(server); adapter_service_remove(server->adapter, server->record_id); if (server->listen_io) { g_io_channel_shutdown(server->listen_io, TRUE, NULL); g_io_channel_unref(server->listen_io); server->listen_io = NULL; } btd_adapter_unref(server->adapter); g_free(server); }
static void path_unregister(void *data) { DBusConnection *conn = btd_get_dbus_connection(); struct service_adapter *serv_adapter = data; GSList *l, *next = NULL; for (l = serv_adapter->records; l != NULL; l = next) { struct record_data *user_record = l->data; next = l->next; g_dbus_remove_watch(conn, user_record->listener_id); exit_callback(conn, user_record); } if (serv_adapter->adapter != NULL) btd_adapter_unref(serv_adapter->adapter); g_free(serv_adapter); }
void avctp_unregister(struct btd_adapter *adapter) { struct avctp_server *server; server = find_server(servers, adapter); if (!server) return; while (server->sessions) avctp_disconnected(server->sessions->data); servers = g_slist_remove(servers, server); g_io_channel_shutdown(server->browsing_io, TRUE, NULL); g_io_channel_unref(server->browsing_io); server->browsing_io = NULL; g_io_channel_shutdown(server->control_io, TRUE, NULL); g_io_channel_unref(server->control_io); btd_adapter_unref(server->adapter); g_free(server); }
static void manager_path_unregister(void *data) { struct serial_adapter *adapter = data; GSList *l; /* Remove proxy objects */ for (l = adapter->proxies; l; l = l->next) { struct serial_proxy *prx = l->data; char *path = g_strdup(prx->path); g_dbus_unregister_interface(adapter->conn, path, SERIAL_PROXY_INTERFACE); g_free(path); } if (adapter->conn) dbus_connection_unref(adapter->conn); adapters = g_slist_remove(adapters, adapter); g_slist_free(adapter->proxies); btd_adapter_unref(adapter->btd_adapter); g_free(adapter); }
static void ext_io_destroy(gpointer p) { struct ext_io *ext_io = p; struct ext_profile *ext = ext_io->ext; if (ext_io->io_id > 0) g_source_remove(ext_io->io_id); if (ext_io->io) { g_io_channel_shutdown(ext_io->io, FALSE, NULL); g_io_channel_unref(ext_io->io); } if (ext_io->auth_id != 0) btd_cancel_authorization(ext_io->auth_id); if (ext_io->new_conn) { dbus_pending_call_cancel(ext_io->new_conn); dbus_pending_call_unref(ext_io->new_conn); ext_cancel(ext); } if (ext_io->resolving) bt_cancel_discovery(adapter_get_address(ext_io->adapter), device_get_address(ext_io->device)); if (ext_io->rec_handle) remove_record_from_server(ext_io->rec_handle); if (ext_io->adapter) btd_adapter_unref(ext_io->adapter); if (ext_io->device) btd_device_unref(ext_io->device); g_free(ext_io); }
static void read_info_complete(int sk, void *buf, size_t len) { struct mgmt_rp_read_info *rp = buf; struct controller_info *info; struct btd_adapter *adapter; uint8_t mode; uint16_t index; char addr[18]; if (len < sizeof(*rp)) { error("Too small read info complete event"); return; } index = btohs(bt_get_unaligned(&rp->index)); if (index > max_index) { error("Unexpected index %u in read info complete", index); return; } mgmt_set_mode(index, MGMT_OP_SET_SERVICE_CACHE, 1); info = &controllers[index]; info->type = rp->type; info->enabled = rp->powered; info->connectable = rp->connectable; info->discoverable = rp->discoverable; info->pairable = rp->pairable; info->sec_mode = rp->sec_mode; bacpy(&info->bdaddr, &rp->bdaddr); memcpy(info->dev_class, rp->dev_class, 3); memcpy(info->features, rp->features, 8); info->manufacturer = btohs(bt_get_unaligned(&rp->manufacturer)); info->hci_ver = rp->hci_ver; info->hci_rev = btohs(bt_get_unaligned(&rp->hci_rev)); ba2str(&info->bdaddr, addr); DBG("hci%u type %u addr %s", index, info->type, addr); DBG("hci%u class 0x%02x%02x%02x", index, info->dev_class[2], info->dev_class[1], info->dev_class[0]); DBG("hci%u manufacturer %d HCI ver %d:%d", index, info->manufacturer, info->hci_ver, info->hci_rev); DBG("hci%u enabled %u discoverable %u pairable %u sec_mode %u", index, info->enabled, info->discoverable, info->pairable, info->sec_mode); adapter = btd_manager_register_adapter(index); if (adapter == NULL) { error("mgmtops: unable to register adapter"); return; } btd_adapter_get_mode(adapter, &mode, NULL, NULL); if (mode == MODE_OFF) { mgmt_set_powered(index, FALSE); return; } if (info->enabled) mgmt_update_powered(index, TRUE); else mgmt_set_powered(index, TRUE); btd_adapter_unref(adapter); }