• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_POSIX_CONFIG_H_
30 #define OPENTHREAD_PLATFORM_POSIX_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 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
50 #define OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE 1
51 #endif
52 
53 /**
54  * @def OPENTHREAD_POSIX_CONFIG_RCP_BUS
55  *
56  * This setting configures what type of RCP bus to use.
57  */
58 #ifdef OPENTHREAD_POSIX_CONFIG_RCP_BUS
59 #error "OPENTHREAD_POSIX_CONFIG_RCP_BUS was replaced by OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE,"\
60        "OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE and OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE"
61 #endif
62 
63 /**
64  * @def OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE
65  *
66  * Define as 1 to enable the spinel HDLC interface.
67  */
68 #ifndef OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE
69 #define OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE 1
70 #endif
71 
72 /**
73  * @def OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE
74  *
75  * Define as 1 to enable the spinel SPI interface.
76  */
77 #ifndef OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE
78 #define OPENTHREAD_POSIX_CONFIG_SPINEL_SPI_INTERFACE_ENABLE 0
79 #endif
80 
81 /**
82  * @def OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE
83  *
84  * Define as 1 to enable the spinel vendor interface.
85  */
86 #ifndef OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE
87 #define OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_ENABLE 0
88 #endif
89 
90 /**
91  * @def OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_URL_PROTOCOL_NAME
92  *
93  * Define the URL protocol name of the vendor Spinel interface.
94  */
95 #ifndef OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_URL_PROTOCOL_NAME
96 #define OPENTHREAD_POSIX_CONFIG_SPINEL_VENDOR_INTERFACE_URL_PROTOCOL_NAME "spinel+vendor"
97 #endif
98 
99 /**
100  * @def OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
101  *
102  * Define as 1 to enable max power table support.
103  */
104 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE
105 #define OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 0
106 #endif
107 
108 /**
109  * @def OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE
110  *
111  * This setting configures the maximum number of Multicast Forwarding Cache table for POSIX native multicast routing.
112  */
113 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE
114 #define OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE (OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS * 10)
115 #endif
116 
117 /**
118  * @def OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
119  *
120  * Define as 1 to enable multicast routing support.
121  */
122 #ifndef OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
123 #define OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE \
124     OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
125 #endif
126 
127 #if OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE && \
128     !OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
129 #error \
130     "OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE is required for OPENTHREAD_POSIX_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE"
131 #endif
132 
133 /**
134  * @def OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE
135  *
136  * Define as 1 to enable the secure settings. When defined to 1, the platform MUST implement the otPosixSecureSetting*
137  * APIs defined in 'src/posix/platform/include/openthread/platform/secure_settings.h'.
138  */
139 #ifndef OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE
140 #define OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 0
141 #endif
142 
143 /**
144  * @def OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC
145  *
146  * This setting configures the prefix route metric on the Thread network interface.
147  * Define as 0 to use use the default prefix route metric.
148  *
149  * Note: The feature works on Linux kernel v4.18+.
150  */
151 #ifndef OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC
152 #define OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 0
153 #endif
154 
155 /**
156  * @def OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE
157  *
158  * Define as 1 to add OMR routes to POSIX kernel when OMR prefixes are changed in netdata.
159  *
160  * Note: This feature can be used to add OMR routes with non-default priority. Unlike
161  * `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC`, it works on Linux kernels before v4.18.
162  * However, `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC` should be preferred on Linux kernel v4.18+.
163  */
164 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE
165 #define OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 0
166 #endif
167 
168 /**
169  * @def OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY
170  *
171  * Defines the priority of OMR routes added to kernel. The larger the number, the lower the priority. We
172  * need to assign a high priority to such routes so that kernel prefers the Thread link rather than infrastructure.
173  * Otherwise we may unnecessarily transmit packets via infrastructure, which potentially causes looping issue.
174  */
175 #ifndef OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY
176 #define OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 1
177 #endif
178 
179 /**
180  * @def OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM
181  *
182  * Defines the max number of OMR routes that can be added to kernel.
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 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE
194 #define OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 1
195 #endif
196 
197 /**
198  * @def OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY
199  *
200  * Defines the priority of external routes added to kernel. The larger the number, the lower the priority. We
201  * need to assign a low priority to such routes so that kernel prefers the infra link rather than thread. Otherwise we
202  * may unnecessarily transmit packets via thread, which potentially causes performance issue. In linux, normally infra
203  * link routes' metric value is not greater than 1024, hence 65535 should be big enough.
204  */
205 #ifndef OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY
206 #define OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 65535
207 #endif
208 
209 /**
210  * @def OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM
211  *
212  * Defines the max number of external routes that can be added to kernel.
213  */
214 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM
215 #define OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 8
216 #endif
217 
218 /**
219  * @def OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
220  *
221  * Define as 1 to enable discovering NAT64 posix on adjacent infrastructure link.
222  */
223 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
224 #define OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 0
225 #endif
226 
227 /**
228  * @def OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
229  *
230  * Define as 1 to enable firewall.
231  *
232  * The rules are implemented using ip6tables and ipset. The rules are as follows.
233  *
234  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -i $THREAD_IF -p ip -j DROP
235  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-deny-src src -p ip -j DROP
236  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-allow-dst dst -p ip -j ACCEPT
237  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -p ip -j DROP
238  * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -p ip -j ACCEPT
239  */
240 #ifndef OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
241 #define OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 0
242 #endif
243 
244 #if OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE
245 #ifndef OPENTHREAD_POSIX_CONFIG_IPSET_BINARY
246 #define OPENTHREAD_POSIX_CONFIG_IPSET_BINARY "ipset"
247 #endif
248 #endif
249 
250 /**
251  * @def OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME
252  *
253  * Define the Thread default network interface name.
254  */
255 #ifndef OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME
256 #define OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME "wpan0"
257 #endif
258 
259 #ifdef __APPLE__
260 
261 /**
262  * Use built-in utun driver on mac OS
263  */
264 #define OT_POSIX_CONFIG_MACOS_UTUN 1
265 
266 /**
267  * Use open-source tun driver on mac OS
268  */
269 #define OT_POSIX_CONFIG_MACOS_TUN 2
270 
271 /**
272  * @def OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION
273  *
274  * This setting configures which tunnel driver to use.
275  */
276 #ifndef OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION
277 #define OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION OT_POSIX_CONFIG_MACOS_UTUN
278 #endif
279 
280 #endif // __APPLE__
281 
282 //---------------------------------------------------------------------------------------------------------------------
283 // Removed or renamed POSIX specific configs.
284 
285 #ifdef OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME
286 #error "OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME was removed (no longer applicable with TREL over DNS-SD)."
287 #endif
288 
289 #ifdef OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET
290 #error "OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET was removed (no longer applicable with TREL over DNS-SD)."
291 #endif
292 
293 /**
294  * @def OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT
295  *
296  * This setting configures the TREL UDP port number.
297  * Define as 0 to use an ephemeral port number.
298  */
299 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT
300 #define OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 0
301 #endif
302 
303 /**
304  * @def OPENTHREAD_POSIX_CONFIG_NAT64_CIDR
305  *
306  * This setting configures the NAT64 CIDR, used by NAT64 translator.
307  */
308 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_CIDR
309 #define OPENTHREAD_POSIX_CONFIG_NAT64_CIDR "192.168.255.0/24"
310 #endif
311 
312 /**
313  * @def OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE
314  *
315  * Define as 1 to enable backtrace support.
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 #ifndef OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE
327 #define OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE 0
328 #endif
329 
330 /**
331  * @def OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE
332  *
333  * Defines `1` to enable the posix implementation of platform/infra_if.h APIs.
334  * The default value is set to `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` if it's
335  * not explicit defined.
336  */
337 #ifndef OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE
338 #define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE \
339     (OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE || OPENTHREAD_CONFIG_BACKBONE_ROUTER_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 #ifndef OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE
351 #define OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE "src/posix/platform/openthread.conf.example"
352 #endif
353 
354 /**
355  * @def OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE
356  *
357  * Define the path of the product config file.
358  */
359 #ifndef OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE
360 #define OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE "src/posix/platform/openthread.conf.example"
361 #endif
362 
363 /**
364  * @def OPENTHREAD_POSIX_CONFIG_CONFIGURATION_FILE_ENABLE
365  *
366  * Define as 1 to enable the configuration file support.
367  */
368 #ifndef OPENTHREAD_POSIX_CONFIG_CONFIGURATION_FILE_ENABLE
369 #define OPENTHREAD_POSIX_CONFIG_CONFIGURATION_FILE_ENABLE 1
370 #endif
371 
372 /**
373  * @def OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL
374  *
375  * This setting configures the interval (in units of microseconds) for host-rcp
376  * time sync. The host will recalculate the time offset between host and RCP
377  * every interval.
378  */
379 #ifdef OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL
380 #error "OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL was replaced by OPENTHREAD_SPINEL_CONFIG_RCP_TIME_SYNC_INTERVAL"
381 #endif
382 
383 /**
384  * @def OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE
385  *
386  * Define as 1 to let the process exit when the infra network interface is lost on the POSIX platform.
387  */
388 #ifndef OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE
389 #define OPENTHREAD_POSIX_CONFIG_EXIT_ON_INFRA_NETIF_LOST_ENABLE 1
390 #endif
391 
392 /**
393  * @def OPENTHREAD_POSIX_CONFIG_TREL_TX_PACKET_POOL_SIZE
394  *
395  * This setting configures the capacity of TREL packet pool for transmission.
396  */
397 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_TX_PACKET_POOL_SIZE
398 #define OPENTHREAD_POSIX_CONFIG_TREL_TX_PACKET_POOL_SIZE 5
399 #endif
400 
401 /**
402  * @def OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE
403  *
404  * Define as 1 to enable RCP capability diagnostic support.
405  */
406 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE
407 #define OPENTHREAD_POSIX_CONFIG_RCP_CAPS_DIAG_ENABLE OPENTHREAD_CONFIG_DIAG_ENABLE
408 #endif
409 
410 /**
411  * @def OPENTHREAD_POSIX_CONFIG_UPSTREAM_DNS_BIND_TO_INFRA_NETIF
412  *
413  * Define as 1 to let the upstream DNS bind the socket to infra network interface.
414  */
415 #ifndef OPENTHREAD_POSIX_CONFIG_UPSTREAM_DNS_BIND_TO_INFRA_NETIF
416 #define OPENTHREAD_POSIX_CONFIG_UPSTREAM_DNS_BIND_TO_INFRA_NETIF 1
417 #endif
418 
419 /**
420  * @def OPENTHREAD_POSIX_CONFIG_TREL_SELECT_INFRA_IF
421  *
422  * Define to 1 to let TREL select the infrastructure interface, otherwise use the interface in the TREL URL.
423  */
424 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_SELECT_INFRA_IF
425 #define OPENTHREAD_POSIX_CONFIG_TREL_SELECT_INFRA_IF 0
426 #endif
427 
428 /**
429  * @def OPENTHREAD_POSIX_CONFIG_TMP_STORAGE_ENABLE
430  *
431  * Define as 1 to enable the temporary storage. The key-value pairs stored in the temporary storage will be erased
432  * after the system is rebooted.
433  */
434 #ifndef OPENTHREAD_POSIX_CONFIG_TMP_STORAGE_ENABLE
435 #define OPENTHREAD_POSIX_CONFIG_TMP_STORAGE_ENABLE 1
436 #endif
437 
438 #endif // OPENTHREAD_PLATFORM_POSIX_CONFIG_H_
439