Imported Upstream version 0.9.1
[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  * @brief 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 <stdint.h>
30 #include <stdlib.h>
31 #include <stdbool.h>
32
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 /**
40  * @brief IP address Length
41  */
42 #define CA_IPADDR_SIZE 16
43
44 /**
45  * @brief Mac address length for BT port
46  */
47 #define CA_MACADDR_SIZE 18
48
49 /**
50  * @brief Max header options data length
51  */
52 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
53
54 /**
55 * @brief Max token length
56 */
57 #define CA_MAX_TOKEN_LEN (8)
58
59 /**
60  * @brief Max URI length
61  */
62 #ifdef ARDUINO
63 #define CA_MAX_URI_LENGTH 128  /* maximum size of URI for embedded platforms*/
64 #else
65 #define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/
66 #endif
67
68 /**
69  * @brief Max PDU length supported
70  */
71 #ifdef ARDUINO
72 #define COAP_MAX_PDU_SIZE           320  /* maximum size of a CoAP PDU for embedded platforms*/
73 #else
74 #define COAP_MAX_PDU_SIZE           1400 /* maximum size of a CoAP PDU for big platforms*/
75 #endif
76
77 /**
78  * @brief option types - the highest option number 63
79  */
80 #define CA_OPTION_IF_MATCH 1
81 #define CA_OPTION_ETAG 4
82 #define CA_OPTION_IF_NONE_MATCH 5
83 #define CA_OPTION_OBSERVE 6
84 #define CA_OPTION_LOCATION_PATH 8
85 #define CA_OPTION_URI_PATH 11
86 #define CA_OPTION_CONTENT_FORMAT 12
87 #define CA_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
88 #define CA_OPTION_MAXAGE 14
89 #define CA_OPTION_URI_QUERY 15
90 #define CA_OPTION_ACCEPT 17
91 #define CA_OPTION_LOCATION_QUERY 20
92
93 /**
94  * @brief Payload information from resource model
95  */
96 typedef char *CAPayload_t;
97
98 /**
99  * @brief URI for the OIC base.CA considers relative URI as the URI.
100  */
101 typedef char *CAURI_t;
102
103 /**
104  * @brief Token information for mapping the request and responses by resource model
105  */
106 typedef char *CAToken_t;
107
108 /**
109  * @enum CATransportType_t
110  * @brief Different connectivities that are handled in Connectivity Abstraction
111  */
112 typedef enum
113 {
114     CA_IPV4 = (1 << 0),     /**< IPV4 Transport Type */
115     CA_IPV6 = (1 << 1),     /**< IPV6 Transport Type */
116     CA_EDR = (1 << 2),      /**< EDR Transport Type */
117     CA_LE = (1 << 3)        /**< LE Transport Type */
118 } CATransportType_t;
119
120 /**
121  * @enum CANetworkStatus_t
122  * @brief Information about the network status.
123  */
124 typedef enum
125 {
126     CA_INTERFACE_DOWN,   /**< Connection is not available */
127     CA_INTERFACE_UP    /**< Connection is Available */
128 } CANetworkStatus_t;
129
130 /**
131  * @brief  Address of the local or remote endpoint
132  */
133 typedef union
134 {
135     /**
136      * @brief BT Mac Information
137      */
138     struct
139     {
140         char btMacAddress[CA_MACADDR_SIZE];   /**< BT mac address **/
141     } BT;
142
143     /**
144      * @brief LE MAC Information
145      */
146     struct
147     {
148         char leMacAddress[CA_MACADDR_SIZE];   /**< BLE mac address **/
149     } LE;
150
151     /**
152      * @brief IP Information
153      */
154     struct
155     {
156         char ipAddress[CA_IPADDR_SIZE]; /**< Ip address of the interface**/
157         uint16_t port;                  /**< port information**/
158     } IP;
159 } CAAddress_t;
160
161 /**
162  * @enum CAMessageType_t
163  * @brief Message Type for Base source code
164  */
165 typedef enum
166 {
167     CA_MSG_CONFIRM = 0,  /**< confirmable message (requires ACK/RST) */
168     CA_MSG_NONCONFIRM,   /**< non-confirmable message (one-shot message) */
169     CA_MSG_ACKNOWLEDGE,  /**< used to acknowledge confirmable messages */
170     CA_MSG_RESET         /**< used to indicates not-interested or error (lack of context)in
171                                                   received messages */
172 } CAMessageType_t;
173
174 /**
175  * @enum CAMethod_t
176  * @brief Allowed method to be used by resource model
177  */
178 typedef enum
179 {
180     CA_GET = 1, /**< GET Method  */
181     CA_POST,    /**< POST Method */
182     CA_PUT,     /**< PUT Method */
183     CA_DELETE   /**< DELETE Method */
184 } CAMethod_t;
185
186 /**
187  * @brief Remote endpoint information for connectivities
188  */
189 typedef struct
190 {
191
192     CAURI_t resourceUri;                    /**< Resource URI information **/
193     CAAddress_t addressInfo;                /**< Remote Endpoint address **/
194     CATransportType_t transportType;  /**< Transport Type of the endpoint**/
195     bool isSecured;                     /**< Secure connection**/
196 } CARemoteEndpoint_t;
197
198
199 /**
200  * @brief Group endpoint information for connectivities
201  */
202 typedef struct
203 {
204     CAURI_t resourceUri;                    /**< Resource URI information **/
205     CATransportType_t transportType;  /**< Transport type of the endpoint**/
206 } CAGroupEndpoint_t;
207
208 /**
209  @brief Local Connectivity information
210  */
211 typedef struct
212 {
213     CAAddress_t addressInfo;    /**< Address of the interface  **/
214     CATransportType_t type;  /**< Transport type of local device **/
215     bool isSecured;         /**< Secure connection**/
216 } CALocalConnectivity_t;
217
218 /**
219  * @enum CAResult_t
220  * @brief Enums for CA return values
221  */
222 typedef enum
223 {
224     // Result code - START HERE
225     CA_STATUS_OK = 0,               /**< Success */
226     CA_STATUS_INVALID_PARAM,        /**< Invalid Parameter */
227     CA_ADAPTER_NOT_ENABLED,         /**< Adapter is not enabled */
228     CA_SERVER_STARTED_ALREADY,      /**< Server is started already */
229     CA_SERVER_NOT_STARTED,          /**< Server is not started*/
230     CA_DESTINATION_NOT_REACHABLE,   /**< Destination is not reachable */
231     CA_SOCKET_OPERATION_FAILED,     /**< Socket operation failed */
232     CA_SEND_FAILED,                 /**< Send request failed */
233     CA_RECEIVE_FAILED,              /**< Receive failed */
234     CA_MEMORY_ALLOC_FAILED,         /**< Memory allocation failed */
235     CA_REQUEST_TIMEOUT,             /**< Request is Timeout */
236     CA_DESTINATION_DISCONNECTED,    /**< Destination is disconnected */
237     CA_NOT_SUPPORTED,               /**< Not supported */
238     CA_STATUS_FAILED =255           /**< Failure */
239     /* Result code - END HERE */
240 } CAResult_t;
241
242 /**
243  * @enum CAResponseResult_t
244  * @brief Enums for CA Response values
245  */
246 typedef enum
247 {
248     /* Response status code - START HERE */
249     CA_EMPTY = 0,                    /**< Empty */
250     CA_SUCCESS = 200,                /**< Success */
251     CA_CREATED = 201,                /**< Created */
252     CA_DELETED = 202,                /**< Deleted */
253     CA_BAD_REQ = 400,                /**< Bad Request */
254     CA_BAD_OPT = 402,                /**< Bad Option */
255     CA_NOT_FOUND = 404,              /**< Not found */
256     CA_INTERNAL_SERVER_ERROR = 500,  /**< Internal Server Error */
257     CA_RETRANSMIT_TIMEOUT = 504      /**< Retransmit timeout */
258     /* Response status code - END HERE */
259 } CAResponseResult_t;
260
261 /**
262  * @enum CATransportProtocolID_t
263  * @brief Transport Protocol IDs for additional options
264  */
265 typedef enum
266 {
267     CA_INVALID_ID = (1 << 0),   /**< Invalid ID */
268     CA_COAP_ID = (1 << 1)       /**< COAP ID */
269 } CATransportProtocolID_t;
270
271 /**
272  * @enum CAAdapterState_t
273  * @brief Adapter State to indicate the network changed notifications.
274  */
275 typedef enum
276 {
277     CA_ADAPTER_DISABLED,   /**< Adapter is Disabled */
278     CA_ADAPTER_ENABLED     /**< Adapter is Enabled */
279 } CAAdapterState_t;
280
281 /**
282  * @brief Header options structure to be filled
283  *
284  * This structure is used to hold header information.
285  */
286 typedef struct
287 {
288     CATransportProtocolID_t protocolID;                     /**< Protocol ID of the Option */
289     uint16_t optionID;                                      /**< The header option ID which will be
290                                                             added to communication packets */
291     uint16_t optionLength;                                  /**< Option Length **/
292     uint8_t optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];   /**< Optional data values**/
293 } CAHeaderOption_t;
294
295 /**
296  * @brief Base Information received
297  *
298  * This structure is used to hold request & response base information
299  */
300 typedef struct
301 {
302
303     CAMessageType_t type;       /**< Qos for the request */
304     uint16_t messageId;         /**< Message id.
305                                  * if message id is zero, it will generated by CA inside.
306                                  * otherwise, you can use it */
307     CAToken_t token;            /**< Token for CA */
308     uint8_t tokenLength;        /**< token length*/
309     CAHeaderOption_t *options;  /** Header Options for the request */
310     uint8_t numOptions;         /**< Number of Header options */
311     CAPayload_t payload;        /**< payload of the request  */
312 } CAInfo_t;
313
314 /**
315  * @brief Request Information to be sent
316  *
317  * This structure is used to hold request information
318  */
319 typedef struct
320 {
321     CAMethod_t method;  /**< Name of the Method Allowed */
322     CAInfo_t info;      /**< Information of the request. */
323 } CARequestInfo_t;
324
325 /**
326  * @brief Response information received
327  *
328  * This structure is used to hold response information
329  */
330 typedef struct
331 {
332     CAResponseResult_t result;  /**< Result for response by resource model */
333     CAInfo_t info;              /**< Information of the response */
334 } CAResponseInfo_t;
335
336 #ifdef __cplusplus
337 } /* extern "C" */
338 #endif
339
340 #endif /* CA_COMMON_H_ */
341