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  * This method tells whether an infra interface has the given IPv6 address assigned.
51  *
52  * @param[in]  aInfraIfIndex  The index of the infra interface.
53  * @param[in]  aAddress       The IPv6 address.
54  *
55  * @returns  TRUE if the infra interface has given IPv6 address assigned, FALSE otherwise.
56  *
57  */
58 bool otPlatInfraIfHasAddress(uint32_t aInfraIfIndex, const otIp6Address *aAddress);
59 
60 /**
61  * This method sends an ICMPv6 Neighbor Discovery message on given infrastructure interface.
62  *
63  * See RFC 4861: https://tools.ietf.org/html/rfc4861.
64  *
65  * @param[in]  aInfraIfIndex  The index of the infrastructure interface this message is sent to.
66  * @param[in]  aDestAddress   The destination address this message is sent to.
67  * @param[in]  aBuffer        The ICMPv6 message buffer. The ICMPv6 checksum is left zero and the
68  *                            platform should do the checksum calculate.
69  * @param[in]  aBufferLength  The length of the message buffer.
70  *
71  * @note  Per RFC 4861, the implementation should send the message with IPv6 link-local source address
72  *        of interface @p aInfraIfIndex and IP Hop Limit 255.
73  *
74  * @retval OT_ERROR_NONE    Successfully sent the ICMPv6 message.
75  * @retval OT_ERROR_FAILED  Failed to send the ICMPv6 message.
76  *
77  */
78 otError otPlatInfraIfSendIcmp6Nd(uint32_t            aInfraIfIndex,
79                                  const otIp6Address *aDestAddress,
80                                  const uint8_t *     aBuffer,
81                                  uint16_t            aBufferLength);
82 
83 /**
84  * The infra interface driver calls this method to notify OpenThread
85  * that an ICMPv6 Neighbor Discovery message is received.
86  *
87  * See RFC 4861: https://tools.ietf.org/html/rfc4861.
88  *
89  * @param[in]  aInstance      The OpenThread instance structure.
90  * @param[in]  aInfraIfIndex  The index of the infrastructure interface on which the ICMPv6 message is received.
91  * @param[in]  aSrcAddress    The source address this message is received from.
92  * @param[in]  aBuffer        The ICMPv6 message buffer.
93  * @param[in]  aBufferLength  The length of the ICMPv6 message buffer.
94  *
95  * @note  Per RFC 4861, the caller should enforce that the source address MUST be a IPv6 link-local
96  *        address and the IP Hop Limit MUST be 255.
97  *
98  */
99 extern void otPlatInfraIfRecvIcmp6Nd(otInstance *        aInstance,
100                                      uint32_t            aInfraIfIndex,
101                                      const otIp6Address *aSrcAddress,
102                                      const uint8_t *     aBuffer,
103                                      uint16_t            aBufferLength);
104 
105 /**
106  * The infra interface driver calls this method to notify OpenThread
107  * of the interface state changes.
108  *
109  * It is fine for the platform to call to method even when the running state
110  * of the interface hasn't changed. In this case, the Routing Manager state is
111  * not affected.
112  *
113  * @param[in]  aInstance          The OpenThread instance structure.
114  * @param[in]  aInfraIfIndex      The index of the infrastructure interface.
115  * @param[in]  aIsRunning         A boolean that indicates whether the infrastructure
116  *                                interface is running.
117  *
118  * @retval  OT_ERROR_NONE           Successfully updated the infra interface status.
119  * @retval  OT_ERROR_INVALID_STATE  The Routing Manager is not initialized.
120  * @retval  OT_ERROR_INVALID_ARGS   The @p aInfraIfIndex doesn't match the infra interface the
121  *                                  Routing Manager are initialized with.
122  *
123  */
124 extern otError otPlatInfraIfStateChanged(otInstance *aInstance, uint32_t aInfraIfIndex, bool aIsRunning);
125 
126 #ifdef __cplusplus
127 } // extern "C"
128 #endif
129 
130 #endif // OPENTHREAD_PLATFORM_INFRA_IF_H_
131