1 /*
2  *  Copyright (c) 2019, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef OPENTHREAD_PLATFORM_CONFIG_H_
30 #define OPENTHREAD_PLATFORM_CONFIG_H_
31 
32 #include "openthread-core-config.h"
33 
34 #ifdef OPENTHREAD_POSIX_CONFIG_FILE
35 #include OPENTHREAD_POSIX_CONFIG_FILE
36 #endif
37 
38 /**
39  * @file
40  * @brief
41  *   This file includes the POSIX platform-specific configurations.
42  */
43 
44 /**
45  * @def OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
46  *
47  * Define as 1 to enable PTY RCP support.
48  *
49  */
50 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
51 #define OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE 1
52 #endif
53 
54 /**
55  * @def OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME
56  *
57  * Define socket basename used by POSIX app daemon.
58  *
59  */
60 #ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME
61 #ifdef __linux__
62 #define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/run/openthread-%s"
63 #else
64 #define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/tmp/openthread-%s"
65 #endif
66 #endif
67 
68 /**
69  * @def OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
70  *
71  * Define to 1 to enable POSIX daemon.
72  *
73  */
74 #ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
75 #define OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE 0
76 #endif
77 
78 /**
79  * RCP bus UART.
80  *
81  * @note This value is also for simulated UART bus.
82  *
83  */
84 #define OT_POSIX_RCP_BUS_UART 1
85 
86 /**
87  * RCP bus SPI.
88  *
89  */
90 #define OT_POSIX_RCP_BUS_SPI 2
91 
92 /**
93  * RCP bus defined by vendors.
94  *
95  */
96 #define OT_POSIX_RCP_BUS_VENDOR 3
97 
98 /**
99  * @def OPENTHREAD_POSIX_CONFIG_RCP_BUS
100  *
101  * This setting configures what type of RCP bus to use.
102  *
103  */
104 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_BUS
105 #define OPENTHREAD_POSIX_CONFIG_RCP_BUS OT_POSIX_RCP_BUS_UART
106 #endif
107 
108 /**
109  * @def OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
110  *
111  * Define as 1 to enable max power table support.
112  *
113  */
114 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
115 #define OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 0
116 #endif
117 
118 /**
119  * @def OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE
120  *
121  * This setting configures the maximum number of Multicast Forwarding Cache table for POSIX native multicast routing.
122  *
123  */
124 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE
125 #define OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE (OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS * 10)
126 #endif
127 
128 /**
129  * @def OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE
130  *
131  * Define as 1 to enable the secure settings. When defined to 1, the platform MUST implement the otPosixSecureSetting*
132  * APIs defined in 'src/posix/platform/include/openthread/platform/secure_settings.h'.
133  *
134  */
135 #ifndef OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE
136 #define OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 0
137 #endif
138 
139 /**
140  * @def OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC
141  *
142  * This setting configures the prefix route metric on the Thread network interface.
143  * Define as 0 to use use the default prefix route metric.
144  *
145  * Note: The feature works on Linux kernel v4.18+.
146  *
147  */
148 #ifndef OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC
149 #define OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 0
150 #endif
151 
152 /**
153  * @def OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE
154  *
155  * Define as 1 to add OMR routes to POSIX kernel when OMR prefixes are changed in netdata.
156  *
157  * Note: This feature can be used to add OMR routes with non-default priority. Unlike
158  * `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC`, it works on Linux kernels before v4.18.
159  * However, `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC` should be preferred on Linux kernel v4.18+.
160  *
161  */
162 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE
163 #define OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 0
164 #endif
165 
166 /**
167  * @def OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY
168  *
169  * This macro defines the priority of OMR routes added to kernel. The larger the number, the lower the priority. We
170  * need to assign a high priority to such routes so that kernel prefers the Thread link rather than infrastructure.
171  * Otherwise we may unnecessarily transmit packets via infrastructure, which potentially causes looping issue.
172  *
173  */
174 #ifndef OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY
175 #define OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 1
176 #endif
177 
178 /**
179  * @def OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM
180  *
181  * This macro defines the max number of OMR routes that can be added to kernel.
182  *
183  */
184 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM
185 #define OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES
186 #endif
187 
188 /**
189  * @def OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE
190  *
191  * Define as 1 to add external routes to POSIX kernel when external routes are changed in netdata.
192  *
193  */
194 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE
195 #define OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 1
196 #endif
197 
198 /**
199  * @def OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY
200  *
201  * This macro defines the priority of external routes added to kernel. The larger the number, the lower the priority. We
202  * need to assign a low priority to such routes so that kernel prefers the infra link rather than thread. Otherwise we
203  * may unnecessarily transmit packets via thread, which potentially causes performance issue. In linux, normally infra
204  * link routes' metric value is not greater than 1024, hence 65535 should be big enough.
205  *
206  */
207 #ifndef OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY
208 #define OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 65535
209 #endif
210 
211 /**
212  * @def OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM
213  *
214  * This macro defines the max number of external routes that can be added to kernel.
215  *
216  */
217 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM
218 #define OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 8
219 #endif
220 
221 /**
222  * @def OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
223  *
224  * Define as 1 to enable discovering NAT64 posix on adjacent infrastructure link.
225  *
226  */
227 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
228 #define OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 0
229 #endif
230 
231 /**
232  * @def OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
233  *
234  * Define as 1 to enable firewall.
235  *
236  * The rules are implemented using ip6tables and ipset. The rules are as follows.
237  *
238  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -i $THREAD_IF -p ip -j DROP
239  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-deny-src src -p ip -j DROP
240  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-allow-dst dst -p ip -j ACCEPT
241  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -p ip -j DROP
242  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -p ip -j ACCEPT
243  *
244  */
245 #ifndef OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
246 #define OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 0
247 #endif
248 
249 #if OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
250 #ifndef OPENTHREAD_POSIX_CONFIG_IPSET_BINARY
251 #define OPENTHREAD_POSIX_CONFIG_IPSET_BINARY "ipset"
252 #endif
253 #endif
254 
255 #ifdef __APPLE__
256 
257 /**
258  * Use built-in utun driver on mac OS
259  */
260 #define OT_POSIX_CONFIG_MACOS_UTUN 1
261 
262 /**
263  * Use open-source tun driver on mac OS
264  */
265 #define OT_POSIX_CONFIG_MACOS_TUN 2
266 
267 /**
268  * @def OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION
269  *
270  * This setting configures which tunnel driver to use.
271  *
272  */
273 #ifndef OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION
274 #define OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION OT_POSIX_CONFIG_MACOS_UTUN
275 #endif
276 
277 #endif // __APPLE__
278 
279 //---------------------------------------------------------------------------------------------------------------------
280 // Removed or renamed POSIX specific configs.
281 
282 #ifdef OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
283 #error "OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME was removed (no longer applicable with TREL over DNS-SD)."
284 #endif
285 
286 #ifdef OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET
287 #error "OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET was removed (no longer applicable with TREL over DNS-SD)."
288 #endif
289 
290 /**
291  * @def OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT
292  *
293  * This setting configures the TREL UDP port number.
294  * Define as 0 to use an ephemeral port number.
295  *
296  */
297 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT
298 #define OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 0
299 #endif
300 
301 /**
302  * @def OPENTHREAD_POSIX_CONFIG_NAT64_CIDR
303  *
304  * This setting configures the NAT64 CIDR, used by NAT64 translator.
305  *
306  */
307 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_CIDR
308 #define OPENTHREAD_POSIX_CONFIG_NAT64_CIDR "192.168.255.0/24"
309 #endif
310 
311 /**
312  * @def OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE
313  *
314  * Define as 1 to enable backtrace support.
315  *
316  */
317 #ifndef OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE
318 #define OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE 1
319 #endif
320 
321 /**
322  * @def OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE
323  *
324  * Define as 1 to enable android support.
325  *
326  */
327 #ifndef OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE
328 #define OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE 0
329 #endif
330 
331 /**
332  * @def OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE
333  *
334  * Defines `1` to enable the posix implementation of platform/infra_if.h APIs.
335  * The default value is set to `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` if it's
336  * not explicit defined.
337  */
338 #ifndef OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE
339 #define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
340 #endif
341 
342 /**
343  * @def OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE
344  *
345  * Define the path of the factory config file.
346  *
347  * Note: The factory config file contains the persist data that configured by the factory. And it won't be changed
348  *       after a device firmware update OTA is done.
349  *
350  */
351 #ifndef OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE
352 #define OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE "src/posix/platform/openthread.conf.example"
353 #endif
354 
355 /**
356  * @def OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE
357  *
358  * Define the path of the product config file.
359  *
360  */
361 #ifndef OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE
362 #define OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE "src/posix/platform/openthread.conf.example"
363 #endif
364 
365 /**
366  * @def OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL
367  *
368  * This setting configures the interval (in units of microseconds) for host-rcp
369  * time sync. The host will recalculate the time offset between host and RCP
370  * every interval.
371  *
372  */
373 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL
374 #define OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL (60 * 1000 * 1000)
375 #endif
376 #endif // OPENTHREAD_PLATFORM_CONFIG_H_
377