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);
65 * @brief Callback function type for getting DTLS credentials.
66 * @param credInfo [OUT] DTLS credentials info
69 typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
70 #endif //__WITH_DTLS__
73 * @brief Initialize the connectivity abstraction module.
74 * It will initialize adapters, thread pool and other modules based on the platform
75 * compilation options.
77 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
79 CAResult_t CAInitialize();
82 * @brief Terminate the connectivity abstraction module.
83 * All threads, data structures are destroyed for next initializations.
89 * @brief Starts listening servers.
90 * This API is used by resource hosting server for listening multicast requests.
91 * Based on the adapters configurations, different kinds of servers are started.
92 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
94 CAResult_t CAStartListeningServer();
97 * @brief Starts discovery servers.
98 * This API is used by resource required clients for listening multicast requests.
99 * Based on the adapters configurations, different kinds of servers are started.
100 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
102 CAResult_t CAStartDiscoveryServer();
105 * @brief Register request callbacks and response callbacks.
106 * Requests and responses are delivered these callbacks .
107 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
108 * @param RespHandler [IN] Response Handler Callback
109 * @see CARequestCallback
110 * @see CAResponseCallback
113 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
117 * @brief Register callback to get DTLS PSK credentials.
118 * @param GetDTLSCredentials [IN] GetDTLS Credetials callback
119 * @return #CA_STATUS_OK
121 CAResult_t CARegisterDTLSCredentialsHandler(
122 CAGetDTLSCredentialsHandler GetDTLSCredentials);
123 #endif //__WITH_DTLS__
126 * @brief Create a Remote endpoint if the URI is available already.
127 * This is a Helper function which can be used before calling
128 * CASendRequest / CASendNotification.
129 * @param uri [IN] Absolute URI of the resource to be used to generate the
131 * \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
132 * \n coap://10:11:12:13:45:45/resource_uri ( for BT)
133 * @param connectivityType [IN] Connectivity type of the endpoint
134 * @param object [OUT] Endpoint object which contains the above parsed data
135 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
136 * @remark The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
137 * @see CADestroyRemoteEndpoint
139 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
140 const CAConnectivityType_t connectivityType,
141 CARemoteEndpoint_t **object);
144 * @brief Destroy the remote endpoint created
145 * @param object [IN] Remote Endpoint object created with CACreateRemoteEndpoint
148 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
151 * @brief Generating the token for matching the request and response.
152 * @param token [OUT] Token for the request
153 * @param tokenLength [IN] length of the token
154 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
155 * or #CA_STATUS_NOT_INITIALIZED
156 * @remark Token memory is destroyed by the caller using CADestroyToken().
157 * @see CADestroyToken
159 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
162 * @brief Destroy the token generated by CAGenerateToken
163 * @param token [IN] token to be freed
166 void CADestroyToken(CAToken_t token);
169 * @brief Find the resource in the network. This API internally sends multicast messages on all
170 * selected connectivity adapters. Responses are delivered via response callbacks.
172 * @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
173 * path of Uri to be search.
174 * @param token [IN] Token for the request
175 * @param tokenLength [IN] length of the token
176 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_NOT_INITIALIZED
178 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength);
181 * @brief Send control Request on a resource
182 * @param object [IN] Remote Endpoint where the payload need to be sent.
183 * This Remote endpoint is delivered with Request or response callback.
184 * @param requestInfo [IN] Information for the request.
185 * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
187 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo);
190 * @brief Send control Request on a resource to multicast group
191 * @param object [IN] Group Endpoint where the payload need to be sent.
192 * This Remote endpoint is delivered with Request or response callback.
193 * @param requestInfo [IN] Information for the request.
194 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
196 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
197 const CARequestInfo_t *requestInfo);
200 * @brief Send the response
201 * @param object [IN] Remote Endpoint where the payload need to be sent.
202 * This Remote endpoint is delivered with Request or response callback
203 * @param responseInfo [IN] Information for the response
204 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
206 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
207 const CAResponseInfo_t *responseInfo);
210 * @brief Send notification to the remote object
211 * @param object [IN] Remote Endpoint where the payload need to be sent.
212 * This Remote endpoint is delivered with Request or response callback.
213 * @param responseInfo [IN] Information for the response.
214 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
216 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
217 const CAResponseInfo_t *responseInfo);
220 * @brief To advertise the resource
221 * @param resourceUri [IN] URI to be advertised
222 * @param token [IN] Token for the request
223 * @param tokenLength [IN] length of the token
224 * @param options [IN] Header options information
225 * @param numOptions [IN] Number of options
226 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or
227 * #CA_MEMORY_ALLOC_FAILED or #CA_STATUS_NOT_INITIALIZED
229 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
230 uint8_t tokenLength, const CAHeaderOption_t *options,
231 const uint8_t numOptions);
234 * @brief Select network to use
235 * @param interestedNetwork [IN] Connectivity Type enum
236 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
238 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
241 * @brief Select network to unuse
242 * @param nonInterestedNetwork [IN] Connectivity Type enum
243 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
245 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
248 * @brief Get network information
249 * It should be destroyed by the caller as it Get Information.
250 * @param info [OUT] LocalConnectivity objects
251 * @param size [OUT] No Of Array objects
252 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
253 * #CA_MEMORY_ALLOC_FAILED
255 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
258 * @brief To Handle the Request or Response
259 * @return #CA_STATUS_OK
261 CAResult_t CAHandleRequestResponse();