1 /* 2 * Copyright (c) 2018, 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 abstraction for the platform UDP service. 33 */ 34 35 #ifndef OPENTHREAD_PLATFORM_UDP_H_ 36 #define OPENTHREAD_PLATFORM_UDP_H_ 37 38 #include <openthread/udp.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /** 45 * Initializes the UDP socket by platform. 46 * 47 * @param[in] aUdpSocket A pointer to the UDP socket. 48 * 49 * @retval OT_ERROR_NONE Successfully initialized UDP socket by platform. 50 * @retval OT_ERROR_FAILED Failed to initialize UDP Socket. 51 * 52 */ 53 otError otPlatUdpSocket(otUdpSocket *aUdpSocket); 54 55 /** 56 * Closes the UDP socket by platform. 57 * 58 * @param[in] aUdpSocket A pointer to the UDP socket. 59 * 60 * @retval OT_ERROR_NONE Successfully closed UDP socket by platform. 61 * @retval OT_ERROR_FAILED Failed to close UDP Socket. 62 * 63 */ 64 otError otPlatUdpClose(otUdpSocket *aUdpSocket); 65 66 /** 67 * Binds the UDP socket by platform. 68 * 69 * @param[in] aUdpSocket A pointer to the UDP socket. 70 * 71 * @retval OT_ERROR_NONE Successfully bound UDP socket by platform. 72 * @retval OT_ERROR_FAILED Failed to bind UDP socket. 73 * 74 */ 75 otError otPlatUdpBind(otUdpSocket *aUdpSocket); 76 77 /** 78 * Binds the UDP socket to a platform network interface. 79 * 80 * Note: only available when `OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE` is used. 81 * 82 * @param[in] aUdpSocket A pointer to the UDP socket. 83 * @param[in] aNetifIdentifier The network interface identifier. 84 * 85 * @retval OT_ERROR_NONE Successfully bound UDP socket. 86 * @retval OT_ERROR_FAILED Failed to bind UDP. 87 * 88 */ 89 otError otPlatUdpBindToNetif(otUdpSocket *aUdpSocket, otNetifIdentifier aNetifIdentifier); 90 91 /** 92 * Connects UDP socket by platform. 93 * 94 * @param[in] aUdpSocket A pointer to the UDP socket. 95 * 96 * @retval OT_ERROR_NONE Successfully connected by platform. 97 * @retval OT_ERROR_FAILED Failed to connect UDP socket. 98 * 99 */ 100 otError otPlatUdpConnect(otUdpSocket *aUdpSocket); 101 102 /** 103 * Sends UDP payload by platform. 104 * 105 * @param[in] aUdpSocket A pointer to the UDP socket. 106 * @param[in] aMessage A pointer to the message to send. 107 * @param[in] aMessageInfo A pointer to the message info associated with @p aMessage. 108 * 109 * @retval OT_ERROR_NONE Successfully sent by platform, and @p aMessage is freed. 110 * @retval OT_ERROR_FAILED Failed to bind UDP socket. 111 * 112 */ 113 otError otPlatUdpSend(otUdpSocket *aUdpSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo); 114 115 /** 116 * Configures the UDP socket to join a UDP multicast group. 117 * 118 * Note: only available when `OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE` is used. 119 * 120 * @param[in] aUdpSocket A pointer to the UDP socket. 121 * @param[in] aNetifIdentifier The network interface identifier. 122 * @param[in] aAddress The UDP multicast group address. 123 * 124 * @retval OT_ERROR_NONE Successfully joined the multicast group. 125 * @retval OT_ERROR_FAILED Failed to join the multicast group. 126 * 127 */ 128 otError otPlatUdpJoinMulticastGroup(otUdpSocket *aUdpSocket, 129 otNetifIdentifier aNetifIdentifier, 130 const otIp6Address *aAddress); 131 132 /** 133 * Configures the UDP socket to leave a UDP multicast group. 134 * 135 * Note: only available when `OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE` is used. 136 * 137 * @param[in] aUdpSocket A pointer to the UDP socket. 138 * @param[in] aNetifIdentifier The network interface identifier. 139 * @param[in] aAddress The UDP multicast group address. 140 * 141 * @retval OT_ERROR_NONE Successfully left the multicast group. 142 * @retval OT_ERROR_FAILED Failed to leave the multicast group. 143 * 144 */ 145 otError otPlatUdpLeaveMulticastGroup(otUdpSocket *aUdpSocket, 146 otNetifIdentifier aNetifIdentifier, 147 const otIp6Address *aAddress); 148 149 #ifdef __cplusplus 150 } // extern "C" 151 #endif 152 153 #endif // OPENTHREAD_PLATFORM_UDP_H_ 154