summaryrefslogtreecommitdiff
path: root/resource/csdk/connectivity/api/cacommon.h
blob: f2369680085837d657a9e280618b5d07e5c02fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/* ****************************************************************
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************/

/**
 * @file cacommon.h
 * This file contains the common data structures between Resource , CA and adapters
 */

#ifndef CA_COMMON_H_
#define CA_COMMON_H_

#include "iotivity_config.h"
#ifdef WITH_PROCESS_EVENT
#include "ocevent.h"
#endif

#ifndef WITH_ARDUINO
#ifdef TCP_ADAPTER
#define HAVE_SYS_POLL_H
#endif
#endif

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>

#ifdef __TIZENRT__
#include <poll.h>
#else
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
#endif

#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#include <mswsock.h>
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/**
 * TAG of Analyzer log.
 */
#define ANALYZER_TAG       "OIC_CA_ANALYZER_102301"
#define BLE_CLIENT_TAG     "OIC_CA_LE_CLIENT_1023"
#define BLE_SERVER_MCD_TAG "OIC_CA_LE_SER_MC_1023"
#define IP_SERVER_TAG      "OIC_CA_IP_SERVER_1023"
#define TCP_SERVER_TAG     "OIC_CA_TCP_SERVER_1023"

/**
 * IP address Length.
 */
#define CA_IPADDR_SIZE 16

/**
 * Remote Access jabber ID length.
 */
#define CA_RAJABBERID_SIZE 256

/**
 * Mac address length for BT port.
 */
#define CA_MACADDR_SIZE 18

/**
 * Max header options data length.
 */
#if defined(ARDUINO) || defined(__TIZENRT__)
#define CA_MAX_HEADER_OPTION_DATA_LENGTH 20
#else
#define CA_MAX_HEADER_OPTION_DATA_LENGTH 1024
#endif

/**
* Max token length.
*/
#define CA_MAX_TOKEN_LEN (8)

/**
* Max interface name length.
*/
#define CA_MAX_INTERFACE_NAME_LEN (16)

/**
 * Max URI length.
 */
#ifdef ARDUINO
#define CA_MAX_URI_LENGTH 128  /* maximum size of URI for embedded platforms*/
#else
#define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/
#endif

/**
 * Max PDU length supported.
 */
#ifdef ARDUINO
#define COAP_MAX_PDU_SIZE           320  /* maximum size of a CoAP PDU for embedded platforms*/
#else
#define COAP_MAX_PDU_SIZE           1400 /* maximum size of a CoAP PDU for big platforms*/
#endif

#ifdef WITH_BWT
#define CA_DEFAULT_BLOCK_SIZE       CA_BLOCK_SIZE_1024_BYTE
#endif

/**
 *Maximum length of the remoteEndpoint identity.
 */
#define CA_MAX_ENDPOINT_IDENTITY_LEN  CA_MAX_IDENTITY_SIZE

/**
 * Max identity size.
 */
#define CA_MAX_IDENTITY_SIZE (37)

/**
 * option types - the highest option number 63.
 */
#define CA_OPTION_IF_MATCH 1
#define CA_OPTION_ETAG 4
#define CA_OPTION_IF_NONE_MATCH 5
#define CA_OPTION_OBSERVE 6
#define CA_OPTION_LOCATION_PATH 8
#define CA_OPTION_URI_PATH 11
#define CA_OPTION_CONTENT_FORMAT 12
#define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
#define CA_OPTION_MAXAGE 14
#define CA_OPTION_URI_QUERY 15
#define CA_OPTION_ACCEPT 17
#define CA_OPTION_LOCATION_QUERY 20

/**
 * Payload information from resource model.
 */
typedef uint8_t *CAPayload_t;

/**
 * URI for the OIC base.CA considers relative URI as the URI.
 */
typedef char *CAURI_t;

/**
 * Token information for mapping the request and responses by resource model.
 */
typedef char *CAToken_t;

/*
 * Socket types and error definitions.
 */
#ifdef HAVE_WINSOCK2_H
# define OC_SOCKET_ERROR      SOCKET_ERROR
# define OC_INVALID_SOCKET    INVALID_SOCKET
typedef SOCKET CASocketFd_t;
#else // HAVE_WINSOCK2_H
# define OC_SOCKET_ERROR      (-1)
# define OC_INVALID_SOCKET    (-1)
typedef int    CASocketFd_t;
#endif

