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 * This file defines the OpenThread SRP server API.
32 */
33
34 #include "openthread-core-config.h"
35
36 #if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
37
38 #include "instance/instance.hpp"
39
40 using namespace ot;
41
otSrpServerGetDomain(otInstance * aInstance)42 const char *otSrpServerGetDomain(otInstance *aInstance) { return AsCoreType(aInstance).Get<Srp::Server>().GetDomain(); }
43
otSrpServerSetDomain(otInstance * aInstance,const char * aDomain)44 otError otSrpServerSetDomain(otInstance *aInstance, const char *aDomain)
45 {
46 return AsCoreType(aInstance).Get<Srp::Server>().SetDomain(aDomain);
47 }
48
otSrpServerGetState(otInstance * aInstance)49 otSrpServerState otSrpServerGetState(otInstance *aInstance)
50 {
51 return MapEnum(AsCoreType(aInstance).Get<Srp::Server>().GetState());
52 }
53
otSrpServerGetPort(otInstance * aInstance)54 uint16_t otSrpServerGetPort(otInstance *aInstance) { return AsCoreType(aInstance).Get<Srp::Server>().GetPort(); }
55
otSrpServerGetAddressMode(otInstance * aInstance)56 otSrpServerAddressMode otSrpServerGetAddressMode(otInstance *aInstance)
57 {
58 return MapEnum(AsCoreType(aInstance).Get<Srp::Server>().GetAddressMode());
59 }
60
otSrpServerSetAddressMode(otInstance * aInstance,otSrpServerAddressMode aMode)61 otError otSrpServerSetAddressMode(otInstance *aInstance, otSrpServerAddressMode aMode)
62 {
63 return AsCoreType(aInstance).Get<Srp::Server>().SetAddressMode(MapEnum(aMode));
64 }
65
otSrpServerGetAnycastModeSequenceNumber(otInstance * aInstance)66 uint8_t otSrpServerGetAnycastModeSequenceNumber(otInstance *aInstance)
67 {
68 return AsCoreType(aInstance).Get<Srp::Server>().GetAnycastModeSequenceNumber();
69 }
70
otSrpServerSetAnycastModeSequenceNumber(otInstance * aInstance,uint8_t aSequenceNumber)71 otError otSrpServerSetAnycastModeSequenceNumber(otInstance *aInstance, uint8_t aSequenceNumber)
72 {
73 return AsCoreType(aInstance).Get<Srp::Server>().SetAnycastModeSequenceNumber(aSequenceNumber);
74 }
75
otSrpServerSetEnabled(otInstance * aInstance,bool aEnabled)76 void otSrpServerSetEnabled(otInstance *aInstance, bool aEnabled)
77 {
78 AsCoreType(aInstance).Get<Srp::Server>().SetEnabled(aEnabled);
79 }
80
81 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
otSrpServerSetAutoEnableMode(otInstance * aInstance,bool aEnabled)82 void otSrpServerSetAutoEnableMode(otInstance *aInstance, bool aEnabled)
83 {
84 AsCoreType(aInstance).Get<Srp::Server>().SetAutoEnableMode(aEnabled);
85 }
86
otSrpServerIsAutoEnableMode(otInstance * aInstance)87 bool otSrpServerIsAutoEnableMode(otInstance *aInstance)
88 {
89 return AsCoreType(aInstance).Get<Srp::Server>().IsAutoEnableMode();
90 }
91 #endif
92
otSrpServerGetTtlConfig(otInstance * aInstance,otSrpServerTtlConfig * aTtlConfig)93 void otSrpServerGetTtlConfig(otInstance *aInstance, otSrpServerTtlConfig *aTtlConfig)
94 {
95 AsCoreType(aInstance).Get<Srp::Server>().GetTtlConfig(AsCoreType(aTtlConfig));
96 }
97
otSrpServerSetTtlConfig(otInstance * aInstance,const otSrpServerTtlConfig * aTtlConfig)98 otError otSrpServerSetTtlConfig(otInstance *aInstance, const otSrpServerTtlConfig *aTtlConfig)
99 {
100 return AsCoreType(aInstance).Get<Srp::Server>().SetTtlConfig(AsCoreType(aTtlConfig));
101 }
102
otSrpServerGetLeaseConfig(otInstance * aInstance,otSrpServerLeaseConfig * aLeaseConfig)103 void otSrpServerGetLeaseConfig(otInstance *aInstance, otSrpServerLeaseConfig *aLeaseConfig)
104 {
105 AsCoreType(aInstance).Get<Srp::Server>().GetLeaseConfig(AsCoreType(aLeaseConfig));
106 }
107
otSrpServerSetLeaseConfig(otInstance * aInstance,const otSrpServerLeaseConfig * aLeaseConfig)108 otError otSrpServerSetLeaseConfig(otInstance *aInstance, const otSrpServerLeaseConfig *aLeaseConfig)
109 {
110 return AsCoreType(aInstance).Get<Srp::Server>().SetLeaseConfig(AsCoreType(aLeaseConfig));
111 }
112
otSrpServerSetServiceUpdateHandler(otInstance * aInstance,otSrpServerServiceUpdateHandler aServiceHandler,void * aContext)113 void otSrpServerSetServiceUpdateHandler(otInstance *aInstance,
114 otSrpServerServiceUpdateHandler aServiceHandler,
115 void *aContext)
116 {
117 AsCoreType(aInstance).Get<Srp::Server>().SetServiceHandler(aServiceHandler, aContext);
118 }
119
otSrpServerHandleServiceUpdateResult(otInstance * aInstance,otSrpServerServiceUpdateId aId,otError aError)120 void otSrpServerHandleServiceUpdateResult(otInstance *aInstance, otSrpServerServiceUpdateId aId, otError aError)
121 {
122 AsCoreType(aInstance).Get<Srp::Server>().HandleServiceUpdateResult(aId, aError);
123 }
124
otSrpServerGetNextHost(otInstance * aInstance,const otSrpServerHost * aHost)125 const otSrpServerHost *otSrpServerGetNextHost(otInstance *aInstance, const otSrpServerHost *aHost)
126 {
127 return AsCoreType(aInstance).Get<Srp::Server>().GetNextHost(AsCoreTypePtr(aHost));
128 }
129
otSrpServerGetResponseCounters(otInstance * aInstance)130 const otSrpServerResponseCounters *otSrpServerGetResponseCounters(otInstance *aInstance)
131 {
132 return AsCoreType(aInstance).Get<Srp::Server>().GetResponseCounters();
133 }
134
otSrpServerHostIsDeleted(const otSrpServerHost * aHost)135 bool otSrpServerHostIsDeleted(const otSrpServerHost *aHost) { return AsCoreType(aHost).IsDeleted(); }
136
otSrpServerHostGetFullName(const otSrpServerHost * aHost)137 const char *otSrpServerHostGetFullName(const otSrpServerHost *aHost) { return AsCoreType(aHost).GetFullName(); }
138
otSrpServerHostMatchesFullName(const otSrpServerHost * aHost,const char * aFullName)139 bool otSrpServerHostMatchesFullName(const otSrpServerHost *aHost, const char *aFullName)
140 {
141 return AsCoreType(aHost).Matches(aFullName);
142 }
143
otSrpServerHostGetAddresses(const otSrpServerHost * aHost,uint8_t * aAddressesNum)144 const otIp6Address *otSrpServerHostGetAddresses(const otSrpServerHost *aHost, uint8_t *aAddressesNum)
145 {
146 return AsCoreType(aHost).GetAddresses(*aAddressesNum);
147 }
148
otSrpServerHostGetLeaseInfo(const otSrpServerHost * aHost,otSrpServerLeaseInfo * aLeaseInfo)149 void otSrpServerHostGetLeaseInfo(const otSrpServerHost *aHost, otSrpServerLeaseInfo *aLeaseInfo)
150 {
151 AsCoreType(aHost).GetLeaseInfo(*aLeaseInfo);
152 }
153
otSrpServerHostGetKeyLease(const otSrpServerHost * aHost)154 uint32_t otSrpServerHostGetKeyLease(const otSrpServerHost *aHost) { return AsCoreType(aHost).GetKeyLease(); }
155
otSrpServerHostGetNextService(const otSrpServerHost * aHost,const otSrpServerService * aService)156 const otSrpServerService *otSrpServerHostGetNextService(const otSrpServerHost *aHost,
157 const otSrpServerService *aService)
158 {
159 return AsCoreType(aHost).GetNextService(AsCoreTypePtr(aService));
160 }
161
otSrpServerServiceIsDeleted(const otSrpServerService * aService)162 bool otSrpServerServiceIsDeleted(const otSrpServerService *aService) { return AsCoreType(aService).IsDeleted(); }
163
otSrpServerServiceGetInstanceName(const otSrpServerService * aService)164 const char *otSrpServerServiceGetInstanceName(const otSrpServerService *aService)
165 {
166 return AsCoreType(aService).GetInstanceName();
167 }
168
otSrpServerServiceMatchesInstanceName(const otSrpServerService * aService,const char * aInstanceName)169 bool otSrpServerServiceMatchesInstanceName(const otSrpServerService *aService, const char *aInstanceName)
170 {
171 return AsCoreType(aService).MatchesInstanceName(aInstanceName);
172 }
173
otSrpServerServiceGetInstanceLabel(const otSrpServerService * aService)174 const char *otSrpServerServiceGetInstanceLabel(const otSrpServerService *aService)
175 {
176 return AsCoreType(aService).GetInstanceLabel();
177 }
178
otSrpServerServiceGetServiceName(const otSrpServerService * aService)179 const char *otSrpServerServiceGetServiceName(const otSrpServerService *aService)
180 {
181 return AsCoreType(aService).GetServiceName();
182 }
183
otSrpServerServiceMatchesServiceName(const otSrpServerService * aService,const char * aServiceName)184 bool otSrpServerServiceMatchesServiceName(const otSrpServerService *aService, const char *aServiceName)
185 {
186 return AsCoreType(aService).MatchesServiceName(aServiceName);
187 }
188
otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService * aService)189 uint16_t otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService *aService)
190 {
191 return AsCoreType(aService).GetNumberOfSubTypes();
192 }
193
otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService * aService,uint16_t aIndex)194 const char *otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService *aService, uint16_t aIndex)
195 {
196 return AsCoreType(aService).GetSubTypeServiceNameAt(aIndex);
197 }
198
otSrpServerServiceHasSubTypeServiceName(const otSrpServerService * aService,const char * aSubTypeServiceName)199 bool otSrpServerServiceHasSubTypeServiceName(const otSrpServerService *aService, const char *aSubTypeServiceName)
200 {
201 return AsCoreType(aService).HasSubTypeServiceName(aSubTypeServiceName);
202 }
203
otSrpServerParseSubTypeServiceName(const char * aSubTypeServiceName,char * aLabel,uint8_t aLabelSize)204 otError otSrpServerParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize)
205 {
206 return Srp::Server::Service::ParseSubTypeServiceName(aSubTypeServiceName, aLabel, aLabelSize);
207 }
208
otSrpServerServiceGetPort(const otSrpServerService * aService)209 uint16_t otSrpServerServiceGetPort(const otSrpServerService *aService) { return AsCoreType(aService).GetPort(); }
210
otSrpServerServiceGetWeight(const otSrpServerService * aService)211 uint16_t otSrpServerServiceGetWeight(const otSrpServerService *aService) { return AsCoreType(aService).GetWeight(); }
212
otSrpServerServiceGetPriority(const otSrpServerService * aService)213 uint16_t otSrpServerServiceGetPriority(const otSrpServerService *aService)
214 {
215 return AsCoreType(aService).GetPriority();
216 }
217
otSrpServerServiceGetTtl(const otSrpServerService * aService)218 uint32_t otSrpServerServiceGetTtl(const otSrpServerService *aService) { return AsCoreType(aService).GetTtl(); }
219
otSrpServerServiceGetTxtData(const otSrpServerService * aService,uint16_t * aDataLength)220 const uint8_t *otSrpServerServiceGetTxtData(const otSrpServerService *aService, uint16_t *aDataLength)
221 {
222 *aDataLength = AsCoreType(aService).GetTxtDataLength();
223
224 return AsCoreType(aService).GetTxtData();
225 }
226
otSrpServerServiceGetHost(const otSrpServerService * aService)227 const otSrpServerHost *otSrpServerServiceGetHost(const otSrpServerService *aService)
228 {
229 return &AsCoreType(aService).GetHost();
230 }
231
otSrpServerServiceGetLeaseInfo(const otSrpServerService * aService,otSrpServerLeaseInfo * aLeaseInfo)232 void otSrpServerServiceGetLeaseInfo(const otSrpServerService *aService, otSrpServerLeaseInfo *aLeaseInfo)
233 {
234 AsCoreType(aService).GetLeaseInfo(*aLeaseInfo);
235 }
236
237 #endif // OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
238