replace : iotivity -> iotivity-sec
[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  * 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 "iotivity_config.h"
30
31 #ifndef WITH_ARDUINO
32 #ifdef TCP_ADAPTER
33 #define HAVE_SYS_POLL_H
34 #endif
35 #endif
36
37 #include <stdint.h>
38 #include <stdlib.h>
39 #include <stdbool.h>
40
41 #ifdef __TIZENRT__
42 #include <poll.h>
43 #else
44 #ifdef HAVE_SYS_POLL_H
45 #include <sys/poll.h>
46 #endif
47 #endif
48
49 #ifdef HAVE_WINSOCK2_H
50 #include <winsock2.h>
51 #include <mswsock.h>
52 #endif
53
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58
59 /**
60  * TAG of Analyzer log.
61  */
62 #define ANALYZER_TAG       "OIC_CA_ANALYZER_071801"
63 #define BLE_CLIENT_TAG     "OIC_CA_LE_CLIENT_0718"
64 #define BLE_SERVER_MCD_TAG "OIC_CA_LE_SER_MC_0718"
65 #define IP_SERVER_TAG      "OIC_CA_IP_SERVER_0718"
66 #define TCP_SERVER_TAG     "OIC_CA_TCP_SERVER_0718"
67
68 /**
69  * IP address Length.
70  */
71 #define CA_IPADDR_SIZE 16
72
73 /**
74  * Remote Access jabber ID length.
75  */
76 #define CA_RAJABBERID_SIZE 256
77
78 /**
79  * Mac address length for BT port.
80  */
81 #define CA_MACADDR_SIZE 18
82
83 /**
84  * Max header options data length.
85  */
86 #if defined(ARDUINO) || defined(__TIZENRT__)
87 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 20
88 #else
89 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 1024
90 #endif
91
92 /**
93 * Max token length.
94 */
95 #define CA_MAX_TOKEN_LEN (8)
96
97 /**
98  * Max URI length.
99  */
100 #ifdef ARDUINO
101 #define CA_MAX_URI_LENGTH 128  /* maximum size of URI for embedded platforms*/
102 #else
103 #define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/
104 #endif
105
106 /**
107  * Max PDU length supported.
108  */
109 #ifdef ARDUINO
110 #define COAP_MAX_PDU_SIZE           320  /* maximum size of a CoAP PDU for embedded platforms*/
111 #else
112 #define COAP_MAX_PDU_SIZE           1400 /* maximum size of a CoAP PDU for big platforms*/
113 #endif
114
115 #ifdef WITH_BWT
116 #define CA_DEFAULT_BLOCK_SIZE       CA_BLOCK_SIZE_1024_BYTE
117 #endif
118
119 /**
120  *Maximum length of the remoteEndpoint identity.
121  */
122 #define CA_MAX_ENDPOINT_IDENTITY_LEN  CA_MAX_IDENTITY_SIZE
123
124 /**
125  * Max identity size.
126  */
127 #define CA_MAX_IDENTITY_SIZE (37)
128
129 /**
130  * option types - the highest option number 63.
131  */
132 #define CA_OPTION_IF_MATCH 1
133 #define CA_OPTION_ETAG 4
134 #define CA_OPTION_IF_NONE_MATCH 5
135 #define CA_OPTION_OBSERVE 6
136 #define CA_OPTION_LOCATION_PATH 8
137 #define CA_OPTION_URI_PATH 11
138 #define CA_OPTION_CONTENT_FORMAT 12
139 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
140 #define CA_OPTION_MAXAGE 14
141 #define CA_OPTION_URI_QUERY 15
142 #define CA_OPTION_ACCEPT 17
143 #define CA_OPTION_LOCATION_QUERY 20
144
145 /**
146  * Payload information from resource model.
147  */
148 typedef uint8_t *CAPayload_t;
149
150 /**
151  * URI for the OIC base.CA considers relative URI as the URI.
152  */
153 typedef char *CAURI_t;
154
155 /**
156  * Token information for mapping the request and responses by resource model.
157  */
158 typedef char *CAToken_t;
159
160 /*
161  * Socket types and error definitions.
162  */
163 #ifdef HAVE_WINSOCK2_H
164 # define OC_SOCKET_ERROR      SOCKET_ERROR
165 # define OC_INVALID_SOCKET    INVALID_SOCKET
166 typedef SOCKET CASocketFd_t;
167 #else // HAVE_WINSOCK2_H
168 # define OC_SOCKET_ERROR      (-1)
169 # define OC_INVALID_SOCKET    (-1)
170 typedef int    CASocketFd_t;
171 #endif
172
173 /*
174  * The following flags are the same as the equivalent OIC values in
175  * octypes.h, allowing direct copying with slight fixup.
176  * The CA layer should used the OC types when build allows that.
177  */
178 #ifdef RA_ADAPTER
179 #define MAX_ADDR_STR_SIZE_CA (256)
180 #else
181 /*
182  * Max Address could be "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
183  * Which is 65, +1 for null terminator => 66
184  * OCDevAddr (defined in OCTypes.h) must be the same
185  * as CAEndpoint_t (defined here)
186  */
187 #define MAX_ADDR_STR_SIZE_CA (66)
188 #endif
189
190 typedef enum
191 {
192     CA_DEFAULT_ADAPTER = 0,
193
194     // value zero indicates discovery
195     CA_ADAPTER_IP            = (1 << 0),   // IPv4 and IPv6, including 6LoWPAN
196     CA_ADAPTER_GATT_BTLE     = (1 << 1),   // GATT over Bluetooth LE
197     CA_ADAPTER_RFCOMM_BTEDR  = (1 << 2),   // RFCOMM over Bluetooth EDR
198
199 #ifdef RA_ADAPTER
200     CA_ADAPTER_REMOTE_ACCESS = (1 << 3),   // Remote Access over XMPP.
201 #endif
202
203     CA_ADAPTER_TCP           = (1 << 4),   // CoAP over TCP
204     CA_ADAPTER_NFC           = (1 << 5),   // NFC Adapter
205
206     CA_ALL_ADAPTERS          = 0xffffffff
207 } CATransportAdapter_t;
208
209 typedef enum
210 {
211     CA_DEFAULT_FLAGS = 0,
212
213     // Insecure transport is the default (subject to change)
214     CA_SECURE          = (1 << 4),   // secure the transport path
215     // IPv4 & IPv6 autoselection is the default
216     CA_IPV6            = (1 << 5),   // IP adapter only
217     CA_IPV4            = (1 << 6),   // IP adapter only
218     // Indication that a message was received by multicast.
219     CA_MULTICAST       = (1 << 7),
220     // Link-Local multicast is the default multicast scope for IPv6.
221     // These correspond in both value and position to the IPv6 address bits.
222     CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
223     CA_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
224     CA_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
225     CA_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
226     CA_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
227     CA_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
228     CA_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
229 } CATransportFlags_t;
230
231 typedef enum
232 {
233     CA_DEFAULT_BT_FLAGS = 0,
234     // flags for BLE transport
235     CA_LE_ADV_DISABLE   = 0x1,   // disable BLE advertisement.
236     CA_LE_ADV_ENABLE    = 0x2,   // enable BLE advertisement.
237     CA_LE_SERVER_DISABLE = (1 << 4),   // disable gatt server.
238     // flags for EDR transport
239     CA_EDR_SERVER_DISABLE = (1 << 7)   // disable rfcomm server.
240 } CATransportBTFlags_t;
241
242 #define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
243 #define CA_SCOPE_MASK 0xf     // mask scope bits above
244
245 /**
246  * Information about the network status.
247  */
248 typedef enum
249 {
250     CA_INTERFACE_DOWN,   /**< Connection is not available */
251     CA_INTERFACE_UP    /**< Connection is Available */
252 } CANetworkStatus_t;
253
254 /*
255  * remoteEndpoint identity.
256  */
257 typedef struct
258 {
259     uint16_t id_length;
260     unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
261 } CARemoteId_t;
262
263 /**
264  * Message Type for Base source code.
265  */
266 typedef enum
267 {
268     CA_MSG_CONFIRM = 0,  /**< confirmable message (requires ACK/RST) */
269     CA_MSG_NONCONFIRM,   /**< non-confirmable message (one-shot message) */
270     CA_MSG_ACKNOWLEDGE,  /**< used to acknowledge confirmable messages */
271     CA_MSG_RESET         /**< used to indicates not-interested or error (lack of context)in
272                                                   received messages */
273 } CAMessageType_t;
274
275 /**
276  * Allowed method to be used by resource model.
277  */
278 typedef enum
279 {
280     CA_GET = 1, /**< GET Method  */
281     CA_POST,    /**< POST Method */
282     CA_PUT,     /**< PUT Method */
283     CA_DELETE   /**< DELETE Method */
284 } CAMethod_t;
285
286 /**
287  * block size.
288  * it depends on defined size in libCoAP.
289  */
290 typedef enum
291 {
292     CA_BLOCK_SIZE_16_BYTE = 0,    /**< 16byte */
293     CA_BLOCK_SIZE_32_BYTE = 1,    /**< 32byte */
294     CA_BLOCK_SIZE_64_BYTE = 2,    /**< 64byte */
295     CA_BLOCK_SIZE_128_BYTE = 3,   /**< 128byte */
296     CA_BLOCK_SIZE_256_BYTE = 4,   /**< 256byte */
297     CA_BLOCK_SIZE_512_BYTE = 5,   /**< 512byte */
298     CA_BLOCK_SIZE_1024_BYTE = 6     /**< 1Kbyte */
299 } CABlockSize_t;
300
301 /**
302  * Endpoint information for connectivities.
303  * Must be identical to OCDevAddr.
304  */
305 typedef struct
306 {
307     CATransportAdapter_t    adapter;    // adapter type
308     CATransportFlags_t      flags;      // transport modifiers
309     uint16_t                port;       // for IP
310     char                    addr[MAX_ADDR_STR_SIZE_CA]; // address for all
311     uint32_t                ifindex;    // usually zero for default interface
312     char                    remoteId[CA_MAX_IDENTITY_SIZE]; // device ID of remote device
313 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
314     char                    routeData[MAX_ADDR_STR_SIZE_CA]; /**< GatewayId:ClientId of
315                                                                     destination. **/
316 #endif
317 } CAEndpoint_t;
318
319 /**
320  * Endpoint information for secure messages.
321  */
322 typedef struct
323 {
324     CAEndpoint_t endpoint;      /**< endpoint */
325     // TODO change name to deviceId
326     CARemoteId_t identity;      /**< endpoint device uuid */
327     CARemoteId_t userId;        /**< endpoint user uuid */
328 } CASecureEndpoint_t;
329
330 /**
331  * Enums for CA return values.
332  */
333 typedef enum
334 {
335     /* Result code - START HERE */
336     CA_STATUS_OK = 0,               /**< Success */
337     CA_STATUS_INVALID_PARAM,        /**< Invalid Parameter */
338     CA_ADAPTER_NOT_ENABLED,         /**< Adapter is not enabled */
339     CA_SERVER_STARTED_ALREADY,      /**< Server is started already */
340     CA_SERVER_NOT_STARTED,          /**< Server is not started */
341     CA_DESTINATION_NOT_REACHABLE,   /**< Destination is not reachable */
342     CA_SOCKET_OPERATION_FAILED,     /**< Socket operation failed */
343     CA_SEND_FAILED,                 /**< Send request failed */
344     CA_RECEIVE_FAILED,              /**< Receive failed */
345     CA_MEMORY_ALLOC_FAILED,         /**< Memory allocation failed */
346     CA_REQUEST_TIMEOUT,             /**< Request is Timeout */
347     CA_DESTINATION_DISCONNECTED,    /**< Destination is disconnected */
348     CA_NOT_SUPPORTED,               /**< Not supported */
349     CA_STATUS_NOT_INITIALIZED,      /**< Not Initialized*/
350     CA_DTLS_AUTHENTICATION_FAILURE, /**< Decryption error in DTLS */
351     CA_STATUS_FAILED =255           /**< Failure */
352     /* Result code - END HERE */
353 } CAResult_t;
354
355 /**
356  * Enums for CA Response values.
357  */
358 typedef enum
359 {
360     /* Response status code - START HERE */
361     CA_EMPTY = 0,                           /**< Empty */
362     CA_CREATED = 201,                       /**< Created */
363     CA_DELETED = 202,                       /**< Deleted */
364     CA_VALID = 203,                         /**< Valid */
365     CA_CHANGED = 204,                       /**< Changed */
366     CA_CONTENT = 205,                       /**< Content */
367     CA_CONTINUE = 231,                      /**< Continue */
368     CA_BAD_REQ = 400,                       /**< Bad Request */
369     CA_UNAUTHORIZED_REQ = 401,              /**< Unauthorized Request */
370     CA_BAD_OPT = 402,                       /**< Bad Option */
371     CA_FORBIDDEN_REQ = 403,                 /**< Forbidden Request */
372     CA_NOT_FOUND = 404,                     /**< Not found */
373     CA_METHOD_NOT_ALLOWED = 405,            /**< Method Not Allowed */
374     CA_NOT_ACCEPTABLE = 406,                /**< Not Acceptable */
375     CA_REQUEST_ENTITY_INCOMPLETE = 408,     /**< Request Entity Incomplete */
376     CA_REQUEST_ENTITY_TOO_LARGE = 413,      /**< Request Entity Too Large */
377     CA_INTERNAL_SERVER_ERROR = 500,         /**< Internal Server Error */
378     CA_NOT_IMPLEMENTED = 501,               /**< Not Implenented */
379     CA_BAD_GATEWAY = 502,                   /**< Bad Gateway */
380     CA_SERVICE_UNAVAILABLE = 503,           /**< Server Unavailable */
381     CA_RETRANSMIT_TIMEOUT = 504,            /**< Retransmit timeout */
382     CA_PROXY_NOT_SUPPORTED = 505            /**< Proxy not enabled to service a request */
383     /* Response status code - END HERE */
384 } CAResponseResult_t;
385
386 /**
387  * Data type whether the data is Request Message or Response Message.
388  * if there is some failure before send data on network.
389  * Type will be set as error type for error callback.
390  */
391 typedef enum
392 {
393     CA_REQUEST_DATA = 1,
394     CA_RESPONSE_DATA,
395     CA_ERROR_DATA,
396     CA_RESPONSE_FOR_RES,
397     CA_NETWORK_COMMAND
398 } CADataType_t;
399
400 typedef enum
401 {
402     CA_DISCONNECTED = 0,
403     CA_CONNECTED,
404     CA_REQ_DISCONNECT
405 } CAConnectEvent_t;
406
407 /**
408  * Transport Protocol IDs for additional options.
409  */
410 typedef enum
411 {
412     CA_INVALID_ID = (1 << 0),   /**< Invalid ID */
413     CA_COAP_ID = (1 << 1)       /**< COAP ID */
414 } CATransportProtocolID_t;
415
416 /**
417  * Adapter State to indicate the network changed notifications.
418  */
419 typedef enum
420 {
421     CA_ADAPTER_DISABLED,   /**< Adapter is Disabled */
422     CA_ADAPTER_ENABLED     /**< Adapter is Enabled */
423 } CAAdapterState_t;
424
425 /**
426  * Format indicating which encoding has been used on the payload.
427  */
428 typedef enum
429 {
430     CA_FORMAT_UNDEFINED = 0,            /**< Undefined enoding format */
431     CA_FORMAT_TEXT_PLAIN,
432     CA_FORMAT_APPLICATION_LINK_FORMAT,
433     CA_FORMAT_APPLICATION_XML,
434     CA_FORMAT_APPLICATION_OCTET_STREAM,
435     CA_FORMAT_APPLICATION_RDF_XML,
436     CA_FORMAT_APPLICATION_EXI,
437     CA_FORMAT_APPLICATION_JSON,
438     CA_FORMAT_APPLICATION_CBOR,
439     CA_FORMAT_UNSUPPORTED
440 } CAPayloadFormat_t;
441
442 /**
443  * Header options structure to be filled.
444  *
445  * This structure is used to hold header information.
446  */
447 typedef struct
448 {
449     CATransportProtocolID_t protocolID;                     /**< Protocol ID of the Option */
450     uint16_t optionID;                                      /**< The header option ID which will be
451                                                             added to communication packets */
452     uint16_t optionLength;                                  /**< Option Length **/
453     char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];      /**< Optional data values**/
454 } CAHeaderOption_t;
455
456 /**
457  * Base Information received.
458  *
459  * This structure is used to hold request & response base information.
460  */
461 typedef struct
462 {
463     CAMessageType_t type;       /**< Qos for the request */
464 #ifdef ROUTING_GATEWAY
465     bool skipRetransmission;    /**< Will not attempt retransmission even if type is CONFIRM.
466                                      Required for packet forwarding */
467 #endif
468     uint16_t messageId;         /**< Message id.
469                                  * if message id is zero, it will generated by CA inside.
470                                  * otherwise, you can use it */
471     CAToken_t token;            /**< Token for CA */
472     uint8_t tokenLength;        /**< token length */
473     CAHeaderOption_t *options;  /** Header Options for the request */
474     uint8_t numOptions;         /**< Number of Header options */
475     CAPayload_t payload;        /**< payload of the request  */
476     size_t payloadSize;         /**< size in bytes of the payload */
477     CAPayloadFormat_t payloadFormat;    /**< encoding format of the request payload */
478     CAPayloadFormat_t acceptFormat;     /**< accept format for the response payload */
479     CAURI_t resourceUri;        /**< Resource URI information **/
480     CARemoteId_t identity;      /**< endpoint identity */
481     CADataType_t dataType;      /**< data type */
482     CAConnectEvent_t event;     /**< network request message / event type */
483 } CAInfo_t;
484
485 /**
486  * Request Information to be sent.
487  *
488  * This structure is used to hold request information.
489  */
490 typedef struct
491 {
492     CAMethod_t method;  /**< Name of the Method Allowed */
493     CAInfo_t info;      /**< Information of the request. */
494     bool isMulticast;   /**< is multicast request */
495 } CARequestInfo_t;
496
497 /**
498  * Response information received.
499  *
500  * This structure is used to hold response information.
501  */
502 typedef struct
503 {
504     CAResponseResult_t result;  /**< Result for response by resource model */
505     CAInfo_t info;              /**< Information of the response */
506     bool isMulticast;
507 } CAResponseInfo_t;
508
509 /**
510  * Error information from CA
511  *        contains error code and message information.
512  *
513  * This structure holds error information.
514  */
515 typedef struct
516 {
517     CAResult_t result;  /**< CA API request result  */
518     CAInfo_t info;      /**< message information such as token and payload data
519                              helpful to identify the error */
520 } CAErrorInfo_t;
521
522 /**
523  * Hold global variables for CA layer. (also used by RI layer)
524  */
525 typedef struct
526 {
527     CASocketFd_t fd;    /**< socket fd */
528     uint16_t port;      /**< socket port */
529 } CASocket_t;
530
531 #define HISTORYSIZE (4)
532
533 typedef struct
534 {
535     CATransportFlags_t flags;
536     uint16_t messageId;
537     char token[CA_MAX_TOKEN_LEN];
538     uint8_t tokenLength;
539 } CAHistoryItem_t;
540
541 typedef struct
542 {
543     int nextIndex;
544     CAHistoryItem_t items[HISTORYSIZE];
545 } CAHistory_t;
546
547 /**
548  * Hold interface index for keeping track of comings and goings.
549  */
550 typedef struct
551 {
552     int32_t ifIndex; /**< network interface index */
553 } CAIfItem_t;
554
555 /**
556  * Hold the port number assigned from application.
557  * It will be used when creating a socket.
558  */
559 typedef struct
560 {
561     struct udpports
562     {
563         uint16_t u6;    /**< unicast IPv6 socket port */
564         uint16_t u6s;   /**< unicast IPv6 socket secure port */
565         uint16_t u4;    /**< unicast IPv4 socket port */
566         uint16_t u4s;   /**< unicast IPv4 socket secure port */
567     } udp;
568 #ifdef TCP_ADAPTER
569     struct tcpports
570     {
571         uint16_t u4;    /**< unicast IPv4 socket port */
572         uint16_t u4s;   /**< unicast IPv6 socket secure port */
573         uint16_t u6;    /**< unicast IPv6 socket port */
574         uint16_t u6s;   /**< unicast IPv6 socket secure port */
575     } tcp;
576 #endif
577 } CAPorts_t;
578
579 typedef struct
580 {
581     CATransportFlags_t clientFlags; /**< flag for client */
582     CATransportFlags_t serverFlags; /**< flag for server */
583     bool client; /**< client mode */
584     bool server; /**< server mode */
585
586     CAPorts_t ports;
587
588     struct sockets
589     {
590         void *threadpool;           /**< threadpool between Initialize and Start */
591         CASocket_t u6;              /**< unicast   IPv6 */
592         CASocket_t u6s;             /**< unicast   IPv6 secure */
593         CASocket_t u4;              /**< unicast   IPv4 */
594         CASocket_t u4s;             /**< unicast   IPv4 secure */
595         CASocket_t m6;              /**< multicast IPv6 */
596         CASocket_t m6s;             /**< multicast IPv6 secure */
597         CASocket_t m4;              /**< multicast IPv4 */
598         CASocket_t m4s;             /**< multicast IPv4 secure */
599         CASocketFd_t netlinkFd;     /**< netlink */
600 #if defined(_WIN32)
601         WSAEVENT shutdownEvent;     /**< Event used to signal threads to stop */
602 #else
603 #ifndef __TIZENRT__
604         int shutdownFds[2];         /**< fds used to signal threads to stop */
605 #endif
606 #endif
607         int selectTimeout;          /**< in seconds */
608         int maxfd;                  /**< highest fd (for select) */
609         bool started;               /**< the IP adapter has started */
610         bool terminate;             /**< the IP adapter needs to stop */
611         bool ipv6enabled;           /**< IPv6 enabled by OCInit flags */
612         bool ipv4enabled;           /**< IPv4 enabled by OCInit flags */
613         bool dualstack;             /**< IPv6 and IPv4 enabled */
614 #if defined (_WIN32)
615         LPFN_WSARECVMSG wsaRecvMsg; /**< Win32 function pointer to WSARecvMsg() */
616 #endif
617
618         struct networkmonitors
619         {
620             CAIfItem_t *ifItems; /**< current network interface index list */
621             size_t sizeIfItems;  /**< size of network interface index array */
622             size_t numIfItems;   /**< number of valid network interfaces */
623         } nm;
624     } ip;
625
626     struct calayer
627     {
628         CAHistory_t requestHistory;  /**< filter IP family in requests */
629     } ca;
630
631 #ifdef TCP_ADAPTER
632     /**
633      * Hold global variables for TCP Adapter.
634      */
635     struct tcpsockets
636     {
637         void *threadpool;       /**< threadpool between Initialize and Start */
638         CASocket_t ipv4;        /**< IPv4 accept socket */
639         CASocket_t ipv4s;       /**< IPv4 accept socket secure */
640         CASocket_t ipv6;        /**< IPv6 accept socket */
641         CASocket_t ipv6s;       /**< IPv6 accept socket secure */
642         void *svrlist;          /**< unicast IPv4 TCP server information*/
643         int selectTimeout;      /**< in seconds */
644         int listenBacklog;      /**< backlog counts*/
645 #ifndef __TIZENRT__
646         int shutdownFds[2];     /**< shutdown pipe */
647 #endif
648         int connectionFds[2];   /**< connection pipe */
649         int maxfd;              /**< highest fd (for select) */
650         bool started;           /**< the TCP adapter has started */
651         bool terminate;         /**< the TCP adapter needs to stop */
652         bool ipv4tcpenabled;    /**< IPv4 TCP enabled by OCInit flags */
653         bool ipv6tcpenabled;    /**< IPv6 TCP enabled by OCInit flags */
654     } tcp;
655 #endif
656     CATransportBTFlags_t bleFlags;
657 } CAGlobals_t;
658
659 extern CAGlobals_t caglobals;
660
661 typedef enum
662 {
663     CA_LOG_LEVEL_ALL = 1,             // all logs.
664     CA_LOG_LEVEL_INFO,                // debug level is disabled
665 } CAUtilLogLevel_t;
666
667 /**
668  * Callback function type for request delivery.
669  * @param[out]   object       Endpoint object from which the request is received.
670  *                            It contains endpoint address based on the connectivity type.
671  * @param[out]   requestInfo  Info for resource model to understand about the request.
672  */
673 typedef void (*CARequestCallback)(const CAEndpoint_t *object,
674                                   const CARequestInfo_t *requestInfo);
675
676 /**
677  * Callback function type for response delivery.
678  * @param[out]   object           Endpoint object from which the response is received.
679  * @param[out]   responseInfo     Identifier which needs to be mapped with response.
680  */
681 typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
682                                    const CAResponseInfo_t *responseInfo);
683 /**
684  * Callback function type for error.
685  * @param[out]   object           remote device information.
686  * @param[out]   errorInfo        CA Error information.
687  */
688 typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
689                                 const CAErrorInfo_t *errorInfo);
690
691 /**
692  * Callback function type for network status changes delivery from CA common logic.
693  * @param[out]   info       Endpoint object from which the network status is changed.
694  *                          It contains endpoint address based on the connectivity type.
695  * @param[out]   status     Current network status info.
696  */
697 typedef void (*CANetworkMonitorCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);
698
699 #ifdef __cplusplus
700 } /* extern "C" */
701 #endif
702
703 #endif // CA_COMMON_H_