1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2023 Linaro Ltd. <maxim.uvarov@linaro.org> */
3
4 #ifndef LWIP_ARCH_CC_H
5 #define LWIP_ARCH_CC_H
6
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <vsprintf.h>
10 #include <rand.h>
11
12 #define LWIP_ERRNO_INCLUDE <errno.h>
13
14 #define LWIP_ERRNO_STDINCLUDE 1
15 #define LWIP_NO_UNISTD_H 1
16 #define LWIP_TIMEVAL_PRIVATE 1
17
18 #ifdef CONFIG_LIB_RAND
19 #define LWIP_RAND() ((u32_t)rand())
20 #else
21 #define LWIP_DNS_SECURE 0
22 #endif
23
24 /* different handling for unit test, normally not needed */
25 #ifdef LWIP_NOASSERT_ON_ERROR
26 #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
27 handler; }} while (0)
28 #endif
29
30 #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
31
32 #define LWIP_PLATFORM_ASSERT(x) do { \
33 printf("Assertion \"%s\" failed at line %d in %s\n", \
34 x, __LINE__, __FILE__); } while (0)
35
36 #define atoi(str) (int)dectoul(str, NULL)
37 #define lwip_strnstr(a, b, c) strnstr(a, b, c)
38
39 #define LWIP_ERR_T int
40 #define LWIP_CONST_CAST(target_type, val) ((target_type)((uintptr_t)val))
41
42 #if defined(CONFIG_SYS_BIG_ENDIAN)
43 #define BYTE_ORDER BIG_ENDIAN
44 #endif
45
46 #define SNTP_STARTUP_DELAY 0
47 void sntp_set_system_time(uint32_t sec);
48 #define SNTP_SET_SYSTEM_TIME(sec) sntp_set_system_time(sec)
49
sntp_format_time(time_t t)50 static inline const char *sntp_format_time(time_t t)
51 {
52 static char buf[29]; /* "(time_t)" + 20 digits max + \0 */
53
54 snprintf(buf, sizeof(buf), "(time_t)%llu", t);
55 return buf;
56 }
57
58 #define sntp_format_time sntp_format_time
59
60 #ifdef CONFIG_LWIP_ICMP_SHOW_UNREACH
61 struct pbuf;
62 void net_lwip_icmp_dest_unreach(int code, struct pbuf *p);
63
64 #define ICMP_DEST_UNREACH_CB(_c, _p) net_lwip_icmp_dest_unreach(_c, _p)
65 #endif
66 #endif /* LWIP_ARCH_CC_H */
67