1 /* 2 * Copyright (c) 2020, 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 /** 30 * @file 31 * @brief 32 * This file includes the platform abstraction for the infrastructure network interface. 33 * 34 */ 35 36 #ifndef OPENTHREAD_PLATFORM_INFRA_IF_H_ 37 #define OPENTHREAD_PLATFORM_INFRA_IF_H_ 38 39 #include <stdint.h> 40 41 #include <openthread/error.h> 42 #include <openthread/instance.h> 43 #include <openthread/ip6.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @addtogroup plat-infra-if 51 * 52 * @brief 53 * This module includes the platform abstraction for the adjacent infrastructure network interface. 54 * 55 * @{ 56 * 57 */ 58 59 /** 60 * Tells whether an infra interface has the given IPv6 address assigned. 61 * 62 * @param[in] aInfraIfIndex The index of the infra interface. 63 * @param[in] aAddress The IPv6 address. 64 * 65 * @returns TRUE if the infra interface has given IPv6 address assigned, FALSE otherwise. 66 * 67 */ 68 bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress); 69 70 /** 71 * Sends an ICMPv6 Neighbor Discovery message on given infrastructure interface. 72 * 73 * See RFC 4861: https://tools.ietf.org/html/rfc4861. 74 * 75 * @param[in] aInfraIfIndex The index of the infrastructure interface this message is sent to. 76 * @param[in] aDestAddress The destination address this message is sent to. 77 * @param[in] aBuffer The ICMPv6 message buffer. The ICMPv6 checksum is left zero and the 78 * platform should do the checksum calculate. 79 * @param[in] aBufferLength The length of the message buffer. 80 * 81 * @note Per RFC 4861, the implementation should send the message with IPv6 link-local source address 82 * of interface @p aInfraIfIndex and IP Hop Limit 255. 83 * 84 * @retval OT_ERROR_NONE Successfully sent the ICMPv6 message. 85 * @retval OT_ERROR_FAILED Failed to send the ICMPv6 message. 86 * 87 */ 88 otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex, 89 const otIp6Address *aDestAddress, 90 const uint8_t *aBuffer, 91 uint16_t aBufferLength); 92 93 /** 94 * The infra interface driver calls this method to notify OpenThread 95 * that an ICMPv6 Neighbor Discovery message is received. 96 * 97 * See RFC 4861: https://tools.ietf.org/html/rfc4861. 98 * 99 * @param[in] aInstance The OpenThread instance structure. 100 * @param[in] aInfraIfIndex The index of the infrastructure interface on which the ICMPv6 message is received. 101 * @param[in] aSrcAddress The source address this message is received from. 102 * @param[in] aBuffer The ICMPv6 message buffer. 103 * @param[in] aBufferLength The length of the ICMPv6 message buffer. 104 * 105 * @note Per RFC 4861, the caller should enforce that the source address MUST be a IPv6 link-local 106 * address and the IP Hop Limit MUST be 255. 107 * 108 */ 109 extern void otPlatInfraIfRecvIcmp6Nd(otInstance *aInstance, 110 uint32_t aInfraIfIndex, 111 const otIp6Address *aSrcAddress, 112 const uint8_t *aBuffer, 113 uint16_t aBufferLength); 114 115 /** 116 * The infra interface driver calls this method to notify OpenThread 117 * of the interface state changes. 118 * 119 * It is fine for the platform to call to method even when the running state 120 * of the interface hasn't changed. In this case, the Routing Manager state is 121 * not affected. 122 * 123 * @param[in] aInstance The OpenThread instance structure. 124 * @param[in] aInfraIfIndex The index of the infrastructure interface. 125 * @param[in] aIsRunning A boolean that indicates whether the infrastructure 126 * interface is running. 127 * 128 * @retval OT_ERROR_NONE Successfully updated the infra interface status. 129 * @retval OT_ERROR_INVALID_STATE The Routing Manager is not initialized. 130 * @retval OT_ERROR_INVALID_ARGS The @p aInfraIfIndex doesn't match the infra interface the 131 * Routing Manager are initialized with. 132 * 133 */ 134 extern otError otPlatInfraIfStateChanged(otInstance *aInstance, uint32_t aInfraIfIndex, bool aIsRunning); 135 136 /** 137 * Send a request to discover the NAT64 prefix on the infrastructure interface with @p aInfraIfIndex. 138 * 139 * OpenThread will call this method periodically to monitor the presence or change of NAT64 prefix. 140 * 141 * @param[in] aInfraIfIndex The index of the infrastructure interface to discover the NAT64 prefix. 142 * 143 * @retval OT_ERROR_NONE Successfully request NAT64 prefix discovery. 144 * @retval OT_ERROR_FAILED Failed to request NAT64 prefix discovery. 145 * 146 */ 147 otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex); 148 149 /** 150 * The infra interface driver calls this method to notify OpenThread that 151 * the discovery of NAT64 prefix is done. 152 * 153 * Is expected to be invoked after calling otPlatInfraIfDiscoverNat64Prefix. 154 * If no NAT64 prefix is discovered, @p aIp6Prefix shall point to an empty prefix with zero length. 155 * 156 * @param[in] aInstance The OpenThread instance structure. 157 * @param[in] aInfraIfIndex The index of the infrastructure interface on which the NAT64 prefix is discovered. 158 * @param[in] aIp6Prefix A pointer to NAT64 prefix. 159 * 160 */ 161 extern void otPlatInfraIfDiscoverNat64PrefixDone(otInstance *aInstance, 162 uint32_t aInfraIfIndex, 163 const otIp6Prefix *aIp6Prefix); 164 165 /** 166 * @} 167 * 168 */ 169 170 #ifdef __cplusplus 171 } // extern "C" 172 #endif 173 174 #endif // OPENTHREAD_PLATFORM_INFRA_IF_H_ 175