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 ******************************************************************/
24 * This file contains the APIs for Resource Model to use.
27 #ifndef CA_INTERFACE_H_
28 #define CA_INTERFACE_H_
31 * Connectivity Abstraction Interface APIs.
36 #include "ocsecurityconfig.h"
45 * @brief Callback function type for request delivery.
46 * @param object [OUT] Endpoint object from which the request is received. It contains
47 * endpoint address based on the connectivity type.
48 * @param requestInfo [OUT] Info for resource model to understand about the request.
51 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
52 const CARequestInfo_t *requestInfo);
55 * @brief Callback function type for response delivery.
56 * @param object [OUT] Endpoint object from which the response is received.
57 * @param responseInfo [OUT] Identifier which needs to be mapped with response.
60 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
61 const CAResponseInfo_t *responseInfo);
63 * @brief Callback function type for error
64 * @param object [OUT] remote device information
65 * @param errorInfo [OUT] CA Error information
68 typedef void (*CAErrorCallback)(const CARemoteEndpoint_t *object,
69 const CAErrorInfo_t *errorInfo);
74 * Binary blob containing device identity and the credentials for all devices
75 * trusted by this device.
79 unsigned char identity[DTLS_PSK_ID_LEN]; /** identity of self */
80 uint32_t num; /** number of credentials in this blob */
81 OCDtlsPskCreds *creds; /** list of credentials. Size of this
82 array is determined by 'num' variable. */
83 } CADtlsPskCredsBlob_t;
86 * @brief Callback function type for getting DTLS credentials.
87 * @param credInfo [OUT] DTLS credentials info. Handler has to allocate new memory for
88 * both credInfo and credInfo->creds which is then freed by CA
91 typedef void (*CAGetDTLSCredentialsHandler)(CADtlsPskCredsBlob_t **credInfo);
92 #endif //__WITH_DTLS__
95 * @brief Initialize the connectivity abstraction module.
96 * It will initialize adapters, thread pool and other modules based on the platform
97 * compilation options.
99 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
101 CAResult_t CAInitialize();
104 * @brief Terminate the connectivity abstraction module.
105 * All threads, data structures are destroyed for next initializations.
111 * @brief Starts listening servers.
112 * This API is used by resource hosting server for listening multicast requests.
113 * Based on the adapters configurations, different kinds of servers are started.
114 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
116 CAResult_t CAStartListeningServer();
119 * @brief Starts discovery servers.
120 * This API is used by resource required clients for listening multicast requests.
121 * Based on the adapters configurations, different kinds of servers are started.
122 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
124 CAResult_t CAStartDiscoveryServer();
127 * @brief Register request callbacks and response callbacks.
128 * Requests and responses are delivered these callbacks .
129 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
130 * @param RespHandler [IN] Response Handler Callback
131 * @see CARequestCallback
132 * @see CAResponseCallback
133 * @see CAErrorCallback
136 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
137 CAErrorCallback ErrorHandler);
141 * @brief Register callback to get DTLS PSK credentials.
142 * @param GetDTLSCredentials [IN] GetDTLS Credetials callback
143 * @return #CA_STATUS_OK
145 CAResult_t CARegisterDTLSCredentialsHandler(
146 CAGetDTLSCredentialsHandler GetDTLSCredentials);
147 #endif //__WITH_DTLS__
150 * @brief Create a Remote endpoint if the URI is available already.
151 * This is a Helper function which can be used before calling
152 * CASendRequest / CASendNotification.
153 * @param uri [IN] Absolute URI of the resource to be used to generate the
155 * \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
156 * \n coap://10:11:12:13:45:45/resource_uri ( for BT)
157 * @param transportType [IN] Transport type of the endpoint
158 * @param object [OUT] Endpoint object which contains the above parsed data
159 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
160 * @remark The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
161 * @see CADestroyRemoteEndpoint
163 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
164 const CATransportType_t transportType,
165 CARemoteEndpoint_t **object);
168 * @brief Destroy the remote endpoint created
169 * @param object [IN] Remote Endpoint object created with CACreateRemoteEndpoint
172 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
175 * @brief Generating the token for matching the request and response.
176 * @param token [OUT] Token for the request
177 * @param tokenLength [IN] length of the token
178 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
179 * or #CA_STATUS_NOT_INITIALIZED
180 * @remark Token memory is destroyed by the caller using CADestroyToken().
181 * @see CADestroyToken
183 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
186 * @brief Destroy the token generated by CAGenerateToken
187 * @param token [IN] token to be freed
190 void CADestroyToken(CAToken_t token);
193 * @brief Find the resource in the network. This API internally sends multicast messages on all
194 * selected connectivity adapters. Responses are delivered via response callbacks.
196 * @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
197 * path of Uri to be search.
198 * @param token [IN] Token for the request
199 * @param tokenLength [IN] length of the token
200 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_NOT_INITIALIZED
202 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength);
205 * @brief Send control Request on a resource
206 * @param object [IN] Remote Endpoint where the payload need to be sent.
207 * This Remote endpoint is delivered with Request or response callback.
208 * @param requestInfo [IN] Information for the request.
209 * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
211 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo);
214 * @brief Send control Request on a resource to multicast group
215 * @param object [IN] Group Endpoint where the payload need to be sent.
216 * This Remote endpoint is delivered with Request or response callback.
217 * @param requestInfo [IN] Information for the request.
218 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
220 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
221 const CARequestInfo_t *requestInfo);
224 * @brief Send the response
225 * @param object [IN] Remote Endpoint where the payload need to be sent.
226 * This Remote endpoint is delivered with Request or response callback
227 * @param responseInfo [IN] Information for the response
228 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
230 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
231 const CAResponseInfo_t *responseInfo);
234 * @brief Send notification to the remote object
235 * @param object [IN] Remote Endpoint where the payload need to be sent.
236 * This Remote endpoint is delivered with Request or response callback.
237 * @param responseInfo [IN] Information for the response.
238 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
240 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
241 const CAResponseInfo_t *responseInfo);
244 * @brief To advertise the resource
245 * @param resourceUri [IN] URI to be advertised
246 * @param token [IN] Token for the request
247 * @param tokenLength [IN] length of the token
248 * @param options [IN] Header options information
249 * @param numOptions [IN] Number of options
250 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or
251 * #CA_MEMORY_ALLOC_FAILED or #CA_STATUS_NOT_INITIALIZED
253 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
254 uint8_t tokenLength, const CAHeaderOption_t *options,
255 const uint8_t numOptions);
258 * @brief Select network to use
259 * @param interestedNetwork [IN] Connectivity Type enum
260 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
262 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
265 * @brief Select network to unuse
266 * @param nonInterestedNetwork [IN] Connectivity Type enum
267 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
269 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
272 * @brief Get network information
273 * It should be destroyed by the caller as it Get Information.
274 * @param info [OUT] LocalConnectivity objects
275 * @param size [OUT] No Of Array objects
276 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
277 * #CA_MEMORY_ALLOC_FAILED
279 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
282 * @brief To Handle the Request or Response
283 * @return #CA_STATUS_OK
285 CAResult_t CAHandleRequestResponse();
291 #endif /* CA_INTERFACE_H_ */