Corrected @file tags and restored 'Files' section.
[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  * @brief   Callback function type for getting DTLS credentials.
66  * @param   credInfo          [OUT] DTLS credentials info
67  * @return  NONE
68  */
69 typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
70 #endif //__WITH_DTLS__
71
72 /**
73  * @brief   Initialize the connectivity abstraction module.
74  *          It will initialize adapters, thread pool and other modules based on the platform
75  *          compilation options.
76  *
77  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
78  */
79 CAResult_t CAInitialize();
80
81 /**
82  * @brief   Terminate the connectivity abstraction module.
83  *          All threads, data structures are destroyed for next initializations.
84  * @return  NONE
85  */
86 void CATerminate();
87
88 /**
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
93  */
94 CAResult_t CAStartListeningServer();
95
96 /**
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
101  */
102 CAResult_t CAStartDiscoveryServer();
103
104 /**
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
111  * @return  NONE
112  */
113 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
114
115 #ifdef __WITH_DTLS__
116 /**
117  * @brief   Register callback to get DTLS PSK credentials.
118  * @param   GetDTLSCredentials   [IN] GetDTLS Credetials callback
119  * @return  #CA_STATUS_OK
120  */
121 CAResult_t CARegisterDTLSCredentialsHandler(
122                                                    CAGetDTLSCredentialsHandler GetDTLSCredentials);
123 #endif //__WITH_DTLS__
124
125 /**
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
130  *                                    Remote endpoint
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
138  */
139 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
140                                   const CAConnectivityType_t connectivityType,
141                                   CARemoteEndpoint_t **object);
142
143 /**
144  * @brief   Destroy the remote endpoint created
145  * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
146  * @return  NONE
147  */
148 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
149
150 /**
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
156  */
157 CAResult_t CAGenerateToken(CAToken_t *token);
158
159 /**
160  * @brief   Destroy the token generated by CAGenerateToken
161  * @param   token   [IN] Token for the request
162  * @return  NONE
163  */
164 void CADestroyToken(CAToken_t token);
165
166 /**
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.
169  *
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
174  */
175 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
176
177 /**
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
183  */
184 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo);
185
186 /**
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
192  */
193 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
194                               const CARequestInfo_t *requestInfo);
195
196 /**
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
202  */
203 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
204                 const CAResponseInfo_t *responseInfo);
205
206 /**
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
212  */
213 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
214                       const  CAResponseInfo_t *responseInfo);
215
216 /**
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
223  */
224 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
225                                const CAHeaderOption_t *options,const uint8_t numOptions);
226
227 /**
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
231  */
232 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
233
234 /**
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
238  */
239 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
240
241 /**
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
248  */
249 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
250
251 /**
252  * @brief    To Handle the Request or Response
253  * @return   #CA_STATUS_OK
254  */
255 CAResult_t CAHandleRequestResponse();
256
257 #ifdef __cplusplus
258 } /* extern "C" */
259 #endif
260
261 #endif
262