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.
29 #ifndef SYS_DEV_RANDOM_RANDOM_ADAPTORS_H_INCLUDED
30 #define SYS_DEV_RANDOM_RANDOM_ADAPTORS_H_INCLUDED
32 MALLOC_DECLARE(M_ENTROPY);
34 typedef void random_adaptor_init_func_t(void);
35 typedef void random_adaptor_deinit_func_t(void);
36 typedef void random_adaptor_read_func_t(uint8_t *, u_int);
37 typedef void random_adaptor_write_func_t(uint8_t *, u_int);
38 typedef int random_adaptor_seeded_func_t(void);
39 typedef void random_adaptor_reseed_func_t(void);
41 struct random_adaptor {
44 random_adaptor_init_func_t *ra_init;
45 random_adaptor_deinit_func_t *ra_deinit;
46 random_adaptor_read_func_t *ra_read;
47 random_adaptor_write_func_t *ra_write;
48 random_adaptor_reseed_func_t *ra_reseed;
49 random_adaptor_seeded_func_t *ra_seeded;
52 struct random_adaptors {
53 LIST_ENTRY(random_adaptors) rra_entries; /* list of providers */
54 const char *rra_name; /* name of random adaptor */
55 struct random_adaptor *rra_ra;
58 /* Dummy "always-block" pseudo-device */
59 extern struct random_adaptor randomdev_dummy;
61 void random_adaptors_init(void);
62 void random_adaptors_deinit(void);
64 void random_adaptor_register(const char *, struct random_adaptor *);
65 void random_adaptor_deregister(const char *);
67 int random_adaptor_read(struct cdev *, struct uio *, int);
68 int random_adaptor_write(struct cdev *, struct uio *, int);
69 int random_adaptor_poll(struct cdev *, int, struct thread *);
71 int random_adaptor_read_rate(void);
72 void random_adaptor_unblock(void);
74 #endif /* SYS_DEV_RANDOM_RANDOM_ADAPTORS_H_INCLUDED */