Add wrong PIN defence codes in case of PIN based OxM
[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 #include "casecurityinterface.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 #ifdef RA_ADAPTER
42
43 /**
44  * Callback for bound JID
45  * @param[out]   jid           Boud Jabber Identifier.
46  */
47 typedef void (*CAJidBoundCallback)(char *jid);
48
49 /**
50  * CA Remote Access information for XMPP Client
51  *
52  */
53 typedef struct
54 {
55     char *hostName;     /**< XMPP server hostname */
56     uint16_t port;      /**< XMPP server serivce port */
57     char *xmppDomain;  /**< XMPP login domain */
58     char *userName;     /**< login username */
59     char *password;     /**< login password */
60     char *resource;     /**< specific resource for login */
61     char *userJid;     /**< specific JID for login */
62     CAJidBoundCallback jidBoundCallback;  /**< callback when JID bound */
63 } CARAInfo_t;
64
65 #endif //RA_ADAPTER
66
67 /**
68  * Initialize the connectivity abstraction module.
69  * It will initialize adapters, thread pool and other modules based on the platform
70  * compilation options.
71  *
72  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
73  */
74 CAResult_t CAInitialize();
75
76 /**
77  * Terminate the connectivity abstraction module.
78  * All threads, data structures are destroyed for next initializations.
79  */
80 void CATerminate();
81
82 /**
83  * Starts listening servers.
84  * This API is used by resource hosting server for listening multicast requests.
85  * Based on the adapters configurations, different kinds of servers are started.
86  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
87  */
88 CAResult_t CAStartListeningServer();
89
90 /**
91  * Stops the server from receiving the multicast traffic. This is used by sleeping
92  * device to not receives the multicast traffic.
93  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
94  */
95 CAResult_t CAStopListeningServer();
96
97 /**
98  * Starts discovery servers.
99  * This API is used by resource required clients for listening multicast requests.
100  * Based on the adapters configurations, different kinds of servers are started.
101  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
102  */
103 CAResult_t CAStartDiscoveryServer();
104
105 /**
106  * Register request callbacks and response callbacks.
107  *          Requests and responses are delivered these callbacks.
108  * @param[in]   ReqHandler    Request callback ( for GET,PUT ..etc).
109  * @param[in]   RespHandler   Response Handler Callback.
110  * @see     CARequestCallback
111  * @see     CAResponseCallback
112  * @see     CAErrorCallback
113  */
114 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
115                        CAErrorCallback ErrorHandler);
116
117 /**
118  * Create an endpoint description.
119  * @param[in]   flags                 how the adapter should be used.
120  * @param[in]   adapter               which adapter to use.
121  * @param[in]   addr                  string representation of address.
122  * @param[in]   port                  port (for IP_ADAPTER).
123  * @param[in]   endpoint              Endpoint which contains the above.
124  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
125  * @remark  The created Remote endpoint can be freed using CADestroyEndpoint().
126  * @see     CADestroyEndpoint
127  */
128 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
129                             CATransportAdapter_t adapter,
130                             const char *addr,
131                             uint16_t port,
132                             CAEndpoint_t **object);
133
134 /**
135  * Destroy the remote endpoint created.
136  * @param[in]   object   Remote Endpoint object created with CACreateEndpoint.
137  */
138 void CADestroyEndpoint(CAEndpoint_t *object);
139
140 /**
141  * Generating the token for matching the request and response.
142  * @param[in]   token            Token for the request.
143  * @param[in]   tokenLength      length of the token.
144  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or
145  *          ::CA_MEMORY_ALLOC_FAILED or ::CA_STATUS_NOT_INITIALIZED
146  * @remark  Token memory is destroyed by the caller using CADestroyToken().
147  * @see     CADestroyToken
148  */
149 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
150
151 /**
152  * Destroy the token generated by CAGenerateToken.
153  * @param[in]   token    token to be freed.
154  */
155 void CADestroyToken(CAToken_t token);
156
157 /**
158  * Send control Request on a resource.
159  * @param[in]   object       Endpoint where the payload need to be sent.
160  *                           This endpoint is delivered with Request or response callback.
161  * @param[in]   requestInfo  Information for the request.
162  * @return  ::CA_STATUS_OK ::CA_STATUS_FAILED ::CA_MEMORY_ALLOC_FAILED
163  */
164 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
165
166 /**
167  * Send the response.
168  * @param[in]   object           Endpoint where the payload need to be sent.
169  *                               This endpoint is delivered with Request or response callback.
170  * @param[in]   responseInfo     Information for the response.
171  * @return  ::CA_STATUS_OK or  ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
172  */
173 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
174
175 /**
176  * Select network to use.
177  * @param[in]   interestedNetwork    Connectivity Type enum.
178  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or
179  *          ::CA_STATUS_FAILED or ::CA_NOT_SUPPORTED
180  */
181 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork);
182
183 /**
184  * Select network to unuse.
185  * @param[in]   nonInterestedNetwork     Connectivity Type enum.
186  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or ::CA_STATUS_FAILED
187  */
188 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork);
189
190 /**
191  * Get network information.
192  * It should be destroyed by the caller as it Get Information.
193  * @param[out]   info     LocalConnectivity objects
194  * @param[out]   size     No Of Array objects
195  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or
196  *          ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
197  */
198 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
199
200 /**
201  * To Handle the Request or Response.
202  * @return   ::CA_STATUS_OK
203  */
204 CAResult_t CAHandleRequestResponse();
205
206 #ifdef RA_ADAPTER
207 /**
208  * Set Remote Access information for XMPP Client.
209  * @param[in]   caraInfo          remote access info.
210  *
211  * @return  ::CA_STATUS_OK
212  */
213 CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
214 #endif
215
216
217
218 #ifdef __cplusplus
219 } /* extern "C" */
220 #endif
221
222 #endif /* CA_INTERFACE_H_ */
223