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 CAEndpoint_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 CAEndpoint_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 CAEndpoint_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(CAGetDTLSCredentialsHandler GetDTLSCredentials);
146 #endif //__WITH_DTLS__
149 * @brief Create an endpoint description
150 * @param flags [IN] how the adapter should be used
151 * @param adapter [IN] which adapter to use
152 * @param addr [IN] string representation of address
153 * @param port [IN] port (for IP_ADAPTER)
154 * @param endpoint [OUT] Endpoint which contains the above
155 * @return #CA_STATUS_OK or #CA_STATUS_FAILED
156 * @remark The created Remote endpoint can be freed using CADestroyEndpoint().
157 * @see CADestroyEndpoint
159 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
160 CATransportAdapter_t adapter,
163 CAEndpoint_t **object);
166 * @brief Destroy the remote endpoint created
167 * @param object [IN] Remote Endpoint object created with CACreateEndpoint
170 void CADestroyEndpoint(CAEndpoint_t *object);
173 * @brief Generating the token for matching the request and response.
174 * @param token [OUT] Token for the request
175 * @param tokenLength [IN] length of the token
176 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
177 * or #CA_STATUS_NOT_INITIALIZED
178 * @remark Token memory is destroyed by the caller using CADestroyToken().
179 * @see CADestroyToken
181 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
184 * @brief Destroy the token generated by CAGenerateToken
185 * @param token [IN] token to be freed
188 void CADestroyToken(CAToken_t token);
191 * @brief Send control Request on a resource
192 * @param object [IN] Endpoint where the payload need to be sent.
193 * This endpoint is delivered with Request or response callback.
194 * @param requestInfo [IN] Information for the request.
195 * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
197 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
200 * @brief Send the response
201 * @param object [IN] Endpoint where the payload need to be sent.
202 * This 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 CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
209 * @brief Send notification to the remote object
210 * @param object [IN] Endpoint where the payload need to be sent.
211 * This endpoint is delivered with Request or response callback.
212 * @param responseInfo [IN] Information for the response.
213 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
215 CAResult_t CASendNotification(const CAEndpoint_t *object,
216 const CAResponseInfo_t *responseInfo);
219 * @brief Select network to use
220 * @param interestedNetwork [IN] Connectivity Type enum
221 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
223 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork);
226 * @brief Select network to unuse
227 * @param nonInterestedNetwork [IN] Connectivity Type enum
228 * @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
230 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork);
233 * @brief Get network information
234 * It should be destroyed by the caller as it Get Information.
235 * @param info [OUT] LocalConnectivity objects
236 * @param size [OUT] No Of Array objects
237 * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
238 * #CA_MEMORY_ALLOC_FAILED
240 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
243 * @brief To Handle the Request or Response
244 * @return #CA_STATUS_OK
246 CAResult_t CAHandleRequestResponse();
250 * @brief Set Remote Access information for XMPP Client.
251 * @param caraInfo [IN] remote access info.
253 * @return #CA_STATUS_OK
255 CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
262 * Select the cipher suite for dtls handshake
264 * @param[IN] cipher cipher suite (Note : Make sure endianness)
265 * 0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA
266 * 0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
267 * 0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
269 * @retval CA_STATUS_OK Successful
270 * @retval CA_STATUS_INVALID_PARAM Invalid input argumets
271 * @retval CA_STATUS_FAILED Operation failed
273 CAResult_t CASelectCipherSuite(const uint16_t cipher);
276 * Enable TLS_ECDH_anon_WITH_AES_128_CBC_SHA cipher suite in dtls
278 * @param[IN] enable TRUE/FALSE enables/disables anonymous cipher suite
280 * @retval CA_STATUS_OK Successful
281 * @retval CA_STATUS_FAILED Operation failed
283 * @note anonymous cipher suite should only be enabled for 'JustWorks' provisioning.
285 CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
289 * Generate ownerPSK using PRF
290 * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
291 * 'ID of new device(Resource Server)',
292 * 'ID of owner smart-phone(Provisioning Server)')
294 * @param[IN] endpoint information of network address
295 * @param[IN] label Ownership transfer method e.g)"oic.sec.doxm.jw"
296 * @param[IN] labelLen Byte length of label
297 * @param[IN] rsrcServerDeviceID ID of new device(Resource Server)
298 * @param[IN] rsrcServerDeviceIDLen Byte length of rsrcServerDeviceID
299 * @param[IN] provServerDeviceID label of previous owner
300 * @param[IN] provServerDeviceIDLen byte length of provServerDeviceID
301 * @param[IN,OUT] ownerPSK Output buffer for owner PSK
302 * @param[IN] ownerPSKSize Byte length of the ownerPSK to be generated
304 * @retval CA_STATUS_OK Successful
305 * @retval CA_STATUS_FAILED Operation failed
307 CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t *endpoint,
308 const uint8_t* label, const size_t labelLen,
309 const uint8_t* rsrcServerDeviceID,
310 const size_t rsrcServerDeviceIDLen,
311 const uint8_t* provServerDeviceID,
312 const size_t provServerDeviceIDLen,
313 uint8_t* ownerPSK, const size_t ownerPSKSize);
316 * Initiate DTLS handshake with selected cipher suite
318 * @param[IN] endpoint information of network address
320 * @retval CA_STATUS_OK Successful
321 * @retval CA_STATUS_FAILED Operation failed
323 CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint);
326 * Close the DTLS session
328 * @param[IN] endpoint information of network address
330 * @retval CA_STATUS_OK Successful
331 * @retval CA_STATUS_FAILED Operation failed
333 CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint);
335 #endif /* __WITH_DTLS__ */
341 #endif /* CA_INTERFACE_H_ */