Esempio n. 1
0
static gboolean confirm_timeout(gpointer user_data)
{
	struct io_data *data = user_data;

	if (data->reject >= 0) {
		printf("Rejecting connection\n");
		g_io_channel_shutdown(data->io, TRUE, NULL);
		return FALSE;
	}

	printf("Accepting connection\n");

	io_data_ref(data);

	if (opt_update_sec > 0)
		update_sec_level(data);

	if (!bt_io_accept(data->io, connect_cb, data,
				(GDestroyNotify) io_data_unref, NULL)) {
		printf("bt_io_accept() failed\n");
		io_data_unref(data);
	}

	return FALSE;
}
Esempio n. 2
0
static void connect_auth_cb(DBusError *derr, void *data)
{
	struct sap_connection *conn = data;
	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_conn_remove(conn);
		return;
	}

	if (!bt_io_accept(conn->io, sap_connect_cb, conn, NULL, &gerr)) {
		error("bt_io_accept: %s", gerr->message);
		g_error_free(gerr);
		sap_conn_remove(conn);
		return;
	}

	DBG("Access has been granted.");
}
Esempio n. 3
0
static void headset_auth_cb(DBusError *derr, void *user_data)
{
	struct audio_device *device = user_data;
	GError *err = NULL;
	GIOChannel *io;

	if (device->hs_preauth_id) {
		g_source_remove(device->hs_preauth_id);
		device->hs_preauth_id = 0;
	}

	if (derr && dbus_error_is_set(derr)) {
		error("Access denied: %s", derr->message);
		headset_set_state(device, HEADSET_STATE_DISCONNECTED);
		return;
	}

	io = headset_get_rfcomm(device);

	if (!bt_io_accept(io, headset_connect_cb, device, NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		headset_set_state(device, HEADSET_STATE_DISCONNECTED);
		return;
	}
}
Esempio n. 4
0
static void auth_cb(DBusError *derr, void *user_data)
{
	struct avctp *session = user_data;
	GError *err = NULL;

	session->auth_id = 0;

	if (session->control->watch > 0) {
		g_source_remove(session->control->watch);
		session->control->watch = 0;
	}

	if (derr && dbus_error_is_set(derr)) {
		error("Access denied: %s", derr->message);
		avctp_set_state(session, AVCTP_STATE_DISCONNECTED);
		return;
	}

	if (!bt_io_accept(session->control->io, avctp_connect_cb, session,
								NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		avctp_set_state(session, AVCTP_STATE_DISCONNECTED);
	}
}
Esempio n. 5
0
static void search_cb(sdp_list_t *recs, int err, gpointer data)
{
	struct avrcp_device *dev = data;
	sdp_list_t *list;

	DBG("");

	if (err < 0) {
		error("Unable to get AV_REMOTE_SVCLASS_ID SDP record: %s",
							strerror(-err));
		goto fail;
	}

	if (!recs || !recs->data) {
		error("No AVRCP records found");
		goto fail;
	}

	for (list = recs; list; list = list->next) {
		sdp_record_t *rec = list->data;
		sdp_list_t *l;
		sdp_profile_desc_t *desc;
		int features;

		if (sdp_get_profile_descs(rec, &l) < 0)
			continue;

		desc = l->data;
		dev->version = desc->version;

		if (sdp_get_int_attr(rec, SDP_ATTR_SUPPORTED_FEATURES,
							&features) == 0)
			dev->features = features;

		sdp_list_free(l, free);
		break;
	}

	if (dev->io) {
		GError *gerr = NULL;
		if (!bt_io_accept(dev->io, connect_cb, dev, NULL, &gerr)) {
			error("bt_io_accept: %s", gerr->message);
			g_error_free(gerr);
			goto fail;
		}
		return;
	}

	if (!avrcp_device_connect(dev, connect_cb)) {
		error("Unable to connect to AVRCP");
		goto fail;
	}

	return;

fail:
	avrcp_device_remove(dev);
}
Esempio n. 6
0
void gateway_start_service(struct audio_device *dev)
{
	struct gateway *gw = dev->gateway;
	GError *err = NULL;

	if (gw->rfcomm == NULL)
		return;

	if (!bt_io_accept(gw->rfcomm, rfcomm_connect_cb, dev, NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
	}
}
Esempio n. 7
0
static void confirm_cb(GIOChannel *io, gpointer user_data)
{
	char addr[18];
	struct io_data *data = user_data;
	GError *err = NULL;

	if (!bt_io_get(io, &err, BT_IO_OPT_DEST, addr, BT_IO_OPT_INVALID)) {
		printf("bt_io_get(OPT_DEST): %s\n", err->message);
		g_clear_error(&err);
	} else
		printf("Got confirmation request for %s\n", addr);

	if (data->accept < 0 && data->reject < 0)
		return;

	if (data->reject == 0) {
		printf("Rejecting connection\n");
		g_io_channel_shutdown(io, TRUE, NULL);
		return;
	}

	if (data->voice) {
		if (!bt_io_set(io, &err, BT_IO_OPT_VOICE, data->voice,
							BT_IO_OPT_INVALID)) {
			printf("bt_io_set(OPT_VOICE): %s\n", err->message);
			g_clear_error(&err);
		}
	}

	data->io = g_io_channel_ref(io);
	io_data_ref(data);

	if (data->accept == 0) {
		if (!bt_io_accept(io, connect_cb, data,
					(GDestroyNotify) io_data_unref,
					&err)) {
			printf("bt_io_accept() failed: %s\n", err->message);
			g_clear_error(&err);
			io_data_unref(data);
			return;
		}
	} else {
		int seconds = (data->reject > 0) ?
						data->reject : data->accept;
		g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, seconds,
					confirm_timeout, data,
					(GDestroyNotify) io_data_unref);
	}
}
Esempio n. 8
0
static gboolean server_accept(struct input_server *server)
{
	GError *err = NULL;

	DBG("");

	if (!bt_io_accept(server->pending_accept.chan, connect_event_cb,
				server, NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		return FALSE;
	}

	return TRUE;
}
Esempio n. 9
0
static void nap_confirm_cb(GIOChannel *chan, gpointer data)
{
    struct pan_device *dev;
    bdaddr_t dst;
    char address[18];
    GError *err = NULL;

    DBG("");

    bt_io_get(chan, &err, BT_IO_OPT_DEST_BDADDR, &dst,
              BT_IO_OPT_DEST, address, BT_IO_OPT_INVALID);
    if (err) {
        error("%s", err->message);
        g_error_free(err);
        return;
    }

    DBG("incoming connect request from %s", address);
    dev = g_new0(struct pan_device, 1);
    bacpy(&dev->dst, &dst);
    local_role = HAL_PAN_ROLE_NAP;
    dev->role = HAL_PAN_ROLE_PANU;

    strncpy(dev->iface, BNEP_NAP_INTERFACE, 16);
    dev->iface[15] = '\0';

    dev->io = g_io_channel_ref(chan);
    g_io_channel_set_close_on_unref(dev->io, TRUE);

    if (!bt_io_accept(dev->io, nap_connect_cb, dev, NULL, &err)) {
        error("bt_io_accept: %s", err->message);
        g_error_free(err);
        goto failed;
    }

    devices = g_slist_append(devices, dev);
    bt_pan_notify_conn_state(dev, HAL_PAN_STATE_CONNECTING);

    return;

failed:
    bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
}
static void auth_callback(DBusError *derr, void *user_data)
{
	struct input_server *server = user_data;
	bdaddr_t src, dst;
	GError *err = NULL;

	bt_io_get(server->confirm, &err,
			BT_IO_OPT_SOURCE_BDADDR, &src,
			BT_IO_OPT_DEST_BDADDR, &dst,
			BT_IO_OPT_INVALID);
	if (err) {
		error("%s", err->message);
		g_error_free(err);
		goto reject;
	}

	if (derr) {
		error("Access denied: %s", derr->message);
		goto reject;
	}

	if (!input_device_exists(&src, &dst) && !dev_is_sixaxis(&src, &dst))
		return;

	if (!bt_io_accept(server->confirm, connect_event_cb, server,
				NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		goto reject;
	}

	g_io_channel_unref(server->confirm);
	server->confirm = NULL;

	return;

reject:
	g_io_channel_shutdown(server->confirm, TRUE, NULL);
	g_io_channel_unref(server->confirm);
	server->confirm = NULL;
	input_device_close_channels(&src, &dst);
}
Esempio n. 11
0
static void avctp_browsing_confirm(struct avctp *session, GIOChannel *chan,
						struct audio_device *dev)
{
	GError *err = NULL;

	if (session->control == NULL || session->browsing != NULL) {
		error("Browsing: Refusing unexpected connect");
		g_io_channel_shutdown(chan, TRUE, NULL);
		return;
	}

	if (bt_io_accept(chan, avctp_connect_browsing_cb, session, NULL,
								&err))
		return;

	error("Browsing: %s", err->message);
	g_error_free(err);

	return;
}
Esempio n. 12
0
static void auth_cb(DBusError *derr, void *user_data)
{
	struct dun_server *server = user_data;
	GError *err = NULL;

	if (derr && dbus_error_is_set(derr)) {
		error("DUN access denied: %s", derr->message);
		goto drop;
	}

	if (!bt_io_accept(server->client, connect_cb, server, NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		goto drop;
	}

	return;

drop:
	disconnect(server);
}
Esempio n. 13
0
static void auth_cb(DBusError *derr, void *user_data)
{
	struct control *control = user_data;
	GError *err = NULL;

	if (control->io_id) {
		g_source_remove(control->io_id);
		control->io_id = 0;
	}

	if (derr && dbus_error_is_set(derr)) {
		error("Access denied: %s", derr->message);
		avctp_set_state(control, AVCTP_STATE_DISCONNECTED);
		return;
	}

	if (!bt_io_accept(control->io, avctp_connect_cb, control,
								NULL, &err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		avctp_set_state(control, AVCTP_STATE_DISCONNECTED);
	}
}
Esempio n. 14
0
static void auth_cb(DBusError *derr, void *user_data)
{
	struct network_adapter *na = user_data;
	GError *err = NULL;

	if (derr) {
		error("Access denied: %s", derr->message);
		goto reject;
	}

	if (!bt_io_accept(na->setup->io, connect_event, na, NULL,
							&err)) {
		error("bt_io_accept: %s", err->message);
		g_error_free(err);
		goto reject;
	}

	return;

reject:
	g_io_channel_shutdown(na->setup->io, TRUE, NULL);
	setup_destroy(na);
}
Esempio n. 15
0
static void ext_auth(DBusError *err, void *user_data)
{
	struct ext_io *conn = user_data;
	struct ext_profile *ext = conn->ext;
	GError *gerr = NULL;
	char addr[18];

	conn->auth_id = 0;

	bt_io_get(conn->io, &gerr, BT_IO_OPT_DEST, addr, BT_IO_OPT_INVALID);
	if (gerr != NULL) {
		error("Unable to get connect data for %s: %s",
						ext->name, err->message);
		g_error_free(gerr);
		goto drop;
	}

	if (err && dbus_error_is_set(err)) {
		error("%s rejected %s: %s", ext->name, addr, err->message);
		goto drop;
	}

	if (!bt_io_accept(conn->io, ext_connect, conn, NULL, &gerr)) {
		error("bt_io_accept: %s", gerr->message);
		g_error_free(gerr);
		goto drop;
	}

	DBG("%s authorized to connect to %s", addr, ext->name);

	return;

drop:
	ext->conns = g_slist_remove(ext->conns, conn);
	ext_io_destroy(conn);
}
Esempio n. 16
0
static void avctp_browsing_confirm(struct avctp *session, GIOChannel *chan,
						struct btd_device *dev)
{
	GError *err = NULL;

	if (session->control == NULL || session->browsing != NULL) {
		error("Browsing: Refusing unexpected connect");
		g_io_channel_shutdown(chan, TRUE, NULL);
		return;
	}

	if (bt_io_accept(chan, avctp_connect_browsing_cb, session, NULL,
								&err)) {
		avctp_set_state(session, AVCTP_STATE_BROWSING_CONNECTING, 0);
		session->browsing = avctp_channel_create(session, chan, 1,
							avctp_destroy_browsing);
		return;
	}

	error("Browsing: %s", err->message);
	g_error_free(err);

	return;
}
Esempio n. 17
0
static void auth_cb(DBusError *derr, void *user_data)
{
    struct serial_proxy *prx = user_data;
    GError *err = NULL;

    if (derr) {
        error("Access denied: %s", derr->message);
        goto reject;
    }

    if (!bt_io_accept(prx->rfcomm, connect_event_cb, prx, NULL,
                      &err)) {
        error("bt_io_accept: %s", err->message);
        g_error_free(err);
        goto reject;
    }

    return;

reject:
    g_io_channel_shutdown(prx->rfcomm, TRUE, NULL);
    g_io_channel_unref(prx->rfcomm);
    prx->rfcomm = NULL;
}
Esempio n. 18
0
static void confirm_sco_cb(GIOChannel *chan, gpointer user_data)
{
	char address[18];
	bdaddr_t bdaddr;
	GError *err = NULL;
	struct bt_sco *sco = user_data;
	uint16_t voice_settings;

	DBG("");

	bt_io_get(chan, &err,
			BT_IO_OPT_DEST, address,
			BT_IO_OPT_DEST_BDADDR, &bdaddr,
			BT_IO_OPT_INVALID);
	if (err) {
		error("sco: audio confirm failed (%s)", err->message);
		g_error_free(err);
		goto drop;
	}

	if (!sco->confirm_cb || !sco->connect_cb) {
		error("sco: Connect and/or confirm callback not registered ");
		goto drop;
	}

	/* Check if there is SCO */
	if (sco->io) {
		error("sco: SCO is in progress");
		goto drop;
	}

	if (!sco->confirm_cb(&bdaddr, &voice_settings)) {
		error("sco: Audio connection from %s rejected", address);
		goto drop;
	}

	bacpy(&sco->remote_addr, &bdaddr);

	DBG("Incoming SCO connection from %s, voice settings 0x%x", address,
								voice_settings);

	err = NULL;
	bt_io_set(chan, &err, BT_IO_OPT_VOICE, voice_settings,
							BT_IO_OPT_INVALID);
	if (err) {
		error("sco: Could not set voice settings (%s)", err->message);
		g_error_free(err);
		goto drop;
	}

	if (!bt_io_accept(chan, connect_sco_cb, sco, NULL, NULL)) {
		error("sco: Failed to accept audio connection");
		goto drop;
	}

	sco->io = g_io_channel_ref(chan);

	return;

drop:
	g_io_channel_shutdown(chan, TRUE, NULL);
}