2 * Copyright (c) 2013 Arthur Mesh <arthurmesh@gmail.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/fcntl.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/module.h>
35 #include <sys/random.h>
36 #include <sys/selinfo.h>
37 #include <sys/systm.h>
40 #include <dev/random/random_adaptors.h>
41 #include <dev/random/randomdev.h>
43 static struct mtx dummy_random_mtx;
45 /* Used to fake out unused random calls in random_adaptor */
47 random_null_func(void)
52 dummy_random_poll(int events __unused, struct thread *td __unused)
59 dummy_random_block(int flag)
63 mtx_lock(&dummy_random_mtx);
67 if (flag & O_NONBLOCK)
70 printf("random: dummy device blocking on read.\n");
71 error = msleep(&dummy_random_block,
73 PUSER | PCATCH, "block", 0);
76 mtx_unlock(&dummy_random_mtx);
82 dummy_random_init(void)
85 mtx_init(&dummy_random_mtx, "sleep mtx for dummy_random",
90 dummy_random_deinit(void)
93 mtx_destroy(&dummy_random_mtx);
96 struct random_adaptor dummy_random = {
97 .ident = "Dummy entropy device that always blocks",
98 .init = dummy_random_init,
99 .deinit = dummy_random_deinit,
100 .block = dummy_random_block,
101 .poll = dummy_random_poll,
102 .read = (random_read_func_t *)random_null_func,
103 .reseed = (random_reseed_func_t *)random_null_func,
104 .seeded = 0, /* This device can never be seeded */
105 .priority = 1, /* Bottom priority, so goes to last position */
109 dummy_random_modevent(module_t mod __unused, int type, void *unused __unused)
114 random_adaptor_register("dummy", &dummy_random);
115 EVENTHANDLER_INVOKE(random_adaptor_attach,
124 RANDOM_ADAPTOR_MODULE(dummy, dummy_random_modevent, 1);