Merge "Fix compiler warnings" into connectivity-abstraction
[platform/upstream/iotivity.git] / resource / csdk / connectivity / api / cacommon.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 cacommon.h
23  * @brief This file contains the common data structures between Resource , CA and adapters
24  */
25
26 #ifndef __CA_COMMON_H_
27 #define __CA_COMMON_H_
28
29 #include <stdint.h>
30 #include <stdlib.h>
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  @brief IP address Length
39  */
40 #define CA_IPADDR_SIZE 16
41
42 /**
43  @brief Mac address length for BT port
44  */
45 #define CA_MACADDR_SIZE 18
46
47 /**
48  @brief Max header options data length
49  */
50 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
51
52 /**
53  @brief Max URI length
54  */
55 #define CA_MAX_URI_LENGTH 128
56
57 /**
58 @brief option types - the highest option number 63
59 */
60 #define CA_OPTION_IF_MATCH 1
61 #define CA_OPTION_ETAG 4
62 #define CA_OPTION_IF_NONE_MATCH 5
63 #define CA_OPTION_LOCATION_PATH 8
64 #define CA_OPTION_URI_PATH 11
65 #define CA_OPTION_CONTENT_FORMAT 12
66 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
67 #define CA_OPTION_MAXAGE 14
68 #define CA_OPTION_URI_QUERY 15
69 #define CA_OPTION_ACCEPT 17
70 #define CA_OPTION_LOCATION_QUERY 20
71 #define CA_OPTION_OBSERVE 6
72
73 /**
74  @brief Max length of ID
75  */
76 #define DTLS_PSK_ID_LEN 16
77
78 /**
79  @brief Max length of PSK
80  */
81 #define DTLS_PSK_PSK_LEN 16
82
83 /**
84  @brief version
85  */
86 #define DtlsPskCredsBlobVer_1 1
87
88 /**
89  @brief current version
90  */
91 #define DtlsPskCredsBlobVer_CurrentVersion DtlsPskCredsBlobVer_1
92
93
94 /**
95  @brief Payload information from resource model
96  */
97 typedef char *CAPayload_t;
98
99 /**
100  @brief URI for the OIC base.CA considers relative URI as the URI.
101  */
102 typedef char *CAURI_t;
103
104 /**
105  @brief Token information for mapping the request and responses by resource model
106  */
107 typedef char *CAToken_t;
108
109 /**
110  @brief Boolean value used for specifying the success or failure
111  */
112
113 typedef enum
114 {
115     CA_FALSE = 0,
116     CA_TRUE
117 } CABool_t;
118
119 /**
120  @brief Different connectivities that are handled in Connectivity Abstraction
121  */
122 typedef enum
123 {
124     CA_ETHERNET = (1 << 0),
125     CA_WIFI = (1 << 1),
126     CA_EDR = (1 << 2),
127     CA_LE = (1 << 3)
128 } CAConnectivityType_t;
129
130 /**
131  @brief Information about the network status.CA_INTERFACE_UP means connectivity is available
132  */
133 typedef enum
134 {
135     CA_INTERFACE_UP,
136     CA_INTERFACE_DOWN
137 } CANetworkStatus_t;
138
139 /**
140  @brief  Address of the local or remote endpoint
141  */
142 typedef union
143 {
144     /**
145      @brief BT Mac Information
146      */
147     struct
148     {
149         /** @brief BT mac address **/
150         char btMacAddress[CA_MACADDR_SIZE];
151     } BT;
152
153     /**
154      @brief LE MAC Information
155      */
156     struct
157     {
158         /** @brief BLE mac address **/
159         char leMacAddress[CA_MACADDR_SIZE];
160     } LE;
161
162     /**
163      @brief IP Information for wifi and ethernet ports
164      */
165     struct
166     {
167         /** Ip address of the interface**/
168         char ipAddress[CA_IPADDR_SIZE];
169         /** port information**/
170         uint32_t port;
171     } IP;
172 } CAAddress_t;
173
174 /**
175  @brief Message Type for Base source code
176  */
177 typedef enum
178 {
179     CA_MSG_CONFIRM = 0,  /* confirmable message (requires ACK/RST) */
180     CA_MSG_NONCONFIRM,   /* non-confirmable message (one-shot message) */
181     CA_MSG_ACKNOWLEDGE,  /* used to acknowledge confirmable messages */
182     CA_MSG_RESET         /* indicates error in received messages */
183 } CAMessageType_t;
184
185 /**
186  @brief Allowed method to be used by resource model
187  */
188 typedef enum
189 {
190     CA_GET = 1,
191     CA_POST,
192     CA_PUT,
193     CA_DELETE
194 } CAMethod_t;
195
196 /**
197  @brief Remote endpoint information for connectivities
198  */
199 typedef struct
200 {
201     /** Resource URI information **/
202     CAURI_t resourceUri;
203     /** Remote Endpoint address **/
204     CAAddress_t addressInfo;
205     /** Connectivity of the endpoint**/
206     CAConnectivityType_t connectivityType;
207     /** Secure connection**/
208     CABool_t isSecured;
209 } CARemoteEndpoint_t;
210
211
212 /**
213  @brief Group endpoint information for connectivities
214  */
215 typedef struct
216 {
217     /** Resource URI information **/
218     CAURI_t resourceUri;
219     /** Connectivity of the endpoint**/
220     CAConnectivityType_t connectivityType;
221 } CAGroupEndpoint_t;
222
223 /**
224  @brief Local Connectivity information
225  */
226 typedef struct
227 {
228     /** address of the interface  **/
229     CAAddress_t addressInfo;
230     /** Connectivity type that localconnectivity avaialble **/
231     CAConnectivityType_t type;
232     /** Secure connection**/
233     CABool_t isSecured;
234 } CALocalConnectivity_t;
235
236 /**
237  @brief Enums for CA return values
238  */
239 typedef enum
240 {
241     /* Success status code - START HERE */
242     CA_STATUS_OK = 0,
243     CA_STATUS_INVALID_PARAM,
244     CA_ADAPTER_NOT_ENABLED,
245     CA_SERVER_STARTED_ALREADY,
246     CA_SERVER_NOT_STARTED,
247     CA_DESTINATION_NOT_REACHABLE,
248     CA_SOCKET_OPERATION_FAILED,
249     CA_SEND_FAILED,
250     CA_RECEVIE_FAILED,
251     CA_MEMORY_ALLOC_FAILED,
252     CA_REQUEST_TIMEOUT,
253     CA_DESTINATION_DISCONNECTED,
254     CA_STATUS_FAILED,
255     CA_NOT_SUPPORTED
256     /* Result code - END HERE */
257 } CAResult_t;
258
259 /**
260  @brief Enums for CA Response  values
261  */
262 typedef enum
263 {
264     /* Success status code - START HERE */
265     CA_SUCCESS = 200,
266     CA_CREATED = 201,
267     CA_DELETED = 202,
268     CA_BAD_REQ = 400,
269     CA_BAD_OPT = 402,
270     CA_NOT_FOUND = 404
271                    /* Response status code - END HERE */
272 } CAResponseResult_t;
273
274 /**
275  @brief Transport Protocol IDs for additional options
276  */
277 typedef enum
278 {
279     CA_INVALID_ID = (1 << 0),
280     CA_COAP_ID = (1 << 1)
281 } CATransportProtocolID_t;
282
283 /**
284  * @brief Header options structure to be filled
285  *
286  * This structure is used to hold header information.
287  */
288 typedef struct
289 {
290     /** The protocol ID this option applies to**/
291     CATransportProtocolID_t protocolID;
292     /** The header option ID which will be added to communication packets**/
293     uint16_t optionID;
294     /** its length   **/
295     uint16_t optionLength;
296     /** optional data values**/
297     uint8_t optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];
298 } CAHeaderOption_t;
299
300 /**
301  * @brief Base Information received
302  *
303  * This structure is used to hold request & response base information
304  */
305 typedef struct
306 {
307     /**Qos for the request **/
308     CAMessageType_t type;
309     /** Message id.
310      * if message id is zero, it will generated by CA inside.
311      * otherwise, you can use it.**/
312     uint16_t messageId;
313     /** Token for CA**/
314     CAToken_t token;
315     /** Header Options for the request **/
316     CAHeaderOption_t *options;
317     /** Number of Header options**/
318     uint8_t numOptions;
319     /** payload of the request **/
320     CAPayload_t payload;
321 } CAInfo_t;
322
323 /**
324  * @brief Request Information to be sent
325  *
326  * This structure is used to hold request information
327  */
328 typedef struct
329 {
330     /** Name of the Method Allowed **/
331     CAMethod_t method;
332     /** Information of the request. **/
333     CAInfo_t info;
334 } CARequestInfo_t;
335
336 /**
337  * @brief Response information received
338  *
339  * This structure is used to hold response information
340  */
341 typedef struct
342 {
343     /**Result for response by resource model**/
344     CAResponseResult_t result;
345     /**Information of the response.**/
346     CAInfo_t info;
347 } CAResponseInfo_t;
348
349 /**
350  * Credentials for a device. Includes identity and the associated PSK.
351  */
352 typedef struct
353 {
354    unsigned char clientIdentity[DTLS_PSK_ID_LEN];
355    unsigned char rsClientPsk[DTLS_PSK_PSK_LEN];
356 } CADtlsPskCreds_t;
357
358 /**
359  * Binary blob containing device identity and the credentials for all devices
360  * trusted by this device.
361  */
362 typedef struct
363 {
364    uint16_t blobVer;                        /**< version of the blob */
365    uint16_t reserved;                       /**< reserved for future use */
366    unsigned char rsIdentity[DTLS_PSK_ID_LEN]; /**< identity of self */
367    uint32_t num;                            /**< number of credentials in this blob */
368    CADtlsPskCreds_t *creds;                 /**< list of credentials. Size of this
369                                                  array is determined by 'num' variable. */
370 } CADtlsPskCredsBlob_t;
371
372 #ifdef __cplusplus
373 } /* extern "C" */
374 #endif
375
376 #endif //#ifndef __CA_COMMON_H_