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 Mac address length for BT port
47 #define CA_MACADDR_SIZE 18
50 * @brief Max header options data length
52 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
55 * @brief Max token length
57 #define CA_MAX_TOKEN_LEN (8)
60 * @brief Max URI length
63 #define CA_MAX_URI_LENGTH 128 /* maximum size of URI for embedded platforms*/
65 #define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/
69 * @brief Max PDU length supported
72 #define COAP_MAX_PDU_SIZE 320 /* maximum size of a CoAP PDU for embedded platforms*/
74 #define COAP_MAX_PDU_SIZE 1400 /* maximum size of a CoAP PDU for big platforms*/
78 *@brief Maximum length of the remoteEndpoint identity
80 #define CA_MAX_ENDPOINT_IDENTITY_LEN (32)
83 * @brief option types - the highest option number 63
85 #define CA_OPTION_IF_MATCH 1
86 #define CA_OPTION_ETAG 4
87 #define CA_OPTION_IF_NONE_MATCH 5
88 #define CA_OPTION_OBSERVE 6
89 #define CA_OPTION_LOCATION_PATH 8
90 #define CA_OPTION_URI_PATH 11
91 #define CA_OPTION_CONTENT_FORMAT 12
92 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
93 #define CA_OPTION_MAXAGE 14
94 #define CA_OPTION_URI_QUERY 15
95 #define CA_OPTION_ACCEPT 17
96 #define CA_OPTION_LOCATION_QUERY 20
99 * @brief Payload information from resource model
101 typedef char *CAPayload_t;
104 * @brief URI for the OIC base.CA considers relative URI as the URI.
106 typedef char *CAURI_t;
109 * @brief Token information for mapping the request and responses by resource model
111 typedef char *CAToken_t;
113 // The following flags are the same as the equivalent OIC values in
114 // octypes.h, allowing direct copying with slight fixup.
115 // The CA layer should used the OC types when build allows that.
116 #define MAX_ADDR_STR_SIZE_CA (40)
120 CA_DEFAULT_ADAPTER = 0,
122 // value zero indicates discovery
123 CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
124 CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
125 CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
126 } CATransportAdapter_t;
130 CA_DEFAULT_FLAGS = 0,
132 // Insecure transport is the default (subject to change)
133 CA_SECURE = (1 << 4), // secure the transport path
134 // IPv4 & IPv6 autoselection is the default
135 CA_IPV6 = (1 << 5), // IP adapter only
136 CA_IPV4 = (1 << 6), // IP adapter only
137 // Link-Local multicast is the default multicast scope for IPv6.
138 // These correspond in both value and position to the IPv6 address bits.
139 CA_SCOPE_INTERFACE = 0x1, // IPv6 Interface-Local scope
140 CA_SCOPE_LINK = 0x2, // IPv6 Link-Local scope (default)
141 CA_SCOPE_REALM = 0x3, // IPv6 Realm-Local scope
142 CA_SCOPE_ADMIN = 0x4, // IPv6 Admin-Local scope
143 CA_SCOPE_SITE = 0x5, // IPv6 Site-Local scope
144 CA_SCOPE_ORG = 0x8, // IPv6 Organization-Local scope
145 CA_SCOPE_GLOBAL = 0xE, // IPv6 Global scope
146 } CATransportFlags_t;
149 * @enum CANetworkStatus_t
150 * @brief Information about the network status.
154 CA_INTERFACE_DOWN, /**< Connection is not available */
155 CA_INTERFACE_UP /**< Connection is Available */
159 * @brief remoteEndpoint identity
164 unsigned char id[CA_MAX_ENDPOINT_IDENTITY_LEN];
168 * @enum CAMessageType_t
169 * @brief Message Type for Base source code
173 CA_MSG_CONFIRM = 0, /**< confirmable message (requires ACK/RST) */
174 CA_MSG_NONCONFIRM, /**< non-confirmable message (one-shot message) */
175 CA_MSG_ACKNOWLEDGE, /**< used to acknowledge confirmable messages */
176 CA_MSG_RESET /**< used to indicates not-interested or error (lack of context)in
182 * @brief Allowed method to be used by resource model
186 CA_GET = 1, /**< GET Method */
187 CA_POST, /**< POST Method */
188 CA_PUT, /**< PUT Method */
189 CA_DELETE /**< DELETE Method */
193 * @brief Endpoint information for connectivities
194 * Must be identical to OCDevAddr.
198 CATransportAdapter_t adapter; // adapter type
199 CATransportFlags_t flags; // transport modifiers
200 char addr[MAX_ADDR_STR_SIZE_CA]; // address for all
201 uint32_t interface; // usually zero for default interface
202 uint16_t port; // for IP
203 CARemoteId_t identity; // endpoint identity
208 * @brief Enums for CA return values
212 // Result code - START HERE
213 CA_STATUS_OK = 0, /**< Success */
214 CA_STATUS_INVALID_PARAM, /**< Invalid Parameter */
215 CA_ADAPTER_NOT_ENABLED, /**< Adapter is not enabled */
216 CA_SERVER_STARTED_ALREADY, /**< Server is started already */
217 CA_SERVER_NOT_STARTED, /**< Server is not started*/
218 CA_DESTINATION_NOT_REACHABLE, /**< Destination is not reachable */
219 CA_SOCKET_OPERATION_FAILED, /**< Socket operation failed */
220 CA_SEND_FAILED, /**< Send request failed */
221 CA_RECEIVE_FAILED, /**< Receive failed */
222 CA_MEMORY_ALLOC_FAILED, /**< Memory allocation failed */
223 CA_REQUEST_TIMEOUT, /**< Request is Timeout */
224 CA_DESTINATION_DISCONNECTED, /**< Destination is disconnected */
225 CA_NOT_SUPPORTED, /**< Not supported */
226 CA_STATUS_NOT_INITIALIZED, /**< CA layer is not initialized */
227 CA_STATUS_FAILED =255 /**< Failure */
228 /* Result code - END HERE */
232 * @enum CAResponseResult_t
233 * @brief Enums for CA Response values
237 /* Response status code - START HERE */
238 CA_EMPTY = 0, /**< Empty */
239 CA_SUCCESS = 200, /**< Success */
240 CA_CREATED = 201, /**< Created */
241 CA_DELETED = 202, /**< Deleted */
242 CA_BAD_REQ = 400, /**< Bad Request */
243 CA_UNAUTHORIZED_REQ = 401, /**< Unauthorized Request */
244 CA_BAD_OPT = 402, /**< Bad Option */
245 CA_FORBIDDEN_REQ = 403, /**< Forbidden Request */
246 CA_NOT_FOUND = 404, /**< Not found */
247 CA_INTERNAL_SERVER_ERROR = 500, /**< Internal Server Error */
248 CA_RETRANSMIT_TIMEOUT = 504 /**< Retransmit timeout */
249 /* Response status code - END HERE */
250 } CAResponseResult_t;
253 * @enum CATransportProtocolID_t
254 * @brief Transport Protocol IDs for additional options
258 CA_INVALID_ID = (1 << 0), /**< Invalid ID */
259 CA_COAP_ID = (1 << 1) /**< COAP ID */
260 } CATransportProtocolID_t;
263 * @enum CAAdapterState_t
264 * @brief Adapter State to indicate the network changed notifications.
268 CA_ADAPTER_DISABLED, /**< Adapter is Disabled */
269 CA_ADAPTER_ENABLED /**< Adapter is Enabled */
273 * @brief Header options structure to be filled
275 * This structure is used to hold header information.
279 CATransportProtocolID_t protocolID; /**< Protocol ID of the Option */
280 uint16_t optionID; /**< The header option ID which will be
281 added to communication packets */
282 uint16_t optionLength; /**< Option Length **/
283 char optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH]; /**< Optional data values**/
287 * @brief Base Information received
289 * This structure is used to hold request & response base information
294 CAMessageType_t type; /**< Qos for the request */
295 uint16_t messageId; /**< Message id.
296 * if message id is zero, it will generated by CA inside.
297 * otherwise, you can use it */
298 CAToken_t token; /**< Token for CA */
299 uint8_t tokenLength; /**< token length*/
300 CAHeaderOption_t *options; /** Header Options for the request */
301 uint8_t numOptions; /**< Number of Header options */
302 CAPayload_t payload; /**< payload of the request */
303 CAURI_t resourceUri; /**< Resource URI information **/
307 * @brief Request Information to be sent
309 * This structure is used to hold request information
313 CAMethod_t method; /**< Name of the Method Allowed */
314 CAInfo_t info; /**< Information of the request. */
315 bool isMulticast; /**< is multicast request */
319 * @brief Response information received
321 * This structure is used to hold response information
325 CAResponseResult_t result; /**< Result for response by resource model */
326 CAInfo_t info; /**< Information of the response */
330 * @brief Error information from CA
331 * contains error code and message information
333 * This structure holds error information
337 CAResult_t result; /**< CA API request result */
338 CAInfo_t info; /**< message information such as token and payload data
339 helpful to identify the error */
343 * @brief Hold global variables for CA layer (also used by RI layer)
347 CATransportFlags_t serverFlags;
348 CATransportFlags_t clientFlags;
351 extern CAGlobals_t caglobals;
357 #endif //#ifndef CA_COMMON_H_