Removed Token ASCII-char limit and length limit
[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  * @param   tokenLength    [IN]  length of the token
154  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
155  *          or #CA_STATUS_NOT_INITIALIZED
156  * @remark  Token memory is destroyed by the caller using CADestroyToken().
157  * @see     CADestroyToken
158  */
159 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
160
161 /**
162  * @brief   Destroy the token generated by CAGenerateToken
163  * @param   token   [IN] token to be freed
164  * @return  NONE
165  */
166 void CADestroyToken(CAToken_t token);
167
168 /**
169  * @brief   Find the resource in the network. This API internally sends multicast messages on all
170  *          selected connectivity adapters. Responses are delivered via response callbacks.
171  *
172  * @param   resourceUri [IN] Uri to send multicast search request. Must contain only relative
173  *                           path of Uri to be search.
174  * @param   token       [IN] Token for the request
175  * @param   tokenLength [IN]  length of the token
176  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_NOT_INITIALIZED
177  */
178 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token, uint8_t tokenLength);
179
180 /**
181  * @brief   Send control Request on a resource
182  * @param   object      [IN] Remote Endpoint where the payload need to be sent.
183  *                           This Remote endpoint is delivered with Request or response callback.
184  * @param   requestInfo [IN] Information for the request.
185  * @return  #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
186  */
187 CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo);
188
189 /**
190  * @brief   Send control Request on a resource to multicast group
191  * @param   object      [IN] Group Endpoint where the payload need to be sent.
192  *                           This Remote endpoint is delivered with Request or response callback.
193  * @param   requestInfo [IN] Information for the request.
194  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
195  */
196 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
197                               const CARequestInfo_t *requestInfo);
198
199 /**
200  * @brief   Send the response
201  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
202  *                               This Remote 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
205  */
206 CAResult_t CASendResponse(const CARemoteEndpoint_t *object,
207                 const CAResponseInfo_t *responseInfo);
208
209 /**
210  * @brief   Send notification to the remote object
211  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
212  *                               This Remote endpoint is delivered with Request or response callback.
213  * @param   responseInfo    [IN] Information for the response.
214  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
215  */
216 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
217                       const  CAResponseInfo_t *responseInfo);
218
219 /**
220  * @brief   To advertise the resource
221  * @param   resourceUri [IN] URI to be advertised
222  * @param   token       [IN] Token for the request
223  * @param   tokenLength [IN] length of the token
224  * @param   options     [IN] Header options information
225  * @param   numOptions  [IN] Number of options
226  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or
227  *          #CA_MEMORY_ALLOC_FAILED or #CA_STATUS_NOT_INITIALIZED
228  */
229 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token,
230                                uint8_t tokenLength, const CAHeaderOption_t *options,
231                                const uint8_t numOptions);
232
233 /**
234  * @brief   Select network to use
235  * @param   interestedNetwork   [IN] Connectivity Type enum
236  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
237  */
238 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
239
240 /**
241  * @brief   Select network to unuse
242  * @param   nonInterestedNetwork    [IN] Connectivity Type enum
243  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
244  */
245 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
246
247 /**
248  * @brief   Get network information
249  *          It should be destroyed by the caller as it Get Information.
250  * @param   info    [OUT] LocalConnectivity objects
251  * @param   size    [OUT] No Of Array objects
252  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or
253 *                #CA_MEMORY_ALLOC_FAILED
254  */
255 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
256
257 /**
258  * @brief    To Handle the Request or Response
259  * @return   #CA_STATUS_OK
260  */
261 CAResult_t CAHandleRequestResponse();
262
263 #ifdef __cplusplus
264 } /* extern "C" */
265 #endif
266
267 #endif
268