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 * @def OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE 80 * 81 * Define to 1 to enable CLI for the posix daemon. 82 * 83 */ 84 #ifndef OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE 85 #define OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE 1 86 #endif 87 88 /** 89 * RCP bus UART. 90 * 91 * @note This value is also for simulated UART bus. 92 * 93 */ 94 #define OT_POSIX_RCP_BUS_UART 1 95 96 /** 97 * RCP bus SPI. 98 * 99 */ 100 #define OT_POSIX_RCP_BUS_SPI 2 101 102 /** 103 * RCP bus defined by vendors. 104 * 105 */ 106 #define OT_POSIX_RCP_BUS_VENDOR 3 107 108 /** 109 * @def OPENTHREAD_POSIX_CONFIG_RCP_BUS 110 * 111 * This setting configures what type of RCP bus to use. 112 * 113 */ 114 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_BUS 115 #define OPENTHREAD_POSIX_CONFIG_RCP_BUS OT_POSIX_RCP_BUS_UART 116 #endif 117 118 /** 119 * @def OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 120 * 121 * Define as 1 to enable max power table support. 122 * 123 */ 124 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 125 #define OPENTHREAD_POSIX_CONFIG_MAX_POWER_TABLE_ENABLE 0 126 #endif 127 128 /** 129 * @def OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE 130 * 131 * This setting configures the maximum number of Multicast Forwarding Cache table for POSIX native multicast routing. 132 * 133 */ 134 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE 135 #define OPENTHREAD_POSIX_CONFIG_MAX_MULTICAST_FORWARDING_CACHE_TABLE (OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS * 10) 136 #endif 137 138 /** 139 * @def OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 140 * 141 * Define as 1 to enable the secure settings. When defined to 1, the platform MUST implement the otPosixSecureSetting* 142 * APIs defined in 'src/posix/platform/include/openthread/platform/secure_settings.h'. 143 * 144 */ 145 #ifndef OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 146 #define OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE 0 147 #endif 148 149 /** 150 * @def OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 151 * 152 * This setting configures the prefix route metric on the Thread network interface. 153 * Define as 0 to use use the default prefix route metric. 154 * 155 * Note: The feature works on Linux kernel v4.18+. 156 * 157 */ 158 #ifndef OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 159 #define OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC 0 160 #endif 161 162 /** 163 * @def OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 164 * 165 * Define as 1 to add OMR routes to POSIX kernel when OMR prefixes are changed in netdata. 166 * 167 * Note: This feature can be used to add OMR routes with non-default priority. Unlike 168 * `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC`, it works on Linux kernels before v4.18. 169 * However, `OPENTHREAD_POSIX_CONFIG_NETIF_PREFIX_ROUTE_METRIC` should be preferred on Linux kernel v4.18+. 170 * 171 */ 172 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 173 #define OPENTHREAD_POSIX_CONFIG_INSTALL_OMR_ROUTES_ENABLE 0 174 #endif 175 176 /** 177 * @def OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 178 * 179 * Defines the priority of OMR routes added to kernel. The larger the number, the lower the priority. We 180 * need to assign a high priority to such routes so that kernel prefers the Thread link rather than infrastructure. 181 * Otherwise we may unnecessarily transmit packets via infrastructure, which potentially causes looping issue. 182 * 183 */ 184 #ifndef OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 185 #define OPENTHREAD_POSIX_CONFIG_OMR_ROUTES_PRIORITY 1 186 #endif 187 188 /** 189 * @def OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM 190 * 191 * Defines the max number of OMR routes that can be added to kernel. 192 * 193 */ 194 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM 195 #define OPENTHREAD_POSIX_CONFIG_MAX_OMR_ROUTES_NUM OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES 196 #endif 197 198 /** 199 * @def OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 200 * 201 * Define as 1 to add external routes to POSIX kernel when external routes are changed in netdata. 202 * 203 */ 204 #ifndef OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 205 #define OPENTHREAD_POSIX_CONFIG_INSTALL_EXTERNAL_ROUTES_ENABLE 1 206 #endif 207 208 /** 209 * @def OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 210 * 211 * Defines the priority of external routes added to kernel. The larger the number, the lower the priority. We 212 * need to assign a low priority to such routes so that kernel prefers the infra link rather than thread. Otherwise we 213 * may unnecessarily transmit packets via thread, which potentially causes performance issue. In linux, normally infra 214 * link routes' metric value is not greater than 1024, hence 65535 should be big enough. 215 * 216 */ 217 #ifndef OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 218 #define OPENTHREAD_POSIX_CONFIG_EXTERNAL_ROUTE_PRIORITY 65535 219 #endif 220 221 /** 222 * @def OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 223 * 224 * Defines the max number of external routes that can be added to kernel. 225 * 226 */ 227 #ifndef OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 228 #define OPENTHREAD_POSIX_CONFIG_MAX_EXTERNAL_ROUTE_NUM 8 229 #endif 230 231 /** 232 * @def OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 233 * 234 * Define as 1 to enable discovering NAT64 posix on adjacent infrastructure link. 235 * 236 */ 237 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 238 #define OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE 0 239 #endif 240 241 /** 242 * @def OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 243 * 244 * Define as 1 to enable firewall. 245 * 246 * The rules are implemented using ip6tables and ipset. The rules are as follows. 247 * 248 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -i $THREAD_IF -p ip -j DROP 249 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-deny-src src -p ip -j DROP 250 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m set --match-set otbr-ingress-allow-dst dst -p ip -j ACCEPT 251 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -m pkttype --pkt-type unicast -p ip -j DROP 252 * ip6tables -A $OTBR_FORWARD_INGRESS_CHAIN -p ip -j ACCEPT 253 * 254 */ 255 #ifndef OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 256 #define OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 0 257 #endif 258 259 #if OPENTHREAD_POSIX_CONFIG_FIREWALL_ENABLE 260 #ifndef OPENTHREAD_POSIX_CONFIG_IPSET_BINARY 261 #define OPENTHREAD_POSIX_CONFIG_IPSET_BINARY "ipset" 262 #endif 263 #endif 264 265 /** 266 * @def OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME 267 * 268 * Define the Thread default network interface name. 269 * 270 */ 271 #ifndef OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME 272 #define OPENTHREAD_POSIX_CONFIG_THREAD_NETIF_DEFAULT_NAME "wpan0" 273 #endif 274 275 #ifdef __APPLE__ 276 277 /** 278 * Use built-in utun driver on mac OS 279 */ 280 #define OT_POSIX_CONFIG_MACOS_UTUN 1 281 282 /** 283 * Use open-source tun driver on mac OS 284 */ 285 #define OT_POSIX_CONFIG_MACOS_TUN 2 286 287 /** 288 * @def OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION 289 * 290 * This setting configures which tunnel driver to use. 291 * 292 */ 293 #ifndef OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION 294 #define OPENTHREAD_POSIX_CONFIG_MACOS_TUN_OPTION OT_POSIX_CONFIG_MACOS_UTUN 295 #endif 296 297 #endif // __APPLE__ 298 299 //--------------------------------------------------------------------------------------------------------------------- 300 // Removed or renamed POSIX specific configs. 301 302 #ifdef OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME 303 #error "OPENTHREAD_CONFIG_POSIX_APP_TREL_INTERFACE_NAME was removed (no longer applicable with TREL over DNS-SD)." 304 #endif 305 306 #ifdef OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET 307 #error "OPENTHREAD_CONFIG_POSIX_TREL_USE_NETLINK_SOCKET was removed (no longer applicable with TREL over DNS-SD)." 308 #endif 309 310 /** 311 * @def OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 312 * 313 * This setting configures the TREL UDP port number. 314 * Define as 0 to use an ephemeral port number. 315 * 316 */ 317 #ifndef OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 318 #define OPENTHREAD_POSIX_CONFIG_TREL_UDP_PORT 0 319 #endif 320 321 /** 322 * @def OPENTHREAD_POSIX_CONFIG_NAT64_CIDR 323 * 324 * This setting configures the NAT64 CIDR, used by NAT64 translator. 325 * 326 */ 327 #ifndef OPENTHREAD_POSIX_CONFIG_NAT64_CIDR 328 #define OPENTHREAD_POSIX_CONFIG_NAT64_CIDR "192.168.255.0/24" 329 #endif 330 331 /** 332 * @def OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE 333 * 334 * Define as 1 to enable backtrace support. 335 * 336 */ 337 #ifndef OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE 338 #define OPENTHREAD_POSIX_CONFIG_BACKTRACE_ENABLE 1 339 #endif 340 341 /** 342 * @def OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE 343 * 344 * Define as 1 to enable android support. 345 * 346 */ 347 #ifndef OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE 348 #define OPENTHREAD_POSIX_CONFIG_ANDROID_ENABLE 0 349 #endif 350 351 /** 352 * @def OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE 353 * 354 * Defines `1` to enable the posix implementation of platform/infra_if.h APIs. 355 * The default value is set to `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` if it's 356 * not explicit defined. 357 */ 358 #ifndef OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE 359 #define OPENTHREAD_POSIX_CONFIG_INFRA_IF_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE 360 #endif 361 362 /** 363 * @def OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE 364 * 365 * Define the path of the factory config file. 366 * 367 * Note: The factory config file contains the persist data that configured by the factory. And it won't be changed 368 * after a device firmware update OTA is done. 369 * 370 */ 371 #ifndef OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE 372 #define OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE "src/posix/platform/openthread.conf.example" 373 #endif 374 375 /** 376 * @def OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE 377 * 378 * Define the path of the product config file. 379 * 380 */ 381 #ifndef OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE 382 #define OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE "src/posix/platform/openthread.conf.example" 383 #endif 384 385 /** 386 * @def OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL 387 * 388 * This setting configures the interval (in units of microseconds) for host-rcp 389 * time sync. The host will recalculate the time offset between host and RCP 390 * every interval. 391 * 392 */ 393 #ifndef OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL 394 #define OPENTHREAD_POSIX_CONFIG_RCP_TIME_SYNC_INTERVAL (60 * 1000 * 1000) 395 #endif 396 #endif // OPENTHREAD_PLATFORM_CONFIG_H_ 397