/*
 * The following flags are the same as the equivalent OIC values in
 * octypes.h, allowing direct copying with slight fixup.
 * The CA layer should used the OC types when build allows that.
 */
#ifdef RA_ADAPTER
#define MAX_ADDR_STR_SIZE_CA (256)
#else
/*
 * Max Address could be "coaps+tcp://[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:yyy.yyy.yyy.yyy]:xxxxx"
 * Which is 65, +1 for null terminator => 66
 * OCDevAddr (defined in OCTypes.h) must be the same
 * as CAEndpoint_t (defined here)
 */
#define MAX_ADDR_STR_SIZE_CA (66)
#endif

typedef enum
{
    CA_DEFAULT_ADAPTER = 0,

    // value zero indicates discovery
    CA_ADAPTER_IP            = (1 << 0),   // IPv4 and IPv6, including 6LoWPAN
    CA_ADAPTER_GATT_BTLE     = (1 << 1),   // GATT over Bluetooth LE
    CA_ADAPTER_RFCOMM_BTEDR  = (1 << 2),   // RFCOMM over Bluetooth EDR

#ifdef RA_ADAPTER
    CA_ADAPTER_REMOTE_ACCESS = (1 << 3),   // Remote Access over XMPP.
#endif

    CA_ADAPTER_TCP           = (1 << 4),   // CoAP over TCP
    CA_ADAPTER_NFC           = (1 << 5),   // NFC Adapter

    CA_ALL_ADAPTERS          = 0xffffffff
} CATransportAdapter_t;

typedef enum
{
    CA_DEFAULT_FLAGS = 0,

    // Insecure transport is the default (subject to change)
    CA_SECURE          = (1 << 4),   // secure the transport path
    // IPv4 & IPv6 autoselection is the default
    CA_IPV6            = (1 << 5),   // IP adapter only
    CA_IPV4            = (1 << 6),   // IP adapter only
    // Indication that a message was received by multicast.
    CA_MULTICAST       = (1 << 7),
    // Link-Local multicast is the default multicast scope for IPv6.
    // These correspond in both value and position to the IPv6 address bits.
    CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
    CA_SCOPE_LINK      = 0x2, // IPv6 Link-Local scope (default)
    CA_SCOPE_REALM     = 0x3, // IPv6 Realm-Local scope
    CA_SCOPE_ADMIN     = 0x4, // IPv6 Admin-Local scope
    CA_SCOPE_SITE      = 0x5, // IPv6 Site-Local scope
    CA_SCOPE_ORG       = 0x8, // IPv6 Organization-Local scope
    CA_SCOPE_GLOBAL    = 0xE, // IPv6 Global scope
} CATransportFlags_t;

typedef enum
{
    CA_DEFAULT_BT_FLAGS = 0,
    // flags for BLE transport
    CA_LE_ADV_DISABLE   = 0x1,   // disable BLE advertisement.
    CA_LE_ADV_ENABLE    = 0x2,   // enable BLE advertisement.
    CA_LE_SERVER_DISABLE = (1 << 4),   // disable gatt server.
    // flags for EDR transport
    CA_EDR_SERVER_DISABLE = (1 << 7)   // disable rfcomm server.
} CATransportBTFlags_t;

#define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
#define CA_SCOPE_MASK 0xf     // mask scope bits above

/**
 * Information about the network status.
 */
typedef enum
{
    CA_INTERFACE_DOWN,   /**< Connection is not available */
    CA_INTERFACE_UP    /**< Connection is Available */
} CANetworkStatus_t;

/*
 * remoteEndpoint identity.
 */
typedef struct
{
    uint16_t id_length;
    unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
} CARemoteId_t;

/**
 * Message Type for Base source code.
 */
typedef enum
{
    CA_MSG_CONFIRM = 0,  /**< confirmable message (requires ACK/RST) */
    CA_MSG_NONCONFIRM,   /**< non-confirmable message (one-shot message) */
    CA_MSG_ACKNOWLEDGE,  /**< used to acknowledge confirmable messages */
    CA_MSG_RESET         /**< used to indicates not-interested or error (lack of context)in
                                                  received messages */
} CAMessageType_t;

