2012-06-25 19:03:47 +04:00
|
|
|
/*
|
|
|
|
* QEMU Random Number Generator Backend
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:49:54 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-04-08 18:55:25 +04:00
|
|
|
#include "sysemu/rng.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2014-01-16 20:34:38 +04:00
|
|
|
#include "qom/object_interfaces.h"
|
2012-06-25 19:03:47 +04:00
|
|
|
|
|
|
|
void rng_backend_request_entropy(RngBackend *s, size_t size,
|
|
|
|
EntropyReceiveFunc *receive_entropy,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
if (k->request_entropy) {
|
|
|
|
k->request_entropy(s, size, receive_entropy, opaque);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rng_backend_cancel_requests(RngBackend *s)
|
|
|
|
{
|
|
|
|
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
if (k->cancel_requests) {
|
|
|
|
k->cancel_requests(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
|
|
|
|
return s->opened;
|
|
|
|
}
|
|
|
|
|
2014-01-16 20:34:39 +04:00
|
|
|
static void rng_backend_complete(UserCreatable *uc, Error **errp)
|
2012-06-25 19:03:47 +04:00
|
|
|
{
|
2014-01-16 20:34:39 +04:00
|
|
|
object_property_set_bool(OBJECT(uc), true, "opened", errp);
|
2012-06-25 19:03:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
RngBackend *s = RNG_BACKEND(obj);
|
|
|
|
RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
|
2014-04-25 14:44:22 +04:00
|
|
|
Error *local_err = NULL;
|
2012-06-25 19:03:47 +04:00
|
|
|
|
|
|
|
if (value == s->opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value && s->opened) {
|
2015-03-17 13:54:50 +03:00
|
|
|
error_setg(errp, QERR_PERMISSION_DENIED);
|
2012-06-25 19:03:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k->opened) {
|
2014-04-25 14:44:22 +04:00
|
|
|
k->opened(s, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-25 19:03:47 +04:00
|
|
|
}
|
|
|
|
|
2014-04-25 14:44:22 +04:00
|
|
|
s->opened = true;
|
2012-06-25 19:03:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rng_backend_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add_bool(obj, "opened",
|
|
|
|
rng_backend_prop_get_opened,
|
|
|
|
rng_backend_prop_set_opened,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2014-01-16 20:34:39 +04:00
|
|
|
static void rng_backend_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
|
|
|
|
|
|
|
ucc->complete = rng_backend_complete;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo rng_backend_info = {
|
2012-06-25 19:03:47 +04:00
|
|
|
.name = TYPE_RNG_BACKEND,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.instance_size = sizeof(RngBackend),
|
|
|
|
.instance_init = rng_backend_init,
|
|
|
|
.class_size = sizeof(RngBackendClass),
|
2014-01-16 20:34:39 +04:00
|
|
|
.class_init = rng_backend_class_init,
|
2012-06-25 19:03:47 +04:00
|
|
|
.abstract = true,
|
2014-01-16 20:34:38 +04:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
2012-06-25 19:03:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&rng_backend_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|