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