/**
 * Allowed method to be used by resource model.
 */
typedef enum
{
    CA_GET = 1, /**< GET Method  */
    CA_POST,    /**< POST Method */
    CA_PUT,     /**< PUT Method */
    CA_DELETE   /**< DELETE Method */
} CAMethod_t;

/**
 * block size.
 * it depends on defined size in libCoAP.
 */
typedef enum
{
    CA_BLOCK_SIZE_16_BYTE = 0,    /**< 16byte */
    CA_BLOCK_SIZE_32_BYTE = 1,    /**< 32byte */
    CA_BLOCK_SIZE_64_BYTE = 2,    /**< 64byte */
    CA_BLOCK_SIZE_128_BYTE = 3,   /**< 128byte */
    CA_BLOCK_SIZE_256_BYTE = 4,   /**< 256byte */
    CA_BLOCK_SIZE_512_BYTE = 5,   /**< 512byte */
    CA_BLOCK_SIZE_1024_BYTE = 6     /**< 1Kbyte */
} CABlockSize_t;

/**
 * Endpoint information for connectivities.
 * Must be identical to OCDevAddr.
 */
typedef struct
{
    CATransportAdapter_t    adapter;    // adapter type
    CATransportFlags_t      flags;      // transport modifiers
    uint16_t                port;       // for IP
    char                    addr[MAX_ADDR_STR_SIZE_CA]; // address for all
    uint32_t                ifindex;    // usually zero for default interface
    char                    remoteId[CA_MAX_IDENTITY_SIZE]; // device ID of remote device
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
    char                    routeData[MAX_ADDR_STR_SIZE_CA]; /**< GatewayId:ClientId of
                                                                    destination. **/
#endif
} CAEndpoint_t;

/**
 * Endpoint information for secure messages.
 */
typedef struct
{
    CAEndpoint_t endpoint;      /**< endpoint */
    // TODO change name to deviceId
    CARemoteId_t identity;      /**< endpoint device uuid */
    CARemoteId_t userId;        /**< endpoint user uuid */
} CASecureEndpoint_t;

/**
 * Enums for CA return values.
 */
typedef enum
{
    /* Result code - START HERE */
    CA_STATUS_OK = 0,               /**< Success */
    CA_STATUS_INVALID_PARAM,        /**< Invalid Parameter */
    CA_ADAPTER_NOT_ENABLED,         /**< Adapter is not enabled */
    CA_SERVER_STARTED_ALREADY,      /**< Server is started already */
    CA_SERVER_NOT_STARTED,          /**< Server is not started */
    CA_DESTINATION_NOT_REACHABLE,   /**< Destination is not reachable */
    CA_SOCKET_OPERATION_FAILED,     /**< Socket operation failed */
    CA_SEND_FAILED,                 /**< Send request failed */
    CA_RECEIVE_FAILED,              /**< Receive failed */
    CA_MEMORY_ALLOC_FAILED,         /**< Memory allocation failed */
    CA_REQUEST_TIMEOUT,             /**< Request is Timeout */
    CA_DESTINATION_DISCONNECTED,    /**< Destination is disconnected */
    CA_NOT_SUPPORTED,               /**< Not supported */
    CA_STATUS_NOT_INITIALIZED,      /**< Not Initialized*/
    CA_DTLS_AUTHENTICATION_FAILURE, /**< Decryption error in DTLS */
    CA_STATUS_FAILED =255           /**< Failure */
    /* Result code - END HERE */
} CAResult_t;

/**
 * Enums for CA Response values.
 */
