iotivity 0.9.0
[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 #ifndef __CA_COMMON_H_
26 #define __CA_COMMON_H_
27
28 #include <stdint.h>
29 #include <stdlib.h>
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35
36 /**
37  @brief IP Address Length
38  */
39 #define CA_IPADDR_SIZE 16
40
41 /**
42  @brief Mac Address Length for BT
43  */
44 #define CA_MACADDR_SIZE 18
45
46 /**
47  @brief Max Header Options data length
48  */
49 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16
50
51 /**
52  @brief CAPayload_t
53  */
54 typedef char* CAPayload_t;
55
56 /**
57  @brief CAURI_t
58  */
59 typedef char* CAURI_t;
60
61 /**
62  @brief CAToken_t
63  */
64 typedef char* CAToken_t;
65
66 /**
67  @brief CABool_t
68  */
69 typedef enum
70 {
71     CA_FALSE = 0, CA_TRUE
72 } CABool_t;
73
74 /**
75  @brief CAConnectivityType_t
76  */
77 typedef enum
78 {
79     CA_ETHERNET = (1 << 0), CA_WIFI = (1 << 1), CA_EDR = (1 << 2), CA_LE = (1 << 3)
80 } CAConnectivityType_t;
81
82 /**
83  @brief CANetworkStatus_t
84  */
85 typedef enum
86 {
87     CA_INTERFACE_UP, CA_INTERFACE_DOWN
88 } CANetworkStatus_t;
89
90 /**
91  @brief  Address of the local or remote endpoint
92  */
93 typedef union
94 {
95     /**
96      @brief BT Information
97      */
98     struct
99     {
100         /** @brief Bluettoth Mac Address **/
101         char btMacAddress[CA_MACADDR_SIZE];
102     } BT;
103     /**
104      @brief IP Information
105      */
106     struct
107     {
108         /** Ip address of the interface**/
109         char ipAddress[CA_IPADDR_SIZE];
110         /** port information**/
111         uint32_t port;
112     } IP;
113 } CAAddress_t;
114
115 /**
116  @brief CAQualityOfService
117  */
118 typedef enum
119 {
120     CA_LOW_QOS = 0, CA_MEDIUM_QOS, CA_HIGH_QOS, CA_NA_QOS // No Quality is defined, let the stack decide
121 } CAQualityOfService_t;
122
123 /**
124  @brief CAMethod_t
125  */
126 typedef enum
127 {
128     CA_GET = 1, CA_POST, CA_PUT, CA_DELETE
129 } CAMethod_t;
130
131 /**
132  @brief RemoteEndpoint information for connectivities
133  */
134 typedef struct
135 {
136     /** Resource URI information **/
137     CAURI_t resourceUri;
138     /** Remote Endpoint address **/
139     CAAddress_t addressInfo;
140     /** Connectivity of the endpoint**/
141     CAConnectivityType_t connectivityType;
142 } CARemoteEndpoint_t;
143
144 /**
145  @brief Local Connectivity information
146  */
147 typedef struct
148 {
149     /** address of the interface  **/
150     CAAddress_t addressInfo;
151     /** Connectivity type that localconnectivity avaialble **/
152     CAConnectivityType_t type;
153 } CALocalConnectivityt_t;
154
155 /**
156  @brief Enums for CA return values
157  */
158 typedef enum
159 {
160     /* Success status code - START HERE */
161     CA_STATUS_OK = 0,
162     CA_STATUS_INVALID_PARAM,
163     CA_DESTINATION_NOT_REACHABLE,
164     CA_SEND_FAILED,
165     CA_RECEVIE_FAILED,
166     CA_MEMORY_ALLOC_FAILED,
167     CA_REQUEST_TIMEOUT,
168     CA_DESTINATION_DISCONNECTED,
169     CA_STATUS_FAILED,
170     CA_NOT_SUPPORTED
171 /* Error status code - END HERE */
172 } CAResult_t;
173
174 /**
175  @brief Enums for CA Response  values
176  */
177 typedef enum
178 {
179     /* Success status code - START HERE */
180     CA_CREATED = 201,
181     CA_DELETED = 202,
182     CA_VALID = 203,
183     CA_CONTENT = 205,
184     CA_BAD_REQ = 400,
185     CA_BAD_OPT = 402,
186     CA_NOT_FOUND = 404
187 /* Error status code - END HERE */
188 } CAResponseResult_t;
189
190 /**
191  @brief Transport Protocol IDs
192  */
193 typedef enum
194 {
195     CA_INVALID_ID = (1 << 0), CA_COAP_ID = (1 << 1)
196 } CATransportProtocolID_t;
197
198 /**
199  * @brief Header options structure to be filled
200  *
201  * This structure is used to hold header information.
202  */
203 typedef struct
204 {
205     /** The protocol ID this option applies to**/
206     CATransportProtocolID_t protocolID;
207     /** The header option ID which will be added to communication packets**/
208     uint16_t optionID;
209     /** its length   191**/
210     uint16_t optionLength;
211     /** optional data values**/
212     uint8_t optionData[CA_MAX_HEADER_OPTION_DATA_LENGTH];
213 } CAHeaderOption_t;
214
215 /**
216  * @brief Request Information to be sent
217  *
218  * This structure is used to hold request information
219  */
220
221 /**
222  * @brief Base Information received
223  *
224  * This structure is used to hold request & response base information
225  */
226 typedef struct
227 {
228     /**Qos for the request **/
229     CAQualityOfService_t qos;
230     /** Token for CA**/
231     CAToken_t token;
232     /** Header Options for the request **/
233     CAHeaderOption_t * options;
234     /** Number of Header options**/
235     uint8_t numOptions;
236     /** payload of the request **/
237     CAPayload_t payload;
238 } CAInfo_t;
239
240 typedef struct
241 {
242     /** Name of the Method Allowed **/
243     CAMethod_t method;
244     /** Base Information **/
245     CAInfo_t info;
246 } CARequestInfo_t;
247
248 /**
249  * @brief Response Information received
250  *
251  * This structure is used to hold response information
252  */
253 typedef struct
254 {
255     /**Response Result by Resource Model**/
256     CAResponseResult_t result;
257     /**Base Information **/
258     CAInfo_t info;
259 } CAResponseInfo_t;
260
261 #ifdef __cplusplus
262 } /* extern "C" */
263 #endif
264
265 #endif //#ifndef __CA_COMMON_H_