1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 * This file contains the common data structures between Resource , CA and adapters
42 #define CA_IPADDR_SIZE 16
45 * Remote Access jabber ID length.
47 #define CA_RAJABBERID_SIZE 256
50 * Mac address length for BT port
52 #define CA_MACADDR_SIZE 18
55 * Max header options data length
57 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
62 #define CA_MAX_TOKEN_LEN (8)
68 #define CA_MAX_URI_LENGTH 128 /* maximum size of URI for embedded platforms*/
70 #define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/
74 * Max PDU length supported
77 #define COAP_MAX_PDU_SIZE 320 /* maximum size of a CoAP PDU for embedded platforms*/
79 #define COAP_MAX_PDU_SIZE 1400 /* maximum size of a CoAP PDU for big platforms*/
83 #define COAP_TCP_MAX_PDU_SIZE 64 * 1024 /* maximum size of a CoAP over TCP PDU for Linux platform*/
87 #define CA_DEFAULT_BLOCK_SIZE CA_BLOCK_SIZE_1024_BYTE
91 *Maximum length of the remoteEndpoint identity
93 #define CA_MAX_ENDPOINT_IDENTITY_LEN (32)
96 * option types - the highest option number 63
98 #define CA_OPTION_IF_MATCH 1
99 #define CA_OPTION_ETAG 4
100 #define CA_OPTION_IF_NONE_MATCH 5
101 #define CA_OPTION_OBSERVE 6
102 #define CA_OPTION_LOCATION_PATH 8
103 #define CA_OPTION_URI_PATH 11
104 #define CA_OPTION_CONTENT_FORMAT 12
105 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
106 #define CA_OPTION_MAXAGE 14
107 #define CA_OPTION_URI_QUERY 15
108 #define CA_OPTION_ACCEPT 17
109 #define CA_OPTION_LOCATION_QUERY 20
112 * Payload information from resource model
114 typedef uint8_t *CAPayload_t;
117 * URI for the OIC base.CA considers relative URI as the URI.
119 typedef char *CAURI_t;
122 * Token information for mapping the request and responses by resource model
124 typedef char *CAToken_t;
126 // The following flags are the same as the equivalent OIC values in
127 // octypes.h, allowing direct copying with slight fixup.
128 // The CA layer should used the OC types when build allows that.
130 #define MAX_ADDR_STR_SIZE_CA (256)
132 #define MAX_ADDR_STR_SIZE_CA (40)
137 CA_DEFAULT_ADAPTER = 0,
139 // value zero indicates discovery
140 CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
141 CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
142 CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
145 CA_ADAPTER_REMOTE_ACCESS = (1 << 3), // Remote Access over XMPP.
149 CA_ADAPTER_CLOUD_INTERFACE = (1 << 5), // CoAP over TCP for Cloud Interface
152 CA_ALL_ADAPTERS = 0xffffffff
153 } CATransportAdapter_t;
157 CA_DEFAULT_FLAGS = 0,
159 // Insecure transport is the default (subject to change)
160 CA_SECURE = (1 << 4), // secure the transport path
161 // IPv4 & IPv6 autoselection is the default
162 CA_IPV6 = (1 << 5), // IP adapter only
163 CA_IPV4 = (1 << 6), // IP adapter only
164 // Indication that a message was received by multicast.
165 CA_MULTICAST = (1 << 7),
167 // A TCP transport for the CoAP
168 CA_IPV4_TCP = (1 << 8),
170 // Link-Local multicast is the default multicast scope for IPv6.
171 // These correspond in both value and position to the IPv6 address bits.
172 CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
173 CA_SCOPE_LINK = 0x2, // IPv6 Link-Local scope (default)
174 CA_SCOPE_REALM = 0x3, // IPv6 Realm-Local scope
175 CA_SCOPE_ADMIN = 0x4, // IPv6 Admin-Local scope
176 CA_SCOPE_SITE = 0x5, // IPv6 Site-Local scope
177 CA_SCOPE_ORG = 0x8, // IPv6 Organization-Local scope
178 CA_SCOPE_GLOBAL = 0xE, // IPv6 Global scope
179 } CATransportFlags_t;
181 #define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
182 #define CA_SCOPE_MASK 0xf // mask scope bits above
185 * @enum CANetworkStatus_t
186 * Information about the network status.
190 CA_INTERFACE_DOWN, /**< Connection is not available */
191 CA_INTERFACE_UP /**< Connection is Available */
195 * remoteEndpoint identity
200 unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
204 * @enum CAMessageType_t
205 * Message Type for Base source code
209 CA_MSG_CONFIRM = 0, /**< confirmable message (requires ACK/RST) */
210 CA_MSG_NONCONFIRM, /**< non-confirmable message (one-shot message) */
211 CA_MSG_ACKNOWLEDGE, /**< used to acknowledge confirmable messages */
212 CA_MSG_RESET /**< used to indicates not-interested or error (lack of context)in
218 * Allowed method to be used by resource model
222 CA_GET = 1, /**< GET Method */
223 CA_POST, /**< POST Method */
224 CA_PUT, /**< PUT Method */
225 CA_DELETE /**< DELETE Method */
230 * it depends on defined size in libCoAP.
234 CA_BLOCK_SIZE_16_BYTE = 0, /**< 16byte */
235 CA_BLOCK_SIZE_32_BYTE = 1, /**< 32byte */
236 CA_BLOCK_SIZE_64_BYTE = 2, /**< 64byte */
237 CA_BLOCK_SIZE_128_BYTE = 3, /**< 128byte */
238 CA_BLOCK_SIZE_256_BYTE = 4, /**< 256byte */
239 CA_BLOCK_SIZE_512_BYTE = 5, /**< 512byte */
240 CA_BLOCK_SIZE_1024_BYTE = 6 /**< 1Kbyte */
244 * Endpoint information for connectivities
245 * Must be identical to OCDevAddr.
249 CATransportAdapter_t adapter; // adapter type
250 CATransportFlags_t flags; // transport modifiers
251 uint16_t port; // for IP
252 char addr[MAX_ADDR_STR_SIZE_CA]; // address for all
253 uint32_t interface; // usually zero for default interface
257 * Endpoint information for secure messages
261 CAEndpoint_t endpoint; /**< endpoint */
262 CARemoteId_t identity; /**< endpoint identity */
263 } CASecureEndpoint_t;
267 * Enums for CA return values
271 /* Result code - START HERE */
272 CA_STATUS_OK = 0, /**< Success */
273 CA_STATUS_INVALID_PARAM, /**< Invalid Parameter */
274 CA_ADAPTER_NOT_ENABLED, /**< Adapter is not enabled */
275 CA_SERVER_STARTED_ALREADY, /**< Server is started already */
276 CA_SERVER_NOT_STARTED, /**< Server is not started*/
277 CA_DESTINATION_NOT_REACHABLE, /**< Destination is not reachable */
278 CA_SOCKET_OPERATION_FAILED, /**< Socket operation failed */
279 CA_SEND_FAILED, /**< Send request failed */
280 CA_RECEIVE_FAILED, /**< Receive failed */
281 CA_MEMORY_ALLOC_FAILED, /**< Memory allocation failed */
282 CA_REQUEST_TIMEOUT, /**< Request is Timeout */
283 CA_DESTINATION_DISCONNECTED, /**< Destination is disconnected */
284 CA_NOT_SUPPORTED, /**< Not supported */
285 CA_STATUS_NOT_INITIALIZED, /**< Not Initialized*/
286 CA_STATUS_FAILED =255 /**< Failure */
287 /* Result code - END HERE */
291 * @enum CAResponseResult_t
292 * Enums for CA Response values
296 /* Response status code - START HERE */
297 CA_EMPTY = 0, /**< Empty */
298 CA_SUCCESS = 200, /**< Success */
299 CA_CREATED = 201, /**< Created */
300 CA_DELETED = 202, /**< Deleted */
301 CA_VALID = 203, /**< Valid */
302 CA_CHANGED = 204, /**< Changed */
303 CA_CONTENT = 205, /**< Content */
304 CA_CONTINUE = 231, /**< Continue */
305 CA_BAD_REQ = 400, /**< Bad Request */
306 CA_UNAUTHORIZED_REQ = 401, /**< Unauthorized Request */
307 CA_BAD_OPT = 402, /**< Bad Option */
308 CA_FORBIDDEN_REQ = 403, /**< Forbidden Request */
309 CA_NOT_FOUND = 404, /**< Not found */
310 CA_REQUEST_ENTITY_INCOMPLETE = 408, /**< Request Entity Incomplete */
311 CA_REQUEST_ENTITY_TOO_LARGE = 413, /**< Request Entity Too Large */
312 CA_INTERNAL_SERVER_ERROR = 500, /**< Internal Server Error */
313 CA_RETRANSMIT_TIMEOUT = 504 /**< Retransmit timeout */
314 /* Response status code - END HERE */
315 } CAResponseResult_t;
318 * @enum CATransportProtocolID_t
319 * Transport Protocol IDs for additional options
323 CA_INVALID_ID = (1 << 0), /**< Invalid ID */
324 CA_COAP_ID = (1 << 1) /**< COAP ID */
325 } CATransportProtocolID_t;
328 * @enum CAAdapterState_t
329 * Adapter State to indicate the network changed notifications.
333 CA_ADAPTER_DISABLED, /**< Adapter is Disabled */
334 CA_ADAPTER_ENABLED /**< Adapter is Enabled */
338 * Header options structure to be filled
340 * This structure is used to hold header information.
344 CATransportProtocolID_t protocolID; /**< Protocol ID of the Option */
345 uint16_t optionID; /**< The header option ID which will be
346 added to communication packets */
347 uint16_t optionLength; /**< Option Length **/
348 char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH]; /**< Optional data values**/
352 * Base Information received
354 * This structure is used to hold request & response base information
359 CAMessageType_t type; /**< Qos for the request */
360 uint16_t messageId; /**< Message id.
361 * if message id is zero, it will generated by CA inside.
362 * otherwise, you can use it */
363 CAToken_t token; /**< Token for CA */
364 uint8_t tokenLength; /**< token length*/
365 CAHeaderOption_t *options; /** Header Options for the request */
366 uint8_t numOptions; /**< Number of Header options */
367 CAPayload_t payload; /**< payload of the request */
368 size_t payloadSize; /**< size in bytes of the payload */
369 CAURI_t resourceUri; /**< Resource URI information **/
370 CARemoteId_t identity; /**< endpoint identity */
374 * Request Information to be sent
376 * This structure is used to hold request information
380 CAMethod_t method; /**< Name of the Method Allowed */
381 CAInfo_t info; /**< Information of the request. */
382 bool isMulticast; /**< is multicast request */
386 * Response information received
388 * This structure is used to hold response information
392 CAResponseResult_t result; /**< Result for response by resource model */
393 CAInfo_t info; /**< Information of the response */
398 * Error information from CA
399 * contains error code and message information
401 * This structure holds error information
405 CAResult_t result; /**< CA API request result */
406 CAInfo_t info; /**< message information such as token and payload data
407 helpful to identify the error */
411 * CA Remote Access information for XMPP Client
416 char *hostname; /**< XMPP server hostname */
417 uint16_t port; /**< XMPP server serivce port */
418 char *xmpp_domain; /**< XMPP login domain */
419 char *username; /**< login username */
420 char *password; /**< login password */
421 char *resource; /**< specific resource for login */
422 char *user_jid; /**< specific JID for login */
427 * Hold global variables for CA layer (also used by RI layer)
431 int fd; /**< socket fd */
432 uint16_t port; /**< socket port */
435 #define HISTORYSIZE (4)
439 CATransportFlags_t flags;
446 CAHistoryItem_t items[HISTORYSIZE];
450 * Hold interface index for keeping track of comings and goings
454 int32_t ifIndex; /**< network interface index */
459 * CI Server Information for IPv4 TCP transport
463 char addr[MAX_ADDR_STR_SIZE_CA]; /**< CI Server address */
464 CASocket_t u4tcp; /**< CI Server port */
470 CATransportFlags_t clientFlags; /**< flag for client */
471 CATransportFlags_t serverFlags; /**< flag for server */
472 bool client; /**< client mode */
473 bool server; /**< server mode */
477 void *threadpool; /**< threadpool between Initialize and Start */
478 CASocket_t u6; /**< unicast IPv6 */
479 CASocket_t u6s; /**< unicast IPv6 secure */
480 CASocket_t u4; /**< unicast IPv4 */
481 CASocket_t u4s; /**< unicast IPv4 secure */
482 CASocket_t m6; /**< multicast IPv6 */
483 CASocket_t m6s; /**< multicast IPv6 secure */
484 CASocket_t m4; /**< multicast IPv4 */
485 CASocket_t m4s; /**< multicast IPv4 secure */
486 int netlinkFd; /**< netlink */
487 int shutdownFds[2]; /**< shutdown pipe */
488 int selectTimeout; /**< in seconds */
489 int maxfd; /**< highest fd (for select) */
490 bool started; /**< the IP adapter has started */
491 bool terminate; /**< the IP adapter needs to stop */
492 bool ipv6enabled; /**< IPv6 enabled by OCInit flags */
493 bool ipv4enabled; /**< IPv4 enabled by OCInit flags */
494 bool dualstack; /**< IPv6 and IPv4 enabled */
496 struct networkmonitors
498 CAIfItem_t *ifItems; /**< current network interface index list */
499 size_t sizeIfItems; /**< size of network interface index array */
500 size_t numIfItems; /**< number of valid network interfaces */
506 CAHistory_t requestHistory; /**< filter IP family in requests */
507 CAHistory_t responseHistory; /**< filter IP family in responses */
508 CATransportFlags_t previousRequestFlags;/**< address family filtering */
509 uint16_t previousRequestMessageId; /**< address family filtering */
514 * Hold global variables for CI Adapter.
518 void *threadpool; /**< threadpool between Initialize and Start */
519 void *svrlist; /**< unicast IPv4 CI server information*/
520 int selectTimeout; /**< in seconds */
521 int maxfd; /**< highest fd (for select) */
522 bool started; /**< the CI adapter has started */
523 bool terminate; /**< the CI adapter needs to stop */
524 bool ipv4tcpenabled; /**< IPv4 TCP enabled by OCInit flags */
529 extern CAGlobals_t caglobals;
535 #endif // CA_COMMON_H_