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