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 * @brief This file contains the common data structures between Resource , CA and adapters
40 * @brief IP address Length
42 #define CA_IPADDR_SIZE 16
45 * @brief Remote Access jabber ID length.
47 #define CA_RAJABBERID_SIZE 256
50 * @brief Mac address length for BT port
52 #define CA_MACADDR_SIZE 18
55 * @brief Max header options data length
57 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
60 * @brief Max token length
62 #define CA_MAX_TOKEN_LEN (8)
65 * @brief Max URI length
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 * @brief 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 *@brief Maximum length of the remoteEndpoint identity
85 #define CA_MAX_ENDPOINT_IDENTITY_LEN (32)
88 * @brief option types - the highest option number 63
90 #define CA_OPTION_IF_MATCH 1
91 #define CA_OPTION_ETAG 4
92 #define CA_OPTION_IF_NONE_MATCH 5
93 #define CA_OPTION_OBSERVE 6
94 #define CA_OPTION_LOCATION_PATH 8
95 #define CA_OPTION_URI_PATH 11
96 #define CA_OPTION_CONTENT_FORMAT 12
97 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
98 #define CA_OPTION_MAXAGE 14
99 #define CA_OPTION_URI_QUERY 15
100 #define CA_OPTION_ACCEPT 17
101 #define CA_OPTION_LOCATION_QUERY 20
104 * @brief Payload information from resource model
106 typedef uint8_t *CAPayload_t;
109 * @brief URI for the OIC base.CA considers relative URI as the URI.
111 typedef char *CAURI_t;
114 * @brief Token information for mapping the request and responses by resource model
116 typedef char *CAToken_t;
118 // The following flags are the same as the equivalent OIC values in
119 // octypes.h, allowing direct copying with slight fixup.
120 // The CA layer should used the OC types when build allows that.
122 #define MAX_ADDR_STR_SIZE_CA (256)
124 #define MAX_ADDR_STR_SIZE_CA (40)
129 CA_DEFAULT_ADAPTER = 0,
131 // value zero indicates discovery
132 CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
133 CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
134 CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
137 CA_ADAPTER_REMOTE_ACCESS = (1 << 3) // Remote Access over XMPP.
139 } CATransportAdapter_t;
143 CA_DEFAULT_FLAGS = 0,
145 // Insecure transport is the default (subject to change)
146 CA_SECURE = (1 << 4), // secure the transport path
147 // IPv4 & IPv6 autoselection is the default
148 CA_IPV6 = (1 << 5), // IP adapter only
149 CA_IPV4 = (1 << 6), // IP adapter only
150 // Indication that a message was received by multicast.
151 CA_MULTICAST = (1 << 7),
152 // Link-Local multicast is the default multicast scope for IPv6.
153 // These correspond in both value and position to the IPv6 address bits.
154 CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
155 CA_SCOPE_LINK = 0x2, // IPv6 Link-Local scope (default)
156 CA_SCOPE_REALM = 0x3, // IPv6 Realm-Local scope
157 CA_SCOPE_ADMIN = 0x4, // IPv6 Admin-Local scope
158 CA_SCOPE_SITE = 0x5, // IPv6 Site-Local scope
159 CA_SCOPE_ORG = 0x8, // IPv6 Organization-Local scope
160 CA_SCOPE_GLOBAL = 0xE, // IPv6 Global scope
161 } CATransportFlags_t;
163 #define CA_IPFAMILY_MASK (CA_IPV6|CA_IPV4)
164 #define CA_SCOPE_MASK 0xf // mask scope bits above
167 * @enum CANetworkStatus_t
168 * @brief Information about the network status.
172 CA_INTERFACE_DOWN, /**< Connection is not available */
173 CA_INTERFACE_UP /**< Connection is Available */
177 * @brief remoteEndpoint identity
182 unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
186 * @enum CAMessageType_t
187 * @brief Message Type for Base source code
191 CA_MSG_CONFIRM = 0, /**< confirmable message (requires ACK/RST) */
192 CA_MSG_NONCONFIRM, /**< non-confirmable message (one-shot message) */
193 CA_MSG_ACKNOWLEDGE, /**< used to acknowledge confirmable messages */
194 CA_MSG_RESET /**< used to indicates not-interested or error (lack of context)in
200 * @brief Allowed method to be used by resource model
204 CA_GET = 1, /**< GET Method */
205 CA_POST, /**< POST Method */
206 CA_PUT, /**< PUT Method */
207 CA_DELETE /**< DELETE Method */
211 * @brief Endpoint information for connectivities
212 * Must be identical to OCDevAddr.
216 CATransportAdapter_t adapter; // adapter type
217 CATransportFlags_t flags; // transport modifiers
218 char addr[MAX_ADDR_STR_SIZE_CA]; // address for all
219 uint32_t interface; // usually zero for default interface
220 uint16_t port; // for IP
221 CARemoteId_t identity; // endpoint identity
226 * @brief Enums for CA return values
230 // Result code - START HERE
231 CA_STATUS_OK = 0, /**< Success */
232 CA_STATUS_INVALID_PARAM, /**< Invalid Parameter */
233 CA_ADAPTER_NOT_ENABLED, /**< Adapter is not enabled */
234 CA_SERVER_STARTED_ALREADY, /**< Server is started already */
235 CA_SERVER_NOT_STARTED, /**< Server is not started*/
236 CA_DESTINATION_NOT_REACHABLE, /**< Destination is not reachable */
237 CA_SOCKET_OPERATION_FAILED, /**< Socket operation failed */
238 CA_SEND_FAILED, /**< Send request failed */
239 CA_RECEIVE_FAILED, /**< Receive failed */
240 CA_MEMORY_ALLOC_FAILED, /**< Memory allocation failed */
241 CA_REQUEST_TIMEOUT, /**< Request is Timeout */
242 CA_DESTINATION_DISCONNECTED, /**< Destination is disconnected */
243 CA_NOT_SUPPORTED, /**< Not supported */
244 CA_STATUS_NOT_INITIALIZED, /**< CA layer is not initialized */
245 CA_STATUS_FAILED =255 /**< Failure */
246 /* Result code - END HERE */
250 * @enum CAResponseResult_t
251 * @brief Enums for CA Response values
255 /* Response status code - START HERE */
256 CA_EMPTY = 0, /**< Empty */
257 CA_SUCCESS = 200, /**< Success */
258 CA_CREATED = 201, /**< Created */
259 CA_DELETED = 202, /**< Deleted */
260 CA_VALID = 203, /**< Valid */
261 CA_CHANGED = 204, /**< Changed */
262 CA_CONTENT = 205, /**< Content */
263 CA_BAD_REQ = 400, /**< Bad Request */
264 CA_UNAUTHORIZED_REQ = 401, /**< Unauthorized Request */
265 CA_BAD_OPT = 402, /**< Bad Option */
266 CA_FORBIDDEN_REQ = 403, /**< Forbidden Request */
267 CA_NOT_FOUND = 404, /**< Not found */
268 CA_INTERNAL_SERVER_ERROR = 500, /**< Internal Server Error */
269 CA_RETRANSMIT_TIMEOUT = 504 /**< Retransmit timeout */
270 /* Response status code - END HERE */
271 } CAResponseResult_t;
274 * @enum CATransportProtocolID_t
275 * @brief Transport Protocol IDs for additional options
279 CA_INVALID_ID = (1 << 0), /**< Invalid ID */
280 CA_COAP_ID = (1 << 1) /**< COAP ID */
281 } CATransportProtocolID_t;
284 * @enum CAAdapterState_t
285 * @brief Adapter State to indicate the network changed notifications.
289 CA_ADAPTER_DISABLED, /**< Adapter is Disabled */
290 CA_ADAPTER_ENABLED /**< Adapter is Enabled */
294 * @brief Header options structure to be filled
296 * This structure is used to hold header information.
300 CATransportProtocolID_t protocolID; /**< Protocol ID of the Option */
301 uint16_t optionID; /**< The header option ID which will be
302 added to communication packets */
303 uint16_t optionLength; /**< Option Length **/
304 char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH]; /**< Optional data values**/
308 * @brief Base Information received
310 * This structure is used to hold request & response base information
315 CAMessageType_t type; /**< Qos for the request */
316 uint16_t messageId; /**< Message id.
317 * if message id is zero, it will generated by CA inside.
318 * otherwise, you can use it */
319 CAToken_t token; /**< Token for CA */
320 uint8_t tokenLength; /**< token length*/
321 CAHeaderOption_t *options; /** Header Options for the request */
322 uint8_t numOptions; /**< Number of Header options */
323 CAPayload_t payload; /**< payload of the request */
324 size_t payloadSize; /**< size in bytes of the payload */
325 CAURI_t resourceUri; /**< Resource URI information **/
329 * @brief Request Information to be sent
331 * This structure is used to hold request information
335 CAMethod_t method; /**< Name of the Method Allowed */
336 CAInfo_t info; /**< Information of the request. */
337 bool isMulticast; /**< is multicast request */
341 * @brief Response information received
343 * This structure is used to hold response information
347 CAResponseResult_t result; /**< Result for response by resource model */
348 CAInfo_t info; /**< Information of the response */
352 * @brief Error information from CA
353 * contains error code and message information
355 * This structure holds error information
359 CAResult_t result; /**< CA API request result */
360 CAInfo_t info; /**< message information such as token and payload data
361 helpful to identify the error */
365 * @brief CA Remote Access information for XMPP Client
370 char *hostname; /**< XMPP server hostname */
371 uint16_t port; /**< XMPP server serivce port */
372 char *xmpp_domain; /**< XMPP login domain */
373 char *username; /**< login username */
374 char *password; /**< login password */
375 char *resource; /**< specific resource for login */
376 char *user_jid; /**< specific JID for login */
381 * @brief Hold global variables for CA layer (also used by RI layer)
391 CATransportFlags_t clientFlags;
392 CATransportFlags_t serverFlags;
398 void *threadpool; // threadpool between Initialize and Start
399 CASocket_t u6; // unicast IPv6
400 CASocket_t u6s; // unicast IPv6 secure
401 CASocket_t u4; // unicast IPv4
402 CASocket_t u4s; // unicast IPv4 secure
403 CASocket_t m6; // multicast IPv6
404 CASocket_t m6s; // multicast IPv6 secure
405 CASocket_t m4; // multicast IPv4
406 CASocket_t m4s; // multicast IPv4 secure
407 int netlinkFd; // netlink
408 int shutdownFds[2]; // shutdown pipe
409 int selectTimeout; // in seconds
410 int maxfd; // highest fd (for select)
411 int numInterfaces; // number of active interfaces
412 bool started; // the IP adapter has started
413 bool terminate; // the IP adapter needs to stop
414 bool ipv6enabled; // IPv6 enabled by OCInit flags
415 bool ipv4enabled; // IPv4 enabled by OCInit flags
420 CATransportFlags_t previousRequestFlags; // address family filtering
421 uint16_t previousRequestMessageId; // address family filtering
425 extern CAGlobals_t caglobals;
431 #endif //#ifndef CA_COMMON_H_