typedef enum
{
    /* Response status code - START HERE */
    CA_EMPTY = 0,                           /**< Empty */
    CA_CREATED = 201,                       /**< Created */
    CA_DELETED = 202,                       /**< Deleted */
    CA_VALID = 203,                         /**< Valid */
    CA_CHANGED = 204,                       /**< Changed */
    CA_CONTENT = 205,                       /**< Content */
    CA_CONTINUE = 231,                      /**< Continue */
    CA_BAD_REQ = 400,                       /**< Bad Request */
    CA_UNAUTHORIZED_REQ = 401,              /**< Unauthorized Request */
    CA_BAD_OPT = 402,                       /**< Bad Option */
    CA_FORBIDDEN_REQ = 403,                 /**< Forbidden Request */
    CA_NOT_FOUND = 404,                     /**< Not found */
    CA_METHOD_NOT_ALLOWED = 405,            /**< Method Not Allowed */
    CA_NOT_ACCEPTABLE = 406,                /**< Not Acceptable */
    CA_REQUEST_ENTITY_INCOMPLETE = 408,     /**< Request Entity Incomplete */
    CA_REQUEST_ENTITY_TOO_LARGE = 413,      /**< Request Entity Too Large */
    CA_TOO_MANY_REQUESTS = 429,             /**< Too Many Requests */
    CA_INTERNAL_SERVER_ERROR = 500,         /**< Internal Server Error */
    CA_NOT_IMPLEMENTED = 501,               /**< Not Implenented */
    CA_BAD_GATEWAY = 502,                   /**< Bad Gateway */
    CA_SERVICE_UNAVAILABLE = 503,           /**< Server Unavailable */
    CA_RETRANSMIT_TIMEOUT = 504,            /**< Retransmit timeout */
    CA_PROXY_NOT_SUPPORTED = 505            /**< Proxy not enabled to service a request */
    /* Response status code - END HERE */
} CAResponseResult_t;

/**
 * Data type whether the data is Request Message or Response Message.
 * if there is some failure before send data on network.
 * Type will be set as error type for error callback.
 */
typedef enum
{
    CA_REQUEST_DATA = 1,
    CA_RESPONSE_DATA,
    CA_ERROR_DATA,
    CA_RESPONSE_FOR_RES,
    CA_NETWORK_COMMAND,
    CA_REQUEST_DATA_SERVER_INIT,
    CA_RESPONSE_DATA_CLIENT_INIT
} CADataType_t;

typedef enum
{
    CA_DISCONNECTED = 0,
    CA_CONNECTED,
    CA_REQ_DISCONNECT
} CAConnectEvent_t;

/**
 * Transport Protocol IDs for additional options.
 */
typedef enum
{
    CA_INVALID_ID = (1 << 0),   /**< Invalid ID */
    CA_COAP_ID = (1 << 1)       /**< COAP ID */
} CATransportProtocolID_t;

/**
 * Adapter State to indicate the network changed notifications.
 */
typedef enum
{
    CA_ADAPTER_DISABLED,   /**< Adapter is Disabled */
    CA_ADAPTER_ENABLED     /**< Adapter is Enabled */
} CAAdapterState_t;

/**
 * Format indicating which encoding has been used on the payload.
 */
typedef enum
{
    CA_FORMAT_UNDEFINED = 0,            /**< Undefined enoding format */
    CA_FORMAT_TEXT_PLAIN,
    CA_FORMAT_APPLICATION_LINK_FORMAT,
    CA_FORMAT_APPLICATION_XML,
    CA_FORMAT_APPLICATION_OCTET_STREAM,
    CA_FORMAT_APPLICATION_RDF_XML,
    CA_FORMAT_APPLICATION_EXI,
    CA_FORMAT_APPLICATION_JSON,
    CA_FORMAT_APPLICATION_CBOR,
    CA_FORMAT_UNSUPPORTED
} CAPayloadFormat_t;

/**
 * Header options structure to be filled.
 *
 * This structure is used to hold header information.
 */
typedef struct
{
    CATransportProtocolID_t protocolID;                     /**< Protocol ID of the Option */
    uint16_t optionID;                                      /**< The header option ID which will be
                                                            added to communication packets */
    uint16_t optionLength;                                  /**< Option Length **/
    char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];      /**< Optional data values**/
} CAHeaderOption_t;

/**
 * Base Information received.
 *
 * This structure is used to hold request & response base information.
 */
