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 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
154 * @remark Token memory is destroyed by the caller using CADestroyToken().
155 * @see CADestroyToken
157 CAResult_t CAGenerateToken(CAToken_t *token);
160 * @brief Destroy the token generated by CAGenerateToken
161 * @param token [IN] Token for the request
164 void CADestroyToken(CAToken_t token);
167 * @brief Find the resource in the network. This API internally sends multicast messages on all
168 * selected connectivity adapters. Responses are delivered via response callbacks.
170 * @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
171 * path of Uri to be search.
172 * @param token [IN] Token for the request
173 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
175 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
178 * @brief Send control Request on a resource
179 * @param object [IN] Remote Endpoint where the payload need to be sent.
180 * This Remote endpoint is delivered with Request or response callback.
181 * @param requestInfo [IN] Information for the request.
182 * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
184 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo);
187 * @brief Send control Request on a resource to multicast group
188 * @param object [IN] Group Endpoint where the payload need to be sent.
189 * This Remote endpoint is delivered with Request or response callback.
190 * @param requestInfo [IN] Information for the request.
191 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
193 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
194 const CARequestInfo_t *requestInfo);
197 * @brief Send the response
198 * @param object [IN] Remote Endpoint where the payload need to be sent.
199 * This Remote endpoint is delivered with Request or response callback
200 * @param responseInfo [IN] Information for the response
201 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
203 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
204 const CAResponseInfo_t *responseInfo);
207 * @brief Send notification to the remote object
208 * @param object [IN] Remote Endpoint where the payload need to be sent.
209 * This Remote endpoint is delivered with Request or response callback.
210 * @param responseInfo [IN] Information for the response.
211 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
213 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
214 const CAResponseInfo_t *responseInfo);
217 * @brief To advertise the resource
218 * @param resourceUri [IN] URI to be advertised
219 * @param token [IN] Token for the request
220 * @param options [IN] Header options information
221 * @param numOptions [IN] Number of options
222 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
224 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
225 const CAHeaderOption_t *options,const uint8_t numOptions);
228 * @brief Select network to use
229 * @param interestedNetwork [IN] Connectivity Type enum
230 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
232 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
235 * @brief Select network to unuse
236 * @param nonInterestedNetwork [IN] Connectivity Type enum
237 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
239 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
242 * @brief Get network information
243 * It should be destroyed by the caller as it Get Information.
244 * @param info [OUT] LocalConnectivity objects
245 * @param size [OUT] No Of Array objects
246 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
247 * #CA_MEMORY_ALLOC_FAILED
249 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
252 * @brief To Handle the Request or Response
253 * @return #CA_STATUS_OK
255 CAResult_t CAHandleRequestResponse();