static void connect_auth_cb(DBusError *derr, void *data) { struct sap_server *server = data; struct sap_connection *conn = server->conn; GError *gerr = NULL; DBG("conn %p", conn); if (!conn) return; if (derr && dbus_error_is_set(derr)) { error("Access has been denied (%s)", derr->message); sap_server_remove_conn(server); return; } if (!bt_io_accept(conn->io, sap_connect_cb, server, NULL, &gerr)) { error("bt_io_accept: %s", gerr->message); g_error_free(gerr); sap_server_remove_conn(server); return; } DBG("Access has been granted."); }
static void connect_confirm_cb(GIOChannel *io, gpointer data) { struct sap_server *server = data; struct sap_connection *conn = server->conn; GError *gerr = NULL; bdaddr_t src, dst; char dstaddr[18]; int err; DBG("conn %p io %p", conn, io); if (!io) return; if (conn) { DBG("Another SAP connection already exists."); g_io_channel_shutdown(io, TRUE, NULL); return; } conn = g_try_new0(struct sap_connection, 1); if (!conn) { error("Can't allocate memory for incoming SAP connection."); g_io_channel_shutdown(io, TRUE, NULL); return; } g_io_channel_set_encoding(io, NULL, NULL); g_io_channel_set_buffered(io, FALSE); server->conn = conn; conn->io = g_io_channel_ref(io); conn->state = SAP_STATE_DISCONNECTED; bt_io_get(io, BT_IO_RFCOMM, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_DEST_BDADDR, &dst, BT_IO_OPT_INVALID); if (gerr) { error("%s", gerr->message); g_error_free(gerr); sap_server_remove_conn(server); return; } ba2str(&dst, dstaddr); err = btd_request_authorization(&src, &dst, SAP_UUID, connect_auth_cb, server); if (err < 0) { error("Authorization failure (err %d)", err); sap_server_remove_conn(server); return; } DBG("Authorizing incoming SAP connection from %s", dstaddr); }
static void sap_io_destroy(void *data) { struct sap_server *server = data; struct sap_connection *conn = server->conn; gboolean connected = FALSE; DBG("conn %p", conn); if (!conn || !conn->io) return; stop_guard_timer(server); if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS && conn->state != SAP_STATE_CONNECT_MODEM_BUSY) emit_property_changed(connection, server->path, SAP_SERVER_INTERFACE, "Connected", DBUS_TYPE_BOOLEAN, &connected); if (conn->state == SAP_STATE_CONNECT_IN_PROGRESS || conn->state == SAP_STATE_CONNECT_MODEM_BUSY || conn->state == SAP_STATE_CONNECTED || conn->state == SAP_STATE_GRACEFUL_DISCONNECT) sap_disconnect_req(server, 1); sap_server_remove_conn(server); }
static void sap_io_destroy(void *data) { struct sap_server *server = data; struct sap_connection *conn = server->conn; DBG("conn %p", conn); if (!conn || !conn->io) return; stop_guard_timer(server); if (conn->state != SAP_STATE_CONNECT_IN_PROGRESS && conn->state != SAP_STATE_CONNECT_MODEM_BUSY) g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter_get_path(server->adapter), SAP_SERVER_INTERFACE, "Connected"); if (conn->state == SAP_STATE_CONNECT_IN_PROGRESS || conn->state == SAP_STATE_CONNECT_MODEM_BUSY || conn->state == SAP_STATE_CONNECTED || conn->state == SAP_STATE_GRACEFUL_DISCONNECT) sap_disconnect_req(server, 1); sap_server_remove_conn(server); }
static void server_remove(struct sap_server *server) { if (!server) return; sap_server_remove_conn(server); remove_record_from_server(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; } g_free(server->path); g_free(server); }
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); }