typedef struct
{
    CAMessageType_t type;       /**< Qos for the request */
#ifdef ROUTING_GATEWAY
    bool skipRetransmission;    /**< Will not attempt retransmission even if type is CONFIRM.
                                     Required for packet forwarding */
#endif
    uint16_t messageId;         /**< Message id.
                                 * if message id is zero, it will generated by CA inside.
                                 * otherwise, you can use it */
    CAToken_t token;            /**< Token for CA */
    uint8_t tokenLength;        /**< token length */
    CAHeaderOption_t *options;  /** Header Options for the request */
    uint8_t numOptions;         /**< Number of Header options */
    CAPayload_t payload;        /**< payload of the request  */
    size_t payloadSize;         /**< size in bytes of the payload */
    CAPayloadFormat_t payloadFormat;    /**< encoding format of the request payload */
    CAPayloadFormat_t acceptFormat;     /**< accept format for the response payload */
    CAURI_t resourceUri;        /**< Resource URI information **/
    CARemoteId_t identity;      /**< endpoint identity */
    CADataType_t dataType;      /**< data type */
    CAConnectEvent_t event;     /**< network request message / event type */
} CAInfo_t;

/**
 * Request Information to be sent.
 *
 * This structure is used to hold request information.
 */
typedef struct
{
    CAMethod_t method;  /**< Name of the Method Allowed */
    CAInfo_t info;      /**< Information of the request. */
    bool isMulticast;   /**< is multicast request */
} CARequestInfo_t;

/**
 * Response information received.
 *
 * This structure is used to hold response information.
 */
typedef struct
{
    CAResponseResult_t result;  /**< Result for response by resource model */
    CAInfo_t info;              /**< Information of the response */
    bool isMulticast;
} CAResponseInfo_t;

/**
 * Error information from CA
 *        contains error code and message information.
 *
 * This structure holds error information.
 */
typedef struct
{
    CAResult_t result;  /**< CA API request result  */
    CAInfo_t info;      /**< message information such as token and payload data
                             helpful to identify the error */
} CAErrorInfo_t;

/**
 * Hold global variables for CA layer. (also used by RI layer)
 */
typedef struct
{
    CASocketFd_t fd;    /**< socket fd */
    uint16_t port;      /**< socket port */
} CASocket_t;

#define HISTORYSIZE (4)

typedef struct
{
    CATransportFlags_t flags;
    uint16_t messageId;
    char token[CA_MAX_TOKEN_LEN];
    uint8_t tokenLength;
    uint32_t ifindex;
} CAHistoryItem_t;

typedef struct
{
    int nextIndex;
    CAHistoryItem_t items[HISTORYSIZE];
} CAHistory_t;

/**
 * Hold interface index for keeping track of comings and goings.
 */
typedef struct
{
    int32_t ifIndex; /**< network interface index */
} CAIfItem_t;

/**
 * Hold the port number assigned from application.
 * It will be used when creating a socket.
 */
typedef struct
{
    struct udpports
    {
        uint16_t u6;    /**< unicast IPv6 socket port */
        uint16_t u6s;   /**< unicast IPv6 socket secure port */
        uint16_t u4;    /**< unicast IPv4 socket port */
        uint16_t u4s;   /**< unicast IPv4 socket secure port */
    } udp;
#ifdef TCP_ADAPTER
    struct tcpports
    {
        uint16_t u4;    /**< unicast IPv4 socket port */
        uint16_t u4s;   /**< unicast IPv6 socket secure port */
        uint16_t u6;    /**< unicast IPv6 socket port */
        uint16_t u6s;   /**< unicast IPv6 socket secure port */
    } tcp;
#endif
} CAPorts_t;

