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