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