typedef struct
{
    CATransportFlags_t clientFlags; /**< flag for client */
    CATransportFlags_t serverFlags; /**< flag for server */
    bool client; /**< client mode */
    bool server; /**< server mode */

    CAPorts_t ports;

    struct sockets
    {
        void *threadpool;           /**< threadpool between Initialize and Start */
        CASocket_t u6;              /**< unicast   IPv6 */
        CASocket_t u6s;             /**< unicast   IPv6 secure */
        CASocket_t u4;              /**< unicast   IPv4 */
        CASocket_t u4s;             /**< unicast   IPv4 secure */
        CASocket_t m6;              /**< multicast IPv6 */
        CASocket_t m6s;             /**< multicast IPv6 secure */
        CASocket_t m4;              /**< multicast IPv4 */
        CASocket_t m4s;             /**< multicast IPv4 secure */
        CASocketFd_t netlinkFd;     /**< netlink */
#if defined(_WIN32)
        WSAEVENT shutdownEvent;     /**< Event used to signal threads to stop */
#else
#ifndef __TIZENRT__
        int shutdownFds[2];         /**< fds used to signal threads to stop */
#endif
#endif
        int selectTimeout;          /**< in seconds */
        bool started;               /**< the IP adapter has started */
        bool terminate;             /**< the IP adapter needs to stop */
        bool ipv6enabled;           /**< IPv6 enabled by OCInit flags */
        bool ipv4enabled;           /**< IPv4 enabled by OCInit flags */
        bool dualstack;             /**< IPv6 and IPv4 enabled */
#if defined (_WIN32)
        LPFN_WSARECVMSG wsaRecvMsg; /**< Win32 function pointer to WSARecvMsg() */
#endif

        struct networkmonitors
        {
            CAIfItem_t *ifItems; /**< current network interface index list */
            size_t sizeIfItems;  /**< size of network interface index array */
            size_t numIfItems;   /**< number of valid network interfaces */
        } nm;
    } ip;

    struct calayer
    {
        CAHistory_t requestHistory;  /**< filter IP family in requests */
    } ca;

#ifdef TCP_ADAPTER
    /**
     * Hold global variables for TCP Adapter.
     */
    struct tcpsockets
    {
        void *threadpool;       /**< threadpool between Initialize and Start */
        CASocket_t ipv4;        /**< IPv4 accept socket */
        CASocket_t ipv4s;       /**< IPv4 accept socket secure */
        CASocket_t ipv6;        /**< IPv6 accept socket */
        CASocket_t ipv6s;       /**< IPv6 accept socket secure */
        void *svrlist;          /**< unicast IPv4 TCP server information*/
        int selectTimeout;      /**< in seconds */
        int listenBacklog;      /**< backlog counts*/
#ifndef __TIZENRT__
        int shutdownFds[2];     /**< shutdown pipe */
#endif
        int connectionFds[2];   /**< connection pipe */
        bool started;           /**< the TCP adapter has started */
        bool terminate;         /**< the TCP adapter needs to stop */
        bool bindenabled;       /**< binding of TCP socket enabled */
        bool ipv4tcpenabled;    /**< IPv4 TCP enabled by OCInit flags */
        bool ipv6tcpenabled;    /**< IPv6 TCP enabled by OCInit flags */
    } tcp;
#endif
    CATransportBTFlags_t bleFlags;
} CAGlobals_t;

extern CAGlobals_t caglobals;

typedef enum
{
    CA_LOG_LEVEL_ALL = 1,             // all logs.
    CA_LOG_LEVEL_INFO,                // debug level is disabled
} CAUtilLogLevel_t;

/**
 * Callback function type for request delivery.
 * @param[out]   object       Endpoint object from which the request is received.
 *                            It contains endpoint address based on the connectivity type.
 * @param[out]   requestInfo  Info for resource model to understand about the request.
 */
typedef void (*CARequestCallback)(const CAEndpoint_t *object,
                                  const CARequestInfo_t *requestInfo);

/**
 * Callback function type for response delivery.
 * @param[out]   object           Endpoint object from which the response is received.
 * @param[out]   responseInfo     Identifier which needs to be mapped with response.
 */
typedef void (*CAResponseCallback)(const CAEndpoint_t *object,
                                   const CAResponseInfo_t *responseInfo);
/**
 * Callback function type for error.
 * @param[out]   object           remote device information.
 * @param[out]   errorInfo        CA Error information.
 */
typedef void (*CAErrorCallback)(const CAEndpoint_t *object,
                                const CAErrorInfo_t *errorInfo);

/**
 * Callback function type for network status changes delivery from CA common logic.
 * @param[out]   info       Endpoint object from which the network status is changed.
 *                          It contains endpoint address based on the connectivity type.
 * @param[out]   status     Current network status info.
 */
typedef void (*CANetworkMonitorCallback)(const CAEndpoint_t *info, CANetworkStatus_t status);

/**
 * Callback function type for editing bluetooth advertisement data before starting bluetooth advertisement.
 * param[in]   max_data_size    Maximal size of advertisement data array
 * param[out]  data             Advertisement data array
 * param[out]  data_size        Actual Data size of advertisement data array
 */
typedef void (*CAAdvertisementDataGetterCB)(int max_data_size, char *data, int *data_size);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif // CA_COMMON_H_