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 20
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 CA_DEFAULT_BLOCK_SIZE CA_BLOCK_SIZE_1024_BYTE
87 *Maximum length of the remoteEndpoint identity
89 #define CA_MAX_ENDPOINT_IDENTITY_LEN (32)
92 * option types - the highest option number 63
94 #define CA_OPTION_IF_MATCH 1
95 #define CA_OPTION_ETAG 4
96 #define CA_OPTION_IF_NONE_MATCH 5
97 #define CA_OPTION_OBSERVE 6
98 #define CA_OPTION_LOCATION_PATH 8
99 #define CA_OPTION_URI_PATH 11
100 #define CA_OPTION_CONTENT_FORMAT 12
101 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
102 #define CA_OPTION_MAXAGE 14
103 #define CA_OPTION_URI_QUERY 15
104 #define CA_OPTION_ACCEPT 17
105 #define CA_OPTION_LOCATION_QUERY 20
108 * Payload information from resource model
110 typedef uint8_t *CAPayload_t;
113 * URI for the OIC base.CA considers relative URI as the URI.
115 typedef char *CAURI_t;
118 * Token information for mapping the request and responses by resource model
120 typedef char *CAToken_t;
122 // The following flags are the same as the equivalent OIC values in
123 // octypes.h, allowing direct copying with slight fixup.
124 // The CA layer should used the OC types when build allows that.
126 #define MAX_ADDR_STR_SIZE_CA (256)
128 #define MAX_ADDR_STR_SIZE_CA (40)
133 CA_DEFAULT_ADAPTER = 0,
135 // value zero indicates discovery
136 CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
137 CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
138 CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
141 CA_ADAPTER_REMOTE_ACCESS = (1 << 3), // Remote Access over XMPP.
144 CA_ADAPTER_TCP = (1 << 4), // CoAP over TCP
145 CA_ALL_ADAPTERS = 0xffffffff
146 } CATransportAdapter_t;
150 CA_DEFAULT_FLAGS = 0,
152 // Insecure transport is the default (subject to change)
153 CA_SECURE = (1 << 4), // secure the transport path
154 // IPv4 & IPv6 autoselection is the default
155 CA_IPV6 = (1 << 5), // IP adapter only
156 CA_IPV4 = (1 << 6), // IP adapter only
157 // Indication that a message was received by multicast.
158 CA_MULTICAST = (1 << 7),
159 // Link-Local multicast is the default multicast scope for IPv6.
160 // These correspond in both value and position to the IPv6 address bits.
161 CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
162 CA_SCOPE_LINK = 0x2, // IPv6 Link-Local scope (default)
163 CA_SCOPE_REALM = 0x3, // IPv6 Realm-Local scope
164 CA_SCOPE_ADMIN = 0x4, // IPv6 Admin-Local scope
165 CA_SCOPE_SITE = 0x5, // IPv6 Site-Local scope
166 CA_SCOPE_ORG = 0x8, // IPv6 Organization-Local scope
167 CA_SCOPE_GLOBAL = 0xE, // IPv6 Global scope
168 } CATransportFlags_t;
170 #define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
171 #define CA_SCOPE_MASK 0xf // mask scope bits above
174 * @enum CANetworkStatus_t
175 * Information about the network status.
179 CA_INTERFACE_DOWN, /**< Connection is not available */
180 CA_INTERFACE_UP /**< Connection is Available */
184 * remoteEndpoint identity
189 unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
193 * @enum CAMessageType_t
194 * Message Type for Base source code
198 CA_MSG_CONFIRM = 0, /**< confirmable message (requires ACK/RST) */
199 CA_MSG_NONCONFIRM, /**< non-confirmable message (one-shot message) */
200 CA_MSG_ACKNOWLEDGE, /**< used to acknowledge confirmable messages */
201 CA_MSG_RESET /**< used to indicates not-interested or error (lack of context)in
207 * Allowed method to be used by resource model
211 CA_GET = 1, /**< GET Method */
212 CA_POST, /**< POST Method */
213 CA_PUT, /**< PUT Method */
214 CA_DELETE /**< DELETE Method */
219 * it depends on defined size in libCoAP.
223 CA_BLOCK_SIZE_16_BYTE = 0, /**< 16byte */
224 CA_BLOCK_SIZE_32_BYTE = 1, /**< 32byte */
225 CA_BLOCK_SIZE_64_BYTE = 2, /**< 64byte */
226 CA_BLOCK_SIZE_128_BYTE = 3, /**< 128byte */
227 CA_BLOCK_SIZE_256_BYTE = 4, /**< 256byte */
228 CA_BLOCK_SIZE_512_BYTE = 5, /**< 512byte */
229 CA_BLOCK_SIZE_1024_BYTE = 6 /**< 1Kbyte */
233 * Endpoint information for connectivities
234 * Must be identical to OCDevAddr.
238 CATransportAdapter_t adapter; // adapter type
239 CATransportFlags_t flags; // transport modifiers
240 uint16_t port; // for IP
241 char addr[MAX_ADDR_STR_SIZE_CA]; // address for all
242 uint32_t interface; // usually zero for default interface
243 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
244 char routeData[MAX_ADDR_STR_SIZE_CA]; /**< GatewayId:ClientId of
250 * Endpoint information for secure messages
254 CAEndpoint_t endpoint; /**< endpoint */
255 CARemoteId_t identity; /**< endpoint identity */
256 } CASecureEndpoint_t;
260 * Enums for CA return values
264 /* Result code - START HERE */
265 CA_STATUS_OK = 0, /**< Success */
266 CA_STATUS_INVALID_PARAM, /**< Invalid Parameter */
267 CA_ADAPTER_NOT_ENABLED, /**< Adapter is not enabled */
268 CA_SERVER_STARTED_ALREADY, /**< Server is started already */
269 CA_SERVER_NOT_STARTED, /**< Server is not started*/
270 CA_DESTINATION_NOT_REACHABLE, /**< Destination is not reachable */
271 CA_SOCKET_OPERATION_FAILED, /**< Socket operation failed */
272 CA_SEND_FAILED, /**< Send request failed */
273 CA_RECEIVE_FAILED, /**< Receive failed */
274 CA_MEMORY_ALLOC_FAILED, /**< Memory allocation failed */
275 CA_REQUEST_TIMEOUT, /**< Request is Timeout */
276 CA_DESTINATION_DISCONNECTED, /**< Destination is disconnected */
277 CA_NOT_SUPPORTED, /**< Not supported */
278 CA_STATUS_NOT_INITIALIZED, /**< Not Initialized*/
279 CA_STATUS_FAILED =255 /**< Failure */
280 /* Result code - END HERE */
284 * @enum CAResponseResult_t
285 * Enums for CA Response values
289 /* Response status code - START HERE */
290 CA_EMPTY = 0, /**< Empty */
291 CA_CREATED = 201, /**< Created */
292 CA_DELETED = 202, /**< Deleted */
293 CA_VALID = 203, /**< Valid */
294 CA_CHANGED = 204, /**< Changed */
295 CA_CONTENT = 205, /**< Content */
296 CA_CONTINUE = 231, /**< Continue */
297 CA_BAD_REQ = 400, /**< Bad Request */
298 CA_UNAUTHORIZED_REQ = 401, /**< Unauthorized Request */
299 CA_BAD_OPT = 402, /**< Bad Option */
300 CA_FORBIDDEN_REQ = 403, /**< Forbidden Request */
301 CA_NOT_FOUND = 404, /**< Not found */
302 CA_NOT_ACCEPTABLE = 406, /**< Not Acceptable */
303 CA_REQUEST_ENTITY_INCOMPLETE = 408, /**< Request Entity Incomplete */
304 CA_REQUEST_ENTITY_TOO_LARGE = 413, /**< Request Entity Too Large */
305 CA_INTERNAL_SERVER_ERROR = 500, /**< Internal Server Error */
306 CA_RETRANSMIT_TIMEOUT = 504 /**< Retransmit timeout */
307 /* Response status code - END HERE */
308 } CAResponseResult_t;
311 * @enum CATransportProtocolID_t
312 * Transport Protocol IDs for additional options
316 CA_INVALID_ID = (1 << 0), /**< Invalid ID */
317 CA_COAP_ID = (1 << 1) /**< COAP ID */
318 } CATransportProtocolID_t;
321 * @enum CAAdapterState_t
322 * Adapter State to indicate the network changed notifications.
326 CA_ADAPTER_DISABLED, /**< Adapter is Disabled */
327 CA_ADAPTER_ENABLED /**< Adapter is Enabled */
331 * Format indicating which encoding has been used on the payload.
335 CA_FORMAT_UNDEFINED = 0, /**< Undefined enoding format */
336 CA_FORMAT_TEXT_PLAIN,
337 CA_FORMAT_APPLICATION_LINK_FORMAT,
338 CA_FORMAT_APPLICATION_XML,
339 CA_FORMAT_APPLICATION_OCTET_STREAM,
340 CA_FORMAT_APPLICATION_RDF_XML,
341 CA_FORMAT_APPLICATION_EXI,
342 CA_FORMAT_APPLICATION_JSON,
343 CA_FORMAT_APPLICATION_CBOR,
344 CA_FORMAT_UNSUPPORTED
348 * Header options structure to be filled
350 * This structure is used to hold header information.
354 CATransportProtocolID_t protocolID; /**< Protocol ID of the Option */
355 uint16_t optionID; /**< The header option ID which will be
356 added to communication packets */
357 uint16_t optionLength; /**< Option Length **/
358 char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH]; /**< Optional data values**/
362 * Base Information received
364 * This structure is used to hold request & response base information
369 CAMessageType_t type; /**< Qos for the request */
370 #ifdef ROUTING_GATEWAY
371 bool skipRetransmission; /**< Will not attempt retransmission even if type is CONFIRM.
372 Required for packet forwarding */
374 uint16_t messageId; /**< Message id.
375 * if message id is zero, it will generated by CA inside.
376 * otherwise, you can use it */
377 CAToken_t token; /**< Token for CA */
378 uint8_t tokenLength; /**< token length*/
379 CAHeaderOption_t *options; /** Header Options for the request */
380 uint8_t numOptions; /**< Number of Header options */
381 CAPayload_t payload; /**< payload of the request */
382 size_t payloadSize; /**< size in bytes of the payload */
383 CAPayloadFormat_t payloadFormat; /**< encoding format of the request payload */
384 CAPayloadFormat_t acceptFormat; /**< accept format for the response payload */
385 CAURI_t resourceUri; /**< Resource URI information **/
386 CARemoteId_t identity; /**< endpoint identity */
390 * Request Information to be sent
392 * This structure is used to hold request information
396 CAMethod_t method; /**< Name of the Method Allowed */
397 CAInfo_t info; /**< Information of the request. */
398 bool isMulticast; /**< is multicast request */
402 * Response information received
404 * This structure is used to hold response information
408 CAResponseResult_t result; /**< Result for response by resource model */
409 CAInfo_t info; /**< Information of the response */
414 * Error information from CA
415 * contains error code and message information
417 * This structure holds error information
421 CAResult_t result; /**< CA API request result */
422 CAInfo_t info; /**< message information such as token and payload data
423 helpful to identify the error */
427 * CA Remote Access information for XMPP Client
432 char *hostname; /**< XMPP server hostname */
433 uint16_t port; /**< XMPP server serivce port */
434 char *xmpp_domain; /**< XMPP login domain */
435 char *username; /**< login username */
436 char *password; /**< login password */
437 char *resource; /**< specific resource for login */
438 char *user_jid; /**< specific JID for login */
443 * Hold global variables for CA layer (also used by RI layer)
447 int fd; /**< socket fd */
448 uint16_t port; /**< socket port */
451 #define HISTORYSIZE (4)
455 CATransportFlags_t flags;
457 char token[CA_MAX_TOKEN_LEN];
464 CAHistoryItem_t items[HISTORYSIZE];
468 * Hold interface index for keeping track of comings and goings
472 int32_t ifIndex; /**< network interface index */
477 CATransportFlags_t clientFlags; /**< flag for client */
478 CATransportFlags_t serverFlags; /**< flag for server */
479 bool client; /**< client mode */
480 bool server; /**< server mode */
484 void *threadpool; /**< threadpool between Initialize and Start */
485 CASocket_t u6; /**< unicast IPv6 */
486 CASocket_t u6s; /**< unicast IPv6 secure */
487 CASocket_t u4; /**< unicast IPv4 */
488 CASocket_t u4s; /**< unicast IPv4 secure */
489 CASocket_t m6; /**< multicast IPv6 */
490 CASocket_t m6s; /**< multicast IPv6 secure */
491 CASocket_t m4; /**< multicast IPv4 */
492 CASocket_t m4s; /**< multicast IPv4 secure */
493 int netlinkFd; /**< netlink */
494 int shutdownFds[2]; /**< shutdown pipe */
495 int selectTimeout; /**< in seconds */
496 int maxfd; /**< highest fd (for select) */
497 bool started; /**< the IP adapter has started */
498 bool terminate; /**< the IP adapter needs to stop */
499 bool ipv6enabled; /**< IPv6 enabled by OCInit flags */
500 bool ipv4enabled; /**< IPv4 enabled by OCInit flags */
501 bool dualstack; /**< IPv6 and IPv4 enabled */
503 struct networkmonitors
505 CAIfItem_t *ifItems; /**< current network interface index list */
506 size_t sizeIfItems; /**< size of network interface index array */
507 size_t numIfItems; /**< number of valid network interfaces */
513 CAHistory_t requestHistory; /**< filter IP family in requests */
514 CAHistory_t responseHistory; /**< filter IP family in responses */
515 CATransportFlags_t previousRequestFlags;/**< address family filtering */
516 uint16_t previousRequestMessageId; /**< address family filtering */
521 * Hold global variables for TCP Adapter.
525 void *threadpool; /**< threadpool between Initialize and Start */
526 void *svrlist; /**< unicast IPv4 TCP server information*/
527 int selectTimeout; /**< in seconds */
528 int listenBacklog; /**< backlog counts*/
529 int maxfd; /**< highest fd (for select) */
530 bool started; /**< the TCP adapter has started */
531 bool terminate; /**< the TCP adapter needs to stop */
532 bool ipv4tcpenabled; /**< IPv4 TCP enabled by OCInit flags */
537 extern CAGlobals_t caglobals;
543 #endif // CA_COMMON_H_