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