Beispiel #1
0
static DBusMessage *start_poll_loop(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct near_adapter *adapter = data;
	const char *dbus_mode;
	int err;

	DBG("conn %p", conn);

	if (!adapter->powered) {
		near_error("Adapter is down, can not start polling");
		return __near_error_failed(msg, ENODEV);
	}

	dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dbus_mode,
							DBUS_TYPE_INVALID);

	DBG("Mode %s", dbus_mode);

	if (g_strcmp0(dbus_mode, "Initiator") == 0)
		adapter->poll_mode = NEAR_ADAPTER_MODE_INITIATOR;
	else if (g_strcmp0(dbus_mode, "Target") == 0)
		adapter->poll_mode = NEAR_ADAPTER_MODE_TARGET;
	else if (g_strcmp0(dbus_mode, "Dual") == 0)
		adapter->poll_mode = NEAR_ADAPTER_MODE_DUAL;
	else
		adapter->poll_mode = NEAR_ADAPTER_MODE_INITIATOR;

	err = adapter_start_poll(adapter);
	if (err < 0)
		return __near_error_failed(msg, -err);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Beispiel #2
0
static DBusMessage *unregister_ndef_agent(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	DBusMessageIter iter;
	const char *sender, *path, *type;
	int err;

	DBG("conn %p", conn);

	sender = dbus_message_get_sender(msg);

	if (!dbus_message_iter_init(msg, &iter))
		return __near_error_invalid_arguments(msg);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
		return __near_error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &path);
	dbus_message_iter_next(&iter);

	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
		return __near_error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &type);

	err = ndef_unregister(sender, path, type);
	if (err < 0)
		return __near_error_failed(msg, -err);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Beispiel #3
0
static DBusMessage *close_channel(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct seel_se *se = data;
	const char *path;
	int err;
	struct close_channel_context *ctx;
	struct seel_apdu *close_channel;

	if (se->enabled == false)
		return __near_error_failed(msg, ENODEV);

	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
					DBUS_TYPE_INVALID))
		return __near_error_invalid_arguments(msg);

	ctx = g_try_malloc0(sizeof(struct open_channel_context));
	if (ctx == NULL)
		return __near_error_failed(msg, ENOMEM);

	ctx->channel = g_hash_table_lookup(se->channel_hash, path);
	if (!ctx->channel) {
		g_free(ctx);
		return __near_error_invalid_arguments(msg);
	}

	ctx->se = se;
	ctx->chn = __seel_channel_get_channel(ctx->channel);

	close_channel = __seel_apdu_close_logical_channel(ctx->chn);
	if (!close_channel) {
		g_free(ctx);
		return __near_error_failed(msg, ENOMEM);
	}

	ctx->msg = dbus_message_ref(msg);

	err = __seel_se_queue_io(se, close_channel, close_channel_cb, ctx);
	if (err < 0) {
		near_error("close channel error %d", err);
		return NULL;
	}

	return NULL;
}
Beispiel #4
0
static DBusMessage *open_channel(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct seel_se *se = data;
	unsigned char *aid;
	int aid_len, err;
	struct open_channel_context *ctx;
	struct seel_apdu *open_channel;

	DBG("");

	if (se->enabled == false)
		return __near_error_failed(msg, ENODEV);

	if (!dbus_message_get_args(msg, NULL,
					DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
					&aid, &aid_len, DBUS_TYPE_INVALID))
		return __near_error_invalid_arguments(msg);

	ctx = g_try_malloc0(sizeof(struct open_channel_context));
	if (ctx == NULL)
		return __near_error_failed(msg, ENOMEM);

	open_channel = __seel_apdu_open_logical_channel();
	if (open_channel == NULL) {
		g_free(ctx);
		return __near_error_failed(msg, ENOMEM);
	}

	ctx->msg = dbus_message_ref(msg);
	ctx->se = se;
	ctx->aid = aid;
	ctx->aid_len = aid_len;

	err = __seel_se_queue_io(se, open_channel, open_channel_cb, ctx);
	if (err < 0) {
		near_error("open channel error %d", err);
		return NULL;
	}

	return NULL;
}
Beispiel #5
0
static DBusMessage *set_property(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct seel_se *se = data;
	DBusMessageIter iter, value;
	const char *name;
	int type, err;

	DBG("conn %p", conn);

	if (dbus_message_iter_init(msg, &iter) == FALSE)
		return __near_error_invalid_arguments(msg);

	dbus_message_iter_get_basic(&iter, &name);
	dbus_message_iter_next(&iter);
	dbus_message_iter_recurse(&iter, &value);

	type = dbus_message_iter_get_arg_type(&value);

	if (g_str_equal(name, "Enabled") == TRUE) {
		bool enabled;

		if (type != DBUS_TYPE_BOOLEAN)
			return __near_error_invalid_arguments(msg);

		dbus_message_iter_get_basic(&value, &enabled);

		err = se_toggle(se, enabled);
		if (err < 0) {
			if (err == -EALREADY) {
				if (se->enabled != enabled)
					goto ignore_err;

				if (enabled)
					return __near_error_already_enabled(msg);
				else
					return __near_error_already_disabled(msg);
			}

			return __near_error_failed(msg, -err);
		}

ignore_err:
		se->enabled = enabled;

		if (enabled)
			g_idle_add(__seel_ace_add, se);
	} else {
		return __near_error_invalid_property(msg);
	}

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
Beispiel #6
0
static void close_channel_error(struct close_channel_context *ctx, int err)
{
	DBusMessage *reply;
	DBusConnection *conn;

	near_error("error %d", err);

	conn = near_dbus_get_connection();

	reply = __near_error_failed(ctx->msg, -err);
	if (reply != NULL)
		g_dbus_send_message(conn, reply);

	dbus_message_unref(ctx->msg);
	ctx->msg = NULL;
	g_free(ctx);
}
Beispiel #7
0
static DBusMessage *stop_poll_loop(DBusConnection *conn,
					DBusMessage *msg, void *data)
{
	struct near_adapter *adapter = data;
	int err;

	DBG("conn %p", conn);

	if (!adapter->polling)
		return __near_error_not_polling(msg);

	err = __near_netlink_stop_poll(adapter->idx);
	if (err < 0)
		return __near_error_failed(msg, -err);

	adapter->polling = false;

	polling_changed(adapter);

	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}