• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
93 #if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
otSrpServerEnableFastStartMode(otInstance * aInstance)94 otError otSrpServerEnableFastStartMode(otInstance *aInstance)
95 {
96     return AsCoreType(aInstance).Get<Srp::Server>().EnableFastStartMode();
97 }
98 
otSrpServerIsFastStartModeEnabled(otInstance * aInstance)99 bool otSrpServerIsFastStartModeEnabled(otInstance *aInstance)
100 {
101     return AsCoreType(aInstance).Get<Srp::Server>().IsFastStartModeEnabled();
102 }
103 #endif
104 
otSrpServerGetTtlConfig(otInstance * aInstance,otSrpServerTtlConfig * aTtlConfig)105 void otSrpServerGetTtlConfig(otInstance *aInstance, otSrpServerTtlConfig *aTtlConfig)
106 {
107     AsCoreType(aInstance).Get<Srp::Server>().GetTtlConfig(AsCoreType(aTtlConfig));
108 }
109 
otSrpServerSetTtlConfig(otInstance * aInstance,const otSrpServerTtlConfig * aTtlConfig)110 otError otSrpServerSetTtlConfig(otInstance *aInstance, const otSrpServerTtlConfig *aTtlConfig)
111 {
112     return AsCoreType(aInstance).Get<Srp::Server>().SetTtlConfig(AsCoreType(aTtlConfig));
113 }
114 
otSrpServerGetLeaseConfig(otInstance * aInstance,otSrpServerLeaseConfig * aLeaseConfig)115 void otSrpServerGetLeaseConfig(otInstance *aInstance, otSrpServerLeaseConfig *aLeaseConfig)
116 {
117     AsCoreType(aInstance).Get<Srp::Server>().GetLeaseConfig(AsCoreType(aLeaseConfig));
118 }
119 
otSrpServerSetLeaseConfig(otInstance * aInstance,const otSrpServerLeaseConfig * aLeaseConfig)120 otError otSrpServerSetLeaseConfig(otInstance *aInstance, const otSrpServerLeaseConfig *aLeaseConfig)
121 {
122     return AsCoreType(aInstance).Get<Srp::Server>().SetLeaseConfig(AsCoreType(aLeaseConfig));
123 }
124 
otSrpServerSetServiceUpdateHandler(otInstance * aInstance,otSrpServerServiceUpdateHandler aServiceHandler,void * aContext)125 void otSrpServerSetServiceUpdateHandler(otInstance                     *aInstance,
126                                         otSrpServerServiceUpdateHandler aServiceHandler,
127                                         void                           *aContext)
128 {
129     AsCoreType(aInstance).Get<Srp::Server>().SetServiceHandler(aServiceHandler, aContext);
130 }
131 
otSrpServerHandleServiceUpdateResult(otInstance * aInstance,otSrpServerServiceUpdateId aId,otError aError)132 void otSrpServerHandleServiceUpdateResult(otInstance *aInstance, otSrpServerServiceUpdateId aId, otError aError)
133 {
134     AsCoreType(aInstance).Get<Srp::Server>().HandleServiceUpdateResult(aId, aError);
135 }
136 
otSrpServerGetNextHost(otInstance * aInstance,const otSrpServerHost * aHost)137 const otSrpServerHost *otSrpServerGetNextHost(otInstance *aInstance, const otSrpServerHost *aHost)
138 {
139     return AsCoreType(aInstance).Get<Srp::Server>().GetNextHost(AsCoreTypePtr(aHost));
140 }
141 
otSrpServerGetResponseCounters(otInstance * aInstance)142 const otSrpServerResponseCounters *otSrpServerGetResponseCounters(otInstance *aInstance)
143 {
144     return AsCoreType(aInstance).Get<Srp::Server>().GetResponseCounters();
145 }
146 
otSrpServerHostIsDeleted(const otSrpServerHost * aHost)147 bool otSrpServerHostIsDeleted(const otSrpServerHost *aHost) { return AsCoreType(aHost).IsDeleted(); }
148 
otSrpServerHostGetFullName(const otSrpServerHost * aHost)149 const char *otSrpServerHostGetFullName(const otSrpServerHost *aHost) { return AsCoreType(aHost).GetFullName(); }
150 
otSrpServerHostMatchesFullName(const otSrpServerHost * aHost,const char * aFullName)151 bool otSrpServerHostMatchesFullName(const otSrpServerHost *aHost, const char *aFullName)
152 {
153     return AsCoreType(aHost).Matches(aFullName);
154 }
155 
otSrpServerHostGetAddresses(const otSrpServerHost * aHost,uint8_t * aAddressesNum)156 const otIp6Address *otSrpServerHostGetAddresses(const otSrpServerHost *aHost, uint8_t *aAddressesNum)
157 {
158     return AsCoreType(aHost).GetAddresses(*aAddressesNum);
159 }
160 
otSrpServerHostGetLeaseInfo(const otSrpServerHost * aHost,otSrpServerLeaseInfo * aLeaseInfo)161 void otSrpServerHostGetLeaseInfo(const otSrpServerHost *aHost, otSrpServerLeaseInfo *aLeaseInfo)
162 {
163     AsCoreType(aHost).GetLeaseInfo(*aLeaseInfo);
164 }
165 
otSrpServerHostGetKeyLease(const otSrpServerHost * aHost)166 uint32_t otSrpServerHostGetKeyLease(const otSrpServerHost *aHost) { return AsCoreType(aHost).GetKeyLease(); }
167 
otSrpServerHostGetNextService(const otSrpServerHost * aHost,const otSrpServerService * aService)168 const otSrpServerService *otSrpServerHostGetNextService(const otSrpServerHost    *aHost,
169                                                         const otSrpServerService *aService)
170 {
171     return AsCoreType(aHost).GetNextService(AsCoreTypePtr(aService));
172 }
173 
otSrpServerServiceIsDeleted(const otSrpServerService * aService)174 bool otSrpServerServiceIsDeleted(const otSrpServerService *aService) { return AsCoreType(aService).IsDeleted(); }
175 
otSrpServerServiceGetInstanceName(const otSrpServerService * aService)176 const char *otSrpServerServiceGetInstanceName(const otSrpServerService *aService)
177 {
178     return AsCoreType(aService).GetInstanceName();
179 }
180 
otSrpServerServiceMatchesInstanceName(const otSrpServerService * aService,const char * aInstanceName)181 bool otSrpServerServiceMatchesInstanceName(const otSrpServerService *aService, const char *aInstanceName)
182 {
183     return AsCoreType(aService).MatchesInstanceName(aInstanceName);
184 }
185 
otSrpServerServiceGetInstanceLabel(const otSrpServerService * aService)186 const char *otSrpServerServiceGetInstanceLabel(const otSrpServerService *aService)
187 {
188     return AsCoreType(aService).GetInstanceLabel();
189 }
190 
otSrpServerServiceGetServiceName(const otSrpServerService * aService)191 const char *otSrpServerServiceGetServiceName(const otSrpServerService *aService)
192 {
193     return AsCoreType(aService).GetServiceName();
194 }
195 
otSrpServerServiceMatchesServiceName(const otSrpServerService * aService,const char * aServiceName)196 bool otSrpServerServiceMatchesServiceName(const otSrpServerService *aService, const char *aServiceName)
197 {
198     return AsCoreType(aService).MatchesServiceName(aServiceName);
199 }
200 
otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService * aService)201 uint16_t otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService *aService)
202 {
203     return AsCoreType(aService).GetNumberOfSubTypes();
204 }
205 
otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService * aService,uint16_t aIndex)206 const char *otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService *aService, uint16_t aIndex)
207 {
208     return AsCoreType(aService).GetSubTypeServiceNameAt(aIndex);
209 }
210 
otSrpServerServiceHasSubTypeServiceName(const otSrpServerService * aService,const char * aSubTypeServiceName)211 bool otSrpServerServiceHasSubTypeServiceName(const otSrpServerService *aService, const char *aSubTypeServiceName)
212 {
213     return AsCoreType(aService).HasSubTypeServiceName(aSubTypeServiceName);
214 }
215 
otSrpServerParseSubTypeServiceName(const char * aSubTypeServiceName,char * aLabel,uint8_t aLabelSize)216 otError otSrpServerParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize)
217 {
218     return Srp::Server::Service::ParseSubTypeServiceName(aSubTypeServiceName, aLabel, aLabelSize);
219 }
220 
otSrpServerServiceGetPort(const otSrpServerService * aService)221 uint16_t otSrpServerServiceGetPort(const otSrpServerService *aService) { return AsCoreType(aService).GetPort(); }
222 
otSrpServerServiceGetWeight(const otSrpServerService * aService)223 uint16_t otSrpServerServiceGetWeight(const otSrpServerService *aService) { return AsCoreType(aService).GetWeight(); }
224 
otSrpServerServiceGetPriority(const otSrpServerService * aService)225 uint16_t otSrpServerServiceGetPriority(const otSrpServerService *aService)
226 {
227     return AsCoreType(aService).GetPriority();
228 }
229 
otSrpServerServiceGetTtl(const otSrpServerService * aService)230 uint32_t otSrpServerServiceGetTtl(const otSrpServerService *aService) { return AsCoreType(aService).GetTtl(); }
231 
otSrpServerServiceGetTxtData(const otSrpServerService * aService,uint16_t * aDataLength)232 const uint8_t *otSrpServerServiceGetTxtData(const otSrpServerService *aService, uint16_t *aDataLength)
233 {
234     *aDataLength = AsCoreType(aService).GetTxtDataLength();
235 
236     return AsCoreType(aService).GetTxtData();
237 }
238 
otSrpServerServiceGetHost(const otSrpServerService * aService)239 const otSrpServerHost *otSrpServerServiceGetHost(const otSrpServerService *aService)
240 {
241     return &AsCoreType(aService).GetHost();
242 }
243 
otSrpServerServiceGetLeaseInfo(const otSrpServerService * aService,otSrpServerLeaseInfo * aLeaseInfo)244 void otSrpServerServiceGetLeaseInfo(const otSrpServerService *aService, otSrpServerLeaseInfo *aLeaseInfo)
245 {
246     AsCoreType(aService).GetLeaseInfo(*aLeaseInfo);
247 }
248 
249 #endif // OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
250