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