Removing Single/Double underscores at beginning of the preprocessor directives
[platform/upstream/iotivity.git] / resource / csdk / connectivity / api / cainterface.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  *
24  * This file contains the APIs for Resource Model to use.
25  */
26
27 #ifndef CA_INTERFACE_H_
28 #define CA_INTERFACE_H_
29
30 /**
31  * Connectivity Abstraction Interface APIs.
32  */
33 #include "cacommon.h"
34
35 #ifdef __WITH_DTLS__
36 #include "ocsecurityconfig.h"
37 #endif
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43
44 /**
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.
49  * @return  NONE
50  */
51 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
52                                   const CARequestInfo_t *requestInfo);
53
54 /**
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.
58  * @return  NONE
59  */
60 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
61                                    const CAResponseInfo_t *responseInfo);
62
63 #ifdef __WITH_DTLS__
64
65 /**
66  * Binary blob containing device identity and the credentials for all devices
67  * trusted by this device.
68  */
69 typedef struct
70 {
71    unsigned char identity[DTLS_PSK_ID_LEN]; /** identity of self */
72    uint32_t num;                            /** number of credentials in this blob */
73    OCDtlsPskCreds *creds;                   /** list of credentials. Size of this
74                                                 array is determined by 'num' variable. */
75 } CADtlsPskCredsBlob_t;
76
77 /**
78  * @brief   Callback function type for getting DTLS credentials.
79  * @param   credInfo          [OUT] DTLS credentials info. Handler has to allocate new memory for
80  *                                  both credInfo and credInfo->creds which is then freed by CA
81  * @return  NONE
82  */
83 typedef void (*CAGetDTLSCredentialsHandler)(CADtlsPskCredsBlob_t **credInfo);
84 #endif //__WITH_DTLS__
85
86 /**
87  * @brief   Initialize the connectivity abstraction module.
88  *          It will initialize adapters, thread pool and other modules based on the platform
89  *          compilation options.
90  *
91  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
92  */
93 CAResult_t CAInitialize();
94
95 /**
96  * @brief   Terminate the connectivity abstraction module.
97  *          All threads, data structures are destroyed for next initializations.
98  * @return  NONE
99  */
100 void CATerminate();
101
102 /**
103  * @brief   Starts listening servers.
104  *          This API is used by resource hosting server for listening multicast requests.
105  *          Based on the adapters configurations, different kinds of servers are started.
106  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
107  */
108 CAResult_t CAStartListeningServer();
109
110 /**
111  * @brief   Starts discovery servers.
112  *          This API is used by resource required clients 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
115  */
116 CAResult_t CAStartDiscoveryServer();
117
118 /**
119  * @brief   Register request callbacks and response callbacks.
120  *          Requests and responses are delivered these callbacks .
121  * @param   ReqHandler   [IN] Request callback ( for GET,PUT ..etc)
122  * @param   RespHandler  [IN] Response Handler Callback
123  * @see     CARequestCallback
124  * @see     CAResponseCallback
125  * @return  NONE
126  */
127 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
128
129 #ifdef __WITH_DTLS__
130 /**
131  * @brief   Register callback to get DTLS PSK credentials.
132  * @param   GetDTLSCredentials   [IN] GetDTLS Credetials callback
133  * @return  #CA_STATUS_OK
134  */
135 CAResult_t CARegisterDTLSCredentialsHandler(
136                                                    CAGetDTLSCredentialsHandler GetDTLSCredentials);
137 #endif //__WITH_DTLS__
138
139 /**
140  * @brief   Create a Remote endpoint if the URI is available already.
141  *          This is a Helper function which can be used before calling
142  *          CASendRequest / CASendNotification.
143  * @param   uri                 [IN]  Absolute URI of the resource to be used to generate the
144  *                                    Remote endpoint
145  *                                    \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
146  *                                    \n coap://10:11:12:13:45:45/resource_uri ( for BT)
147  * @param   transportType    [IN]  Transport type of the endpoint
148  * @param   object              [OUT] Endpoint object which contains the above parsed data
149  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
150  * @remark  The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
151  * @see     CADestroyRemoteEndpoint
152  */
153 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
154                                   const CATransportType_t transportType,
155                                   CARemoteEndpoint_t **object);
156
157 /**
158  * @brief   Destroy the remote endpoint created
159  * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
160  * @return  NONE
161  */
162 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
163
164 /**
165  * @brief   Generating the token for matching the request and response.
166  * @param   token          [OUT] Token for the request
167  * @param   tokenLength    [IN]  length of the token
168  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
169  *          or #CA_STATUS_NOT_INITIALIZED
170  * @remark  Token memory is destroyed by the caller using CADestroyToken().
171  * @see     CADestroyToken
172  */
173 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
174
175 /**
176  * @brief   Destroy the token generated by CAGenerateToken
177  * @param   token   [IN] token to be freed
178  * @return  NONE
179  */
180 void CADestroyToken(CAToken_t token);
181
182 /**
183  * @brief   Find the resource in the network. This API internally sends multicast messages on all
184  *          selected connectivity adapters. Responses are delivered via response callbacks.
185  *
186  * @param   resourceUri [IN] Uri to send multicast search request. Must contain only relative
187  *                           path of Uri to be search.
188  * @param   token       [IN] Token for the request
189  * @param   tokenLength [IN]  length of the token
190  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_NOT_INITIALIZED
191  */
192 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength);
193
194 /**
195  * @brief   Send control Request on a resource
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   requestInfo [IN] Information for the request.
199  * @return  #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
200  */
201 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo);
202
203 /**
204  * @brief   Send control Request on a resource to multicast group
205  * @param   object      [IN] Group Endpoint where the payload need to be sent.
206  *                           This Remote endpoint is delivered with Request or response callback.
207  * @param   requestInfo [IN] Information for the request.
208  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
209  */
210 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
211                               const CARequestInfo_t *requestInfo);
212
213 /**
214  * @brief   Send the response
215  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
216  *                               This Remote endpoint is delivered with Request or response callback
217  * @param   responseInfo    [IN] Information for the response
218  * @return  #CA_STATUS_OK or  #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
219  */
220 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
221                 const CAResponseInfo_t *responseInfo);
222
223 /**
224  * @brief   Send notification to the remote object
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
229  */
230 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
231                       const  CAResponseInfo_t *responseInfo);
232
233 /**
234  * @brief   To advertise the resource
235  * @param   resourceUri [IN] URI to be advertised
236  * @param   token       [IN] Token for the request
237  * @param   tokenLength [IN] length of the token
238  * @param   options     [IN] Header options information
239  * @param   numOptions  [IN] Number of options
240  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or
241  *          #CA_MEMORY_ALLOC_FAILED or #CA_STATUS_NOT_INITIALIZED
242  */
243 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
244                                uint8_t tokenLength, const CAHeaderOption_t *options,
245                                const uint8_t numOptions);
246
247 /**
248  * @brief   Select network to use
249  * @param   interestedNetwork   [IN] Connectivity Type enum
250  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
251  */
252 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
253
254 /**
255  * @brief   Select network to unuse
256  * @param   nonInterestedNetwork    [IN] Connectivity Type enum
257  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
258  */
259 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
260
261 /**
262  * @brief   Get network information
263  *          It should be destroyed by the caller as it Get Information.
264  * @param   info    [OUT] LocalConnectivity objects
265  * @param   size    [OUT] No Of Array objects
266  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
267 *                #CA_MEMORY_ALLOC_FAILED
268  */
269 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
270
271 /**
272  * @brief    To Handle the Request or Response
273  * @return   #CA_STATUS_OK
274  */
275 CAResult_t CAHandleRequestResponse();
276
277 #ifdef __cplusplus
278 } /* extern "C" */
279 #endif
280
281 #endif /* CA_INTERFACE_H_ */
282