1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
23 * @brief This file contains the APIs for Resource Model to use
26 #ifndef __CA_INTERFACE_H_
27 #define __CA_INTERFACE_H_
30 * Connectivity Abstraction Interface Description APIs.
35 #include "ocsecurityconfig.h"
44 * @brief Callback function type for request delivery.
45 * @param object [OUT] Endpoint object from which the request is received. It contains
46 * endpoint address based on the connectivity type.
47 * @param requestInfo [OUT] Info for resource model to understand about the request.
50 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
51 const CARequestInfo_t *requestInfo);
54 * @brief Callback function type for response delivery.
55 * @param object [OUT] Endpoint object from which the response is received.
56 * @param responseInfo [OUT] Identifier which needs to be mapped with response.
59 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
60 const CAResponseInfo_t *responseInfo);
64 * @brief Callback function type for getting DTLS credentials.
65 * @param credInfo [OUT] DTLS credentials info
68 typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
69 #endif //__WITH_DTLS__
72 * @brief Initialize the connectivity abstraction module.
73 * It will initialize adapters, thread pool and other modules based on the platform
74 * compilation options.
76 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
78 CAResult_t CAInitialize();
81 * @brief Terminate the connectivity abstraction module.
82 * All threads, data structures are destroyed for next initializations.
88 * @brief Starts listening servers.
89 * This API is used by resource hosting server for listening multicast requests.
90 * Based on the adapters configurations, different kinds of servers are started.
91 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
93 CAResult_t CAStartListeningServer();
96 * @brief Starts discovery servers.
97 * This API is used by resource required clients for listening multicast requests.
98 * Based on the adapters configurations, different kinds of servers are started.
99 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
101 CAResult_t CAStartDiscoveryServer();
104 * @brief Register request callbacks and response callbacks.
105 * Requests and responses are delivered these callbacks .
106 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
107 * @param RespHandler [IN] Response Handler Callback
108 * @see CARequestCallback
109 * @see CAResponseCallback
111 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
115 * @brief Register callback to get DTLS PSK credentials.
116 * @param GetDTLSCredentials [IN] GetDTLS Credetials callback
117 * @return #CA_STATUS_OK
119 CAResult_t CARegisterDTLSCredentialsHandler(
120 CAGetDTLSCredentialsHandler GetDTLSCredentials);
121 #endif //__WITH_DTLS__
124 * @brief Create a Remote endpoint if the URI is available already.
125 * This is a Helper function which can be used before calling
126 * CASendRequest / CASendNotification.
127 * @param uri [IN] Absolute URI of the resource to be used to generate the
129 * \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
130 * \n coap://10:11:12:13:45:45/resource_uri ( for BT)
131 * @param connectivityType [IN] Connectivity type of the endpoint
132 * @param object [OUT] Endpoint object which contains the above parsed data
133 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
134 * @remark The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
135 * @see CADestroyRemoteEndpoint
137 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
138 const CAConnectivityType_t connectivityType,
139 CARemoteEndpoint_t **object);
142 * @brief Destroy the remote endpoint created
143 * @param object [IN] Remote Endpoint object created with CACreateRemoteEndpoint
146 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
149 * @brief Generating the token for matching the request and response.
150 * @param token [OUT] Token for the request
151 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
152 * @remark Token memory is destroyed by the caller using CADestroyToken().
153 * @see CADestroyToken
155 CAResult_t CAGenerateToken(CAToken_t *token);
158 * @brief Destroy the token generated by CAGenerateToken
159 * @param token [IN] Token for the request
162 void CADestroyToken(CAToken_t token);
165 * @brief Find the resource in the network. This API internally sends multicast messages on all
166 * selected connectivity adapters. Responses are delivered via response callbacks.
168 * @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
169 * path of Uri to be search.
170 * @param token [IN] Token for the request
171 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
173 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
176 * @brief Send control Request on a resource
177 * @param object [IN] Remote Endpoint where the payload need to be sent.
178 * This Remote endpoint is delivered with Request or response callback.
179 * @param requestInfo [IN] Information for the request.
180 * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
182 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
185 * @brief Send control Request on a resource to multicast group
186 * @param object [IN] Group Endpoint where the payload need to be sent.
187 * This Remote endpoint is delivered with Request or response callback.
188 * @param requestInfo [IN] Information for the request.
189 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
191 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
192 const CARequestInfo_t *requestInfo);
195 * @brief Send the response
196 * @param object [IN] Remote Endpoint where the payload need to be sent.
197 * This Remote endpoint is delivered with Request or response callback
198 * @param responseInfo [IN] Information for the response
199 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
201 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
204 * @brief Send notification to the remote object
205 * @param object [IN] Remote Endpoint where the payload need to be sent.
206 * This Remote endpoint is delivered with Request or response callback.
207 * @param responseInfo [IN] Information for the response.
208 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
210 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
211 CAResponseInfo_t *responseInfo);
214 * @brief To advertise the resource
215 * @param resourceUri [IN] URI to be advertised
216 * @param token [IN] Token for the request
217 * @param options [IN] Header options information
218 * @param numOptions [IN] Number of options
219 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
221 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
222 CAHeaderOption_t *options, uint8_t numOptions);
225 * @brief Select network to use
226 * @param interestedNetwork [IN] Connectivity Type enum
227 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
229 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
232 * @brief Select network to unuse
233 * @param nonInterestedNetwork [IN] Connectivity Type enum
234 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
236 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
239 * @brief Get network information
240 * It should be destroyed by the caller as it Get Information.
241 * @param info [OUT] LocalConnectivity objects
242 * @param size [OUT] No Of Array objects
243 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or #CA_MEMORY_ALLOC_FAILED
245 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
248 * @brief To Handle the Request or Response
249 * @return #CA_STATUS_OK
251 CAResult_t CAHandleRequestResponse();