Added connectivity files for full code review
[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 cainterface.h
23  * @brief This file contains the APIs for Resource Model to use
24  */
25
26 #ifndef __CA_INTERFACE_H_
27 #define __CA_INTERFACE_H_
28
29 /**
30  * Connectivity Abstraction Interface APIs.
31  */
32 #include "cacommon.h"
33
34 #ifdef __WITH_DTLS__
35 #include "ocsecurityconfig.h"
36 #endif
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42
43 /**
44  * @brief   Callback function type for request delivery.
45  * @param   object      [OUT] Endpoint object from which the request is received. It contains
46  *                            endpoint address based on the connectivity type.
47  * @param   requestInfo [OUT] Info for resource model to understand about the request.
48  * @return  NONE
49  */
50 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
51                                   const CARequestInfo_t *requestInfo);
52
53 /**
54  * @brief   Callback function type for response delivery.
55  * @param   object          [OUT] Endpoint object from which the response is received.
56  * @param   responseInfo    [OUT] Identifier which needs to be mapped with response.
57  * @return  NONE
58  */
59 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
60                                    const CAResponseInfo_t *responseInfo);
61
62 #ifdef __WITH_DTLS__
63 /**
64  * @brief   Callback function type for getting DTLS credentials.
65  * @param   credInfo          [OUT] DTLS credentials info
66  * @return  NONE
67  */
68 typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
69 #endif //__WITH_DTLS__
70
71 /**
72  * @brief   Initialize the connectivity abstraction module.
73  *          It will initialize adapters, thread pool and other modules based on the platform
74  *          compilation options.
75  *
76  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
77  */
78 CAResult_t CAInitialize();
79
80 /**
81  * @brief   Terminate the connectivity abstraction module.
82  *          All threads, data structures are destroyed for next initializations.
83  * @return  NONE
84  */
85 void CATerminate();
86
87 /**
88  * @brief   Starts listening servers.
89  *          This API is used by resource hosting server for listening multicast requests.
90  *          Based on the adapters configurations, different kinds of servers are started.
91  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
92  */
93 CAResult_t CAStartListeningServer();
94
95 /**
96  * @brief   Starts discovery servers.
97  *          This API is used by resource required clients for listening multicast requests.
98  *          Based on the adapters configurations, different kinds of servers are started.
99  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
100  */
101 CAResult_t CAStartDiscoveryServer();
102
103 /**
104  * @brief   Register request callbacks and response callbacks.
105  *          Requests and responses are delivered these callbacks .
106  * @param   ReqHandler   [IN] Request callback ( for GET,PUT ..etc)
107  * @param   RespHandler  [IN] Response Handler Callback
108  * @see     CARequestCallback
109  * @see     CAResponseCallback
110  * @return  NONE
111  */
112 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
113
114 #ifdef __WITH_DTLS__
115 /**
116  * @brief   Register callback to get DTLS PSK credentials.
117  * @param   GetDTLSCredentials   [IN] GetDTLS Credetials callback
118  * @return  #CA_STATUS_OK
119  */
120 CAResult_t CARegisterDTLSCredentialsHandler(
121                                                    CAGetDTLSCredentialsHandler GetDTLSCredentials);
122 #endif //__WITH_DTLS__
123
124 /**
125  * @brief   Create a Remote endpoint if the URI is available already.
126  *          This is a Helper function which can be used before calling
127  *          CASendRequest / CASendNotification.
128  * @param   uri                 [IN]  Absolute URI of the resource to be used to generate the
129  *                                    Remote endpoint
130  *                                    \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
131  *                                    \n coap://10:11:12:13:45:45/resource_uri ( for BT)
132  * @param   connectivityType    [IN]  Connectivity type of the endpoint
133  * @param   object              [OUT] Endpoint object which contains the above parsed data
134  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
135  * @remark  The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
136  * @see     CADestroyRemoteEndpoint
137  */
138 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
139                                   const CAConnectivityType_t connectivityType,
140                                   CARemoteEndpoint_t **object);
141
142 /**
143  * @brief   Destroy the remote endpoint created
144  * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
145  * @return  NONE
146  */
147 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
148
149 /**
150  * @brief   Generating the token for matching the request and response.
151  * @param   token   [OUT] Token for the request
152  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
153  * @remark  Token memory is destroyed by the caller using CADestroyToken().
154  * @see     CADestroyToken
155  */
156 CAResult_t CAGenerateToken(CAToken_t *token);
157
158 /**
159  * @brief   Destroy the token generated by CAGenerateToken
160  * @param   token   [IN] Token for the request
161  * @return  NONE
162  */
163 void CADestroyToken(CAToken_t token);
164
165 /**
166  * @brief   Find the resource in the network. This API internally sends multicast messages on all
167  *          selected connectivity adapters. Responses are delivered via response callbacks.
168  *
169  * @param   resourceUri [IN] Uri to send multicast search request. Must contain only relative
170  *                           path of Uri to be search.
171  * @param   token       [IN] Token for the request
172  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
173  */
174 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
175
176 /**
177  * @brief   Send control Request on a resource
178  * @param   object      [IN] Remote Endpoint where the payload need to be sent.
179  *                           This Remote endpoint is delivered with Request or response callback.
180  * @param   requestInfo [IN] Information for the request.
181  * @return  #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
182  */
183 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo);
184
185 /**
186  * @brief   Send control Request on a resource to multicast group
187  * @param   object      [IN] Group Endpoint where the payload need to be sent.
188  *                           This Remote endpoint is delivered with Request or response callback.
189  * @param   requestInfo [IN] Information for the request.
190  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
191  */
192 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
193                               const CARequestInfo_t *requestInfo);
194
195 /**
196  * @brief   Send the response
197  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
198  *                               This Remote endpoint is delivered with Request or response callback
199  * @param   responseInfo    [IN] Information for the response
200  * @return  #CA_STATUS_OK or  #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
201  */
202 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
203                 const CAResponseInfo_t *responseInfo);
204
205 /**
206  * @brief   Send notification to the remote object
207  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
208  *                               This Remote endpoint is delivered with Request or response callback.
209  * @param   responseInfo    [IN] Information for the response.
210  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
211  */
212 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
213                       const  CAResponseInfo_t *responseInfo);
214
215 /**
216  * @brief   To advertise the resource
217  * @param   resourceUri       [IN] URI to be advertised
218  * @param   token               [IN] Token for the request
219  * @param   options             [IN] Header options information
220  * @param   numOptions      [IN] Number of options
221  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
222  */
223 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
224                                const CAHeaderOption_t *options,const uint8_t numOptions);
225
226 /**
227  * @brief   Select network to use
228  * @param   interestedNetwork   [IN] Connectivity Type enum
229  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
230  */
231 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
232
233 /**
234  * @brief   Select network to unuse
235  * @param   nonInterestedNetwork    [IN] Connectivity Type enum
236  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
237  */
238 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
239
240 /**
241  * @brief   Get network information
242  *          It should be destroyed by the caller as it Get Information.
243  * @param   info    [OUT] LocalConnectivity objects
244  * @param   size    [OUT] No Of Array objects
245  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
246 *                #CA_MEMORY_ALLOC_FAILED
247  */
248 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
249
250 /**
251  * @brief    To Handle the Request or Response
252  * @return   #CA_STATUS_OK
253  */
254 CAResult_t CAHandleRequestResponse();
255
256 #ifdef __cplusplus
257 } /* extern "C" */
258 #endif
259
260 #endif
261