1 /*
2  * wpa_supplicant/hostapd / Internal implementation of OS specific functions
3  * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  *
14  * This file is an example of operating system specific  wrapper functions.
15  * This version implements many of the functions internally, so it can be used
16  * to fill in missing functions from the target system C libraries.
17  *
18  * Some of the functions are using standard C library calls in order to keep
19  * this file in working condition to allow the functions to be tested on a
20  * Linux target. Please note that OS_NO_C_LIB_DEFINES needs to be defined for
21  * this file to work correctly. Note that these implementations are only
22  * examples and are not optimized for speed.
23  */
24 
25 #include "os.h"
26 #include <stdlib.h>
27 #include "esp_system.h"
28 #include "utils/common.h"
29 #include <zephyr/random/random.h>
30 
os_get_time(struct os_time * t)31 int os_get_time(struct os_time *t)
32 {
33 	if (t == NULL) {
34 		return -1;
35 	}
36 
37 	int64_t now = k_uptime_ticks();
38 	t->sec = now / CONFIG_SYS_CLOCK_TICKS_PER_SEC;
39 	t->usec = k_ticks_to_us_floor64(now);
40 
41 	return 0;
42 }
43 
os_random(void)44 unsigned long os_random(void)
45 {
46 	return sys_rand32_get();
47 }
48 
os_get_random(unsigned char * buf,size_t len)49 int os_get_random(unsigned char *buf, size_t len)
50 {
51 	sys_rand_get((void *)buf, len);
52 	return 0;
53 }
54