Revert "[CONPRO-1568] Ignoring duplicate IPv6/Ipv4 messages"
[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     CA_REQUEST_DATA_SERVER_INIT,
408     CA_RESPONSE_DATA_CLIENT_INIT
409 } CADataType_t;
410
411 typedef enum
412 {
413     CA_DISCONNECTED = 0,
414     CA_CONNECTED,
415     CA_REQ_DISCONNECT
416 } CAConnectEvent_t;
417
418 /**
419  * Transport Protocol IDs for additional options.
420  */
421 typedef enum
422 {
423     CA_INVALID_ID = (1 << 0),   /**< Invalid ID */
424     CA_COAP_ID = (1 << 1)       /**< COAP ID */
425 } CATransportProtocolID_t;
426
427 /**
428  * Adapter State to indicate the network changed notifications.
429  */
430 typedef enum
431 {
432     CA_ADAPTER_DISABLED,   /**< Adapter is Disabled */
433     CA_ADAPTER_ENABLED     /**< Adapter is Enabled */
434 } CAAdapterState_t;
435
436 /**
437  * Format indicating which encoding has been used on the payload.
438  */
439 typedef enum
440 {
441     CA_FORMAT_UNDEFINED = 0,            /**< Undefined enoding format */
442     CA_FORMAT_TEXT_PLAIN,
443     CA_FORMAT_APPLICATION_LINK_FORMAT,
444     CA_FORMAT_APPLICATION_XML,
445     CA_FORMAT_APPLICATION_OCTET_STREAM,
446     CA_FORMAT_APPLICATION_RDF_XML,
447     CA_FORMAT_APPLICATION_EXI,
448     CA_FORMAT_APPLICATION_JSON,
449     CA_FORMAT_APPLICATION_CBOR,
450     CA_FORMAT_UNSUPPORTED
451 } CAPayloadFormat_t;
452
453 /**
454  * Header options structure to be filled.
455  *
456  * This structure is used to hold header information.
457  */
458 typedef struct
459 {
460     CATransportProtocolID_t protocolID;                     /**< Protocol ID of the Option */
461     uint16_t optionID;                                      /**< The header option ID which will be
462                                                             added to communication packets */
463     uint16_t optionLength;                                  /**< Option Length **/
464     char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];      /**< Optional data values**/
465 } CAHeaderOption_t;
466
467 /**
468  * Base Information received.
469  *
470  * This structure is used to hold request & response base information.
471  */
472 typedef struct
473 {
474     CAMessageType_t type;       /**< Qos for the request */
475 #ifdef ROUTING_GATEWAY
476     bool skipRetransmission;    /**< Will not attempt retransmission even if type is CONFIRM.
477                                      Required for packet forwarding */
478 #endif
479     uint16_t messageId;         /**< Message id.
480                                  * if message id is zero, it will generated by CA inside.
481                                  * otherwise, you can use it */
482     CAToken_t token;            /**< Token for CA */
483     uint8_t tokenLength;        /**< token length */
484     CAHeaderOption_t *options;  /** Header Options for the request */
485     uint8_t numOptions;         /**< Number of Header options */
486     CAPayload_t payload;        /**< payload of the request  */
487     size_t payloadSize;         /**< size in bytes of the payload */
488     CAPayloadFormat_t payloadFormat;    /**< encoding format of the request payload */
489     CAPayloadFormat_t acceptFormat;     /**< accept format for the response payload */
490     CAURI_t resourceUri;        /**< Resource URI information **/
491     CARemoteId_t identity;      /**< endpoint identity */
492     CADataType_t dataType;      /**< data type */
493     CAConnectEvent_t event;     /**< network request message / event type */
494 } CAInfo_t;
495
496 /**
497  * Request Information to be sent.
498  *
499  * This structure is used to hold request information.
500  */
501 typedef struct
502 {
503     CAMethod_t method;  /**< Name of the Method Allowed */
504     CAInfo_t info;      /**< Information of the request. */
505     bool isMulticast;   /**< is multicast request */
506 } CARequestInfo_t;
507
508 /**
509  * Response information received.
510  *
511  * This structure is used to hold response information.
512  */
513 typedef struct
514 {
515     CAResponseResult_t result;  /**< Result for response by resource model */
516     CAInfo_t info;              /**< Information of the response */
517     bool isMulticast;
518 } CAResponseInfo_t;
519
520 /**
521  * Error information from CA
522  *        contains error code and message information.
523  *
524  * This structure holds error information.
525  */
526 typedef struct
527 {
528     CAResult_t result;  /**< CA API request result  */
529     CAInfo_t info;      /**< message information such as token and payload data
530                              helpful to identify the error */
531 } CAErrorInfo_t;
532
533 /**
534  * Hold global variables for CA layer. (also used by RI layer)
535  */
536 typedef struct
537 {
538     CASocketFd_t fd;    /**< socket fd */
539     uint16_t port;      /**< socket port */
540 } CASocket_t;
541
542 #define HISTORYSIZE (4)
543
544 typedef struct
545 {
546     CATransportFlags_t flags;
547     uint16_t messageId;
548     char token[CA_MAX_TOKEN_LEN];
549     uint8_t tokenLength;
550 } CAHistoryItem_t;
551
552 typedef struct
553 {
554     int nextIndex;
555     CAHistoryItem_t items[HISTORYSIZE];
556 } CAHistory_t;
557
558 /**
559  * Hold interface index for keeping track of comings and goings.
560  */
561 typedef struct
562 {
563     int32_t ifIndex; /**< network interface index */
564 } CAIfItem_t;
565
566 /**
567  * Hold the port number assigned from application.
568  * It will be used when creating a socket.
569  */
570 typedef struct
571 {
572     struct udpports
573     {
574         uint16_t u6;    /**< unicast IPv6 socket port */
575         uint16_t u6s;   /**< unicast IPv6 socket secure port */
576         uint16_t u4;    /**< unicast IPv4 socket port */
577         uint16_t u4s;   /**< unicast IPv4 socket secure port */
578     } udp;
579 #ifdef TCP_ADAPTER
580     struct tcpports
581     {
582         uint16_t u4;    /**< unicast IPv4 socket port */
583         uint16_t u4s;   /**< unicast IPv6 socket secure port */
584         uint16_t u6;    /**< unicast IPv6 socket port */
585         uint16_t u6s;   /**< unicast IPv6 socket secure port */
586     } tcp;
587 #endif
588 } CAPorts_t;
589
590 typedef struct
591 {
592     CATransportFlags_t clientFlags; /**< flag for client */
593     CATransportFlags_t serverFlags; /**< flag for server */
594     bool client; /**< client mode */
595     bool server; /**< server mode */
596
597     CAPorts_t ports;
598
599     struct sockets
600     {
601         void *threadpool;           /**< threadpool between Initialize and Start */
602         CASocket_t u6;              /**< unicast   IPv6 */
603         CASocket_t u6s;             /**< unicast   IPv6 secure */
604         CASocket_t u4;              /**< unicast   IPv4 */
605         CASocket_t u4s;             /**< unicast   IPv4 secure */
606         CASocket_t m6;              /**< multicast IPv6 */
607         CASocket_t m6s;             /**< multicast IPv6 secure */
608         CASocket_t m4;              /**< multicast IPv4 */
609         CASocket_t m4s;             /**< multicast IPv4 secure */
610         CASocketFd_t netlinkFd;     /**< netlink */
611 #if defined(_WIN32)
612         WSAEVENT shutdownEvent;     /**< Event used to signal threads to stop */
613 #else
614 #ifndef __TIZENRT__
615         int shutdownFds[2];         /**< fds used to signal threads to stop */
616 #endif
617 #endif
618         int selectTimeout;          /**< in seconds */
619         bool started;               /**< the IP adapter has started */
620         bool terminate;             /**< the IP adapter needs to stop */
621         bool ipv6enabled;           /**< IPv6 enabled by OCInit flags */
622         bool ipv4enabled;           /**< IPv4 enabled by OCInit flags */
623         bool dualstack;             /**< IPv6 and IPv4 enabled */
624 #if defined (_WIN32)
625         LPFN_WSARECVMSG wsaRecvMsg; /**< Win32 function pointer to WSARecvMsg() */
626 #endif
627
628         struct networkmonitors
629         {
630             CAIfItem_t *ifItems; /**< current network interface index list */
631             size_t sizeIfItems;  /**< size of network interface index array */
632             size_t numIfItems;   /**< number of valid network interfaces */
633         } nm;
634     } ip;
635
636     struct calayer
637     {
638         CAHistory_t requestHistory;  /**< filter IP family in requests */
639     } ca;
640
641 #ifdef TCP_ADAPTER
642     /**
643      * Hold global variables for TCP Adapter.
644      */
645     struct tcpsockets
646     {
647         void *threadpool;       /**< threadpool between Initialize and Start */
648         CASocket_t ipv4;        /**< IPv4 accept socket */
649         CASocket_t ipv4s;       /**< IPv4 accept socket secure */
650         CASocket_t ipv6;        /**< IPv6 accept socket */
651         CASocket_t ipv6s;       /**< IPv6 accept socket secure */
652         void *svrlist;          /**< unicast IPv4 TCP server information*/
653         int selectTimeout;      /**< in seconds */
654         int listenBacklog;      /**< backlog counts*/
655 #ifndef __TIZENRT__
656         int shutdownFds[2];     /**< shutdown pipe */
657 #endif
658         int connectionFds[2];   /**< connection pipe */
659         bool started;           /**< the TCP adapter has started */
660         bool terminate;         /**< the TCP adapter needs to stop */
661         bool bindenabled;       /**< binding of TCP socket enabled */
662         bool ipv4tcpenabled;    /**< IPv4 TCP enabled by OCInit flags */
663         bool ipv6tcpenabled;    /**< IPv6 TCP enabled by OCInit flags */
664     } tcp;
665 #endif
666     CATransportBTFlags_t bleFlags;
667 } CAGlobals_t;
668
669 extern CAGlobals_t caglobals;
670
671 typedef enum
672 {
673     CA_LOG_LEVEL_ALL = 1,             // all logs.
674     CA_LOG_LEVEL_INFO,                // debug level is disabled
675 } CAUtilLogLevel_t;
676
677 /**
678  * Callback function type for request delivery.
679  * @param[out]   object       Endpoint object from which the request is received.
680  *                            It contains endpoint address based on the connectivity type.
681  * @param[out]   requestInfo  Info for resource model to understand about the request.
682  */
683 typedef void (*CARequestCallback)(const CAEndpoint_t *object,
684                                   const CARequestInfo_t *requestInfo);
685
686 /**
687  * Callback function type for response delivery.
688  * @param[out]   object           Endpoint object from which the response is received.
689  * @param[out]   responseInfo     Identifier which needs to be mapped with response.
690  */
691 typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
692                                    const CAResponseInfo_t *responseInfo);
693 /**
694  * Callback function type for error.
695  * @param[out]   object           remote device information.
696  * @param[out]   errorInfo        CA Error information.
697  */
698 typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
699                                 const CAErrorInfo_t *errorInfo);
700
701 /**
702  * Callback function type for network status changes delivery from CA common logic.
703  * @param[out]   info       Endpoint object from which the network status is changed.
704  *                          It contains endpoint address based on the connectivity type.
705  * @param[out]   status     Current network status info.
706  */
707 typedef void (*CANetworkMonitorCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);
708
709 /**
710  * Callback function type for editing bluetooth advertisement data before starting bluetooth advertisement.
711  * param[in]   max_data_size    Maximal size of advertisement data array
712  * param[out]  data             Advertisement data array
713  * param[out]  data_size        Actual Data size of advertisement data array
714  */
715 typedef void (*CAAdvertisementDataGetterCB)(int max_data_size, char *data, int *data_size);
716
717 #ifdef __cplusplus
718 } /* extern "C" */
719 #endif
720
721 #endif // CA_COMMON_H_