replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / inc / escommon.h
1 //******************************************************************
2 //
3 // Copyright 2015 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 #ifndef ES_COMMON_H_
22 #define ES_COMMON_H_
23
24 #include "ocstack.h"
25 #include "octypes.h"
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 // Defines
33 #define OC_RSRVD_ES_RES_TYPE_COL          "oic.wk.col"
34 #define OC_RSRVD_ES_INTERFACE             "if"
35 #define OC_RSRVD_ES_RES_TYPE              "rt"
36
37
38
39 #define OIC_STRING_MAX_VALUE    256
40 #define MAX_WEBLINKLEN          3
41 #define NUM_WIFIMODE            10
42 #define NUM_CONNECT_TYPE        3
43
44 /**
45  * Attributes used to form a proper easysetup conforming JSON message.
46  */
47 #define OC_RSRVD_ES_PROVSTATUS             "ps"
48 #define OC_RSRVD_ES_LAST_ERRORCODE         "lec"
49 #define OC_RSRVD_ES_LINKS                  "links"
50 #define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
51 #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
52 #define OC_RSRVD_ES_SSID                   "tnn"
53 #define OC_RSRVD_ES_CRED                   "cd"
54 #define OC_RSRVD_ES_AUTHTYPE               "wat"
55 #define OC_RSRVD_ES_ENCTYPE                "wet"
56 #define OC_RSRVD_ES_AUTHCODE               "ac"
57 #define OC_RSRVD_ES_ACCESSTOKEN            "at"
58 #define OC_RSRVD_ES_ACCESSTOKEN_TYPE       "att"
59 #define OC_RSRVD_ES_AUTHPROVIDER           "apn"
60 #define OC_RSRVD_ES_CISERVER               "cis"
61 #define OC_RSRVD_ES_SERVERID               "sid"
62 #define OC_RSRVD_ES_DEVNAME                "dn"
63 #define OC_RSRVD_ES_HREF                   "href"
64 #define OC_RSRVD_ES_CONNECT                "cn"
65
66 /**
67  * Easysetup defined resoruce types and uris.
68  */
69 #define OC_RSRVD_ES_RES_TYPE_EASYSETUP          "oic.r.easysetup"
70 #define OC_RSRVD_ES_URI_EASYSETUP               "/EasySetupResURI"
71 #define OC_RSRVD_ES_RES_TYPE_WIFICONF           "oic.r.wificonf"
72 #define OC_RSRVD_ES_URI_WIFICONF                "/WiFiConfResURI"
73 #define OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF      "oic.r.coapcloudconf"
74 #define OC_RSRVD_ES_URI_COAPCLOUDCONF           "/CoapCloudConfResURI"
75 #define OC_RSRVD_ES_RES_TYPE_DEVCONF            "oic.r.devconf"
76 #define OC_RSRVD_ES_URI_DEVCONF                 "/DevConfResURI"
77
78
79 /**
80  * @brief  Supported WIFI frequency like 2.4G and 5G
81  */
82 typedef enum
83 {
84     WIFI_24G = 0,       /**< 2.4G **/
85     WIFI_5G,            /**< 5G **/
86     WIFI_BOTH,          /**< 2.4G and 5G **/
87     WIFI_FREQ_NONE      /**< EOF **/
88 } WIFI_FREQ;
89
90 /**
91  * @brief  Supported WIFI mode like 802.11g and 802.11n
92  */
93 typedef enum
94 {
95     WIFI_11A = 0,       /**< 802.11a **/
96     WIFI_11B,           /**< 802.11b **/
97     WIFI_11G,           /**< 802.11g **/
98     WIFI_11N,           /**< 802.11n **/
99     WIFI_11AC,          /**< 802.11ac **/
100     WiFi_EOF = 999
101 } WIFI_MODE;
102
103
104 /**
105  * @brief  WIFI Authentication tlype of the Enroller
106  */
107 typedef enum
108 {
109     NONE_AUTH = 0,      /**< NO authentication **/
110     WEP,                /**< WEP **/
111     WPA_PSK,            /**< WPA-PSK **/
112     WPA2_PSK            /**< WPA2-PSK **/
113 } WIFI_AUTHTYPE;
114
115 /**
116  * @brief  WIFI encryption type of the Enroller
117  */
118 typedef enum
119 {
120     NONE_ENC = 0,       /**< NO encryption **/
121     WEP_64,             /**< WEP-64 **/
122     WEP_128,            /**< WEP-128**/
123     TKIP,               /**< TKIP **/
124     AES,                /**< AES **/
125     TKIP_AES            /**< TKIP-AES **/
126 } WIFI_ENCTYPE;
127
128 /**
129  * @brief OAuth Access Token Types. "bearer" and "mac" types are supported.
130  */
131 typedef enum
132 {
133     NONE_OAUTH_TOKENTYPE = 0,
134     OAUTH_TOKENTYPE_BEARER,
135     OAUTH_TOKENTYPE_MAC
136 } OAUTH_TOKENTYPE;
137
138 /**
139  * @brief  A target configuration type to be connected (or executed)
140  */
141 typedef enum
142 {
143     ES_CONNECT_NONE = 0,        /**< Init value **/
144     ES_CONNECT_WIFI = 1,        /**< WiFi Conf resource **/
145     ES_CONNECT_COAPCLOUD = 2    /**< Coap Cloud Conf resource **/
146 } ES_CONNECT_TYPE;
147
148 /**
149  * @brief A result of Easy Setup
150  */
151 typedef enum
152 {
153     /**
154      * Provisioning succeeds.
155      */
156     ES_OK = 0,
157
158     /**
159      * Secure resource is discovered.
160      */
161     ES_SECURE_RESOURCE_IS_DISCOVERED = 1,
162
163     /**
164      * Enrollee discovery fails in cloud provisioning
165      */
166     ES_ENROLLEE_DISCOVERY_FAILURE = 11,
167
168     /**
169      * Valid GET or POST request fails for some reason.
170      * This failure may happen when it failed to receive any response from Enrollee by a timeout threshold
171      */
172     ES_COMMUNICATION_ERROR,
173
174     /**
175      * Security opertion is not supported because Mediator is built as unsecured mode.
176      */
177     ES_SEC_OPERATION_IS_NOT_SUPPORTED,
178
179     /**
180      * Security resource discovery fails due to loss of discovery packet or absence of the resource in a network
181      */
182     ES_SECURE_RESOURCE_DISCOVERY_FAILURE,
183
184     /**
185      * Ownership transfer fails due to one of unexpected reasons.
186      * E.g. A packet loss even with retransmission happens during ownership transfer.
187      * E.g. Mediator's owned status is 'unowned'
188      * E.g. A user confirmation for random pin-based or certificate-based OT fails
189      */
190     ES_OWNERSHIP_TRANSFER_FAILURE = 20,
191
192     /**
193      * Ownership transfer which is cert-based method fails due to user confirmation is denied.
194      */
195     ES_USER_DENIED_CONFIRMATION_REQ,
196
197     /**
198      * Ownership transfer which is cert-based method fails due to wrong certificate.
199      */
200     ES_AUTHENTICATION_FAILURE_WITH_WRONG_CERT,
201
202     /**
203      * Ownership transfer which is random-pin method fails due to wrong pin.
204      */
205     ES_AUTHENTICATION_FAILURE_WITH_WRONG_PIN,
206
207     /**
208      * Ownership information is not synchronized between Mediator and Enrollee.
209      * e.g. A mediator's PDM DB has an ownership information to the found enrollee
210      *      but it is actually owned by other mediator.
211      *      That can happen where the found enrollee is reset and performed in easy setup without any inform to the first mediator.
212      * e.g. A list of owned devices managed in mediator's PMD db has no element for the found enrollee.
213      *      That can happen where only mediator is reset without any inform to the enrollee.
214      * To proceed an ownership transfer to the enrollee, it needs to reset the enrollee's SVR DB for its owner, i.e. the mediator
215      */
216     ES_OWNERSHIP_IS_NOT_SYNCHRONIZED,
217
218     /**
219      * MOT is not supported at the target Enrollee device.
220      *
221      * @note This ESResult values will be returned ONLY IF a mediator is a first owner to an Enrollee.
222      * @note If the mediator gets this values, it means OT has been successfully done
223      * (or already took an ownership, before), but failed MOT configuration.
224      */
225     ES_MOT_NOT_SUPPORTED = 30,
226
227     /**
228      * MOT enabling is failed.
229      *
230      * @note This ESResult values will be returned ONLY IF a mediator is a first owner to an Enrollee.
231      * @note If the mediator gets this values, it means OT has been successfully done
232      * (or already took an ownership, before), but failed MOT configuration.
233      */
234     ES_MOT_ENABLING_FAILURE,
235
236     /**
237      * MOT method selection is failed
238      *
239      * @note This ESResult values will be returned ONLY IF a mediator is a first owner to an Enrollee.
240      * @note If the mediator gets this values, it means OT has been successfully done
241      * (or already took an ownership, before), but failed MOT configuration.
242      */
243     ES_MOT_METHOD_SELECTION_FAILURE,
244
245     /**
246      * A provisioning of Pre-configured pin number for MOT is failed
247      *
248      * @note This ESResult values will be returned ONLY IF a mediator is a first owner to an Enrollee.
249      * @note If the mediator gets this values, it means OT has been successfully done
250      * (or already took an ownership, before), but failed MOT configuration.
251      */
252     ES_PRE_CONFIG_PIN_PROVISIONING_FAILURE,
253
254     /**
255      * ACL provisioning fails in cloud provisioning.
256      * It could be that UUID format of cloud server is wrong.
257      * Or any response for the provisioning request is not arrived at Mediator
258      */
259     ES_ACL_PROVISIONING_FAILURE = 40,
260
261     /**
262      * Cert. provisioning fails in cloud provisioning.
263      * It could be that you put a wrong cred ID of which the corresponding certificate does not exist in SVR DB.
264      * Or any response for the provisioning request is not arrived at Mediator
265      */
266     ES_CERT_PROVISIONING_FAILURE,
267
268     /**
269      * Provisioning fails for some reason.
270      */
271
272     ES_ERROR = 255
273 } ESResult;
274
275 /**
276  * @brief Indicate which resource is created in Enrollee
277  */
278 typedef enum
279 {
280     ES_WIFICONF_RESOURCE = 0x01,
281     ES_COAPCLOUDCONF_RESOURCE = 0x02,
282     ES_DEVCONF_RESOURCE = 0x04
283 } ESResourceMask;
284
285 /**
286  * @brief Indicate enrollee and provisioning status. Provisioning status is shown in "provisioning
287  *        status" property in easysetup resource.
288  */
289 typedef enum
290 {
291     /**
292      * Default state of the device
293      */
294     ES_STATE_INIT = 0,
295
296     /**
297      * Status indicating being connecting to target network
298      */
299     ES_STATE_CONNECTING_TO_ENROLLER,
300
301     /**
302      * Status indicating successful conection to target network
303      */
304     ES_STATE_CONNECTED_TO_ENROLLER,
305
306     /**
307      * Status indicating connection failure to target network
308      */
309     ES_STATE_FAILED_TO_CONNECT_TO_ENROLLER,
310
311     /**
312      * Status indicating being registering to cloud
313      */
314     ES_STATE_REGISTERING_TO_CLOUD,
315
316     /**
317      * Status indicating successful registration to cloud
318      */
319     ES_STATE_REGISTERED_TO_CLOUD,
320
321     /**
322      * Status indicating registeration failure to cloud
323      */
324     ES_STATE_FAILED_TO_REGISTER_TO_CLOUD,
325
326     /**
327      * Status indicating being publishing resources to cloud
328      */
329     ES_STATE_PUBLISHING_RESOURCES_TO_CLOUD,
330
331     /**
332      * Status indicating successful resource publish to cloud
333      */
334     ES_STATE_PUBLISHED_RESOURCES_TO_CLOUD,
335
336     /**
337      * Status indicating resource publish failure to cloud
338      */
339     ES_STATE_FAILED_TO_PUBLISH_RESOURCES_TO_CLOUD,
340
341     /**
342      * End of Easy setup status
343      */
344     ES_STATE_EOF = 255
345 } ESEnrolleeState, ProvStatus;
346
347 /**
348  * @brief Indicate last error code to describe a reason of error during easy setup.
349  */
350 typedef enum
351 {
352     /**
353      * Init Error Code
354      */
355     ES_ERRCODE_NO_ERROR = 0,
356
357     /**
358      * Error Code that given WiFi's SSID is not found
359      */
360     ES_ERRCODE_SSID_NOT_FOUND,
361
362     /**
363      * Error Code that given WiFi's Password is wrong
364      */
365     ES_ERRCODE_PW_WRONG,
366
367     /**
368      * Error Code that IP address is not allocated
369      */
370     ES_ERRCODE_IP_NOT_ALLOCATED,
371
372     /**
373      * Error Code that there is no Internet connection
374      */
375     ES_ERRCODE_NO_INTERNETCONNECTION,
376
377     /**
378      * Error Code that Timeout occured
379      */
380     ES_ERRCODE_TIMEOUT,
381
382     /**
383      * Error Code that cloud server is not reachable due to wrong URL of cloud server, for example.
384      */
385     ES_ERRCODE_FAILED_TO_ACCESS_CLOUD_SERVER,
386
387     /**
388      * Error Code that no response is arrived from cloud server
389      */
390     ES_ERRCODE_NO_RESPONSE_FROM_CLOUD_SERVER,
391
392     /**
393      * Error Code that a delivered authcode is not valid.
394      */
395     ES_ERRCODE_INVALID_AUTHCODE,
396
397     /**
398      * Error Code that a given access token is not valid due to its expiration, for example.
399      */
400     ES_ERRCODE_INVALID_ACCESSTOKEN,
401
402     /**
403      * Error Code that a refresh of expired access token is failed due to some reasons.
404      */
405     ES_ERRCODE_FAILED_TO_REFRESH_ACCESSTOKEN,
406
407     /**
408      * Error Code that a target device is not discovered in cloud server
409      */
410     ES_ERRCODE_FAILED_TO_FIND_REGISTERED_DEVICE_IN_CLOUD,
411
412     /**
413      * Error Code that a target user does not exist in cloud server.
414      */
415     ES_ERRCODE_FAILED_TO_FIND_REGISTERED_USER_IN_CLOUD,
416
417     /**
418      * Error Code that an enrollee can not connect to a target WiFi AP because the AP resides in
419      * an unsupported WiFi frequency.
420      */
421     ES_ERRCODE_UNSUPPORTED_WIFI_FREQUENCY,
422
423     /**
424      * Error Code that Unknown error occured
425      */
426     ES_ERRCODE_UNKNOWN = 255
427 } ESErrorCode;
428
429 #ifdef __cplusplus
430 }
431 #endif
432
433 #endif //ES_COMMON_H_