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