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