1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/kernel_compat.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* 1.5 + * kernel_compat.h 1.6 + * 1.7 + * Compatibility stuff for building in kernel context where standard 1.8 + * C headers and library are not available. 1.9 + * 1.10 + * Marcus Sundberg 1.11 + * Ingate Systems AB 1.12 + */ 1.13 +/* 1.14 + * 1.15 + * Copyright(c) 2005 Ingate Systems AB 1.16 + * All rights reserved. 1.17 + * 1.18 + * Redistribution and use in source and binary forms, with or without 1.19 + * modification, are permitted provided that the following conditions 1.20 + * are met: 1.21 + * 1.22 + * Redistributions of source code must retain the above copyright 1.23 + * notice, this list of conditions and the following disclaimer. 1.24 + * 1.25 + * Redistributions in binary form must reproduce the above 1.26 + * copyright notice, this list of conditions and the following 1.27 + * disclaimer in the documentation and/or other materials provided 1.28 + * with the distribution. 1.29 + * 1.30 + * Neither the name of the author(s) nor the names of its 1.31 + * contributors may be used to endorse or promote products derived 1.32 + * from this software without specific prior written permission. 1.33 + * 1.34 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.35 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.36 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.37 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.38 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.39 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.40 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.41 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.42 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.43 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.44 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.45 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.46 + * 1.47 + */ 1.48 + 1.49 +#ifndef KERNEL_COMPAT_H 1.50 +#define KERNEL_COMPAT_H 1.51 + 1.52 +#ifdef SRTP_KERNEL_LINUX 1.53 + 1.54 +#include <linux/kernel.h> 1.55 +#include <linux/slab.h> 1.56 +#include <linux/sched.h> 1.57 +#include <linux/random.h> 1.58 +#include <linux/byteorder/generic.h> 1.59 + 1.60 + 1.61 +#define err_report(priority, ...) \ 1.62 + do {\ 1.63 + if (priority <= err_level) {\ 1.64 + printk(__VA_ARGS__);\ 1.65 + }\ 1.66 + }while(0) 1.67 + 1.68 +#define clock() (jiffies) 1.69 +#define time(x) (jiffies) 1.70 + 1.71 +/* rand() implementation. */ 1.72 +#define RAND_MAX 32767 1.73 + 1.74 +static inline int rand(void) 1.75 +{ 1.76 + uint32_t temp; 1.77 + get_random_bytes(&temp, sizeof(temp)); 1.78 + return temp % (RAND_MAX+1); 1.79 +} 1.80 + 1.81 +/* stdio/stdlib implementation. */ 1.82 +#define printf(...) printk(__VA_ARGS__) 1.83 +#define exit(n) panic("%s:%d: exit(%d)\n", __FILE__, __LINE__, (n)) 1.84 + 1.85 +#endif /* SRTP_KERNEL_LINUX */ 1.86 + 1.87 +#endif /* KERNEL_COMPAT_H */