Add an API for handling user-specific properties in Enrollee side
[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 OIC_STRING_MAX_VALUE    100
34 #define IPV4_ADDR_SIZE          16
35 #define IP_PORT                 55555
36
37 /**
38  * @brief Mac address length for BT port
39  */
40 #define NET_MACADDR_SIZE 18
41
42 /**
43  * Attributes used to form a proper easysetup conforming JSON message.
44  */
45 #define OC_RSRVD_ES_PROVSTATUS             "ps"
46 #define OC_RSRVD_ES_LAST_ERRORCODE         "lec"
47 #define OC_RSRVD_ES_LINKS                  "links"
48 #define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
49 #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
50 #define OC_RSRVD_ES_SSID                   "tnn"
51 #define OC_RSRVD_ES_CRED                   "cd"
52 #define OC_RSRVD_ES_AUTHTYPE               "wat"
53 #define OC_RSRVD_ES_ENCTYPE                "wet"
54 #define OC_RSRVD_ES_AUTHCODE               "ac"
55 #define OC_RSRVD_ES_AUTHPROVIDER           "apn"
56 #define OC_RSRVD_ES_CISERVER               "cis"
57 #define OC_RSRVD_ES_SERVERID               "sid"
58 #define OC_RSRVD_ES_DEVNAME                "dn"
59 #define OC_RSRVD_ES_LANGUAGE               "lang"
60 #define OC_RSRVD_ES_COUNTRY                "ctry"
61
62 /**
63  * Easysetup defined resoruce types and uris.
64  */
65 #define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.wk.prov"
66 #define OC_RSRVD_ES_URI_PROV              "/ProvisioningResURI"
67 #define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.wk.wifi"
68 #define OC_RSRVD_ES_URI_WIFI              "/WiFiProvisioningResURI"
69 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.wk.cloudserver"
70 #define OC_RSRVD_ES_URI_CLOUDSERVER       "/CloudServerProvisioningResURI"
71 #define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.wk.devconf"
72 #define OC_RSRVD_ES_URI_DEVCONF           "/DevConfProvisioningResURI"
73
74 #define NUM_WIFIMODE    10
75 #define MAX_SSIDLEN     33
76 #define MAX_CREDLEN     20
77
78 #define MAX_DEVICELEN   100
79 #define MAX_WEBLINKLEN  100
80
81 /**
82  * @brief  Supported WIFI mode like 802.11g and 802.11n
83  */
84 typedef enum
85 {
86     WiFi_11A = 0,       /**< 802.11a **/
87     WiFi_11B,           /**< 802.11b **/
88     WiFi_11G,           /**< 802.11g **/
89     WiFi_11N,           /**< 802.11n **/
90     WiFi_11AC,          /**< 802.11ac **/
91     WiFi_EOF = 999
92 } WIFI_MODE;
93
94 /**
95  * @brief  Supported WIFI frequency like 2.4G and 5G
96  */
97 typedef enum
98 {
99     WiFi_24G = 0,       /**< 2.4G **/
100     WiFi_5G,            /**< 5G **/
101     WiFi_BOTH,          /**< 2.4G and 5G **/
102     WiFi_FREQ_NONE      /**< EOF **/
103 } WIFI_FREQ;
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 } WIFI_AUTHTYPE;
115
116 /**
117  * @brief  WIFI encryption type of the Enroller
118  */
119 typedef enum
120 {
121     NONE_ENC = 0,       /**< NO encryption **/
122     WEP_64,             /**< WEP-64 **/
123     WEP_128,            /**< WEP-128**/
124     TKIP,               /**< TKIP **/
125     AES,                /**< AES **/
126     TKIP_AES            /**< TKIP-AES **/
127 } WIFI_ENCTYPE;
128
129 typedef enum
130 {
131     ES_ERROR = -1,
132     ES_OK = 0,
133     ES_NETWORKFOUND = 1,
134     ES_NETWORKCONNECTED,
135     ES_NETWORKNOTCONNECTED,
136     ES_RESOURCECREATED = 11,
137     ES_RECVREQOFPROVRES = 21,
138     ES_RECVREQOFNETRES,
139     ES_RECVUPDATEOFPROVRES,
140     ES_RECVTRIGGEROFPROVRES,
141     ES_UNAUTHORIZED = 31
142 } ESResult;
143
144 /**
145  * @brief Indicate which resource is created in Enrollee
146  */
147 typedef enum
148 {
149     ES_WIFI_RESOURCE = 0x01,
150     ES_CLOUD_RESOURCE = 0x02,
151     ES_DEVCONF_RESOURCE = 0x04
152 } ESResourceMask;
153
154 /**
155  * @brief Data structure delivered from mediator, which provides WiFi information
156  */
157 typedef struct
158 {
159     char ssid[MAX_SSIDLEN];         /**< Ssid of the Enroller**/
160     char pwd[MAX_CREDLEN];          /**< Pwd of the Enroller**/
161     WIFI_AUTHTYPE authtype;         /**< Auth type of the Enroller**/
162     WIFI_ENCTYPE enctype;           /**< Encryption type of the Enroller**/
163     void *userdata;                 /**< Vender-specific data**/
164 } ESWiFiProvData;
165
166 /**
167  * @brief Data structure delivered from mediator, which provides device configuration information
168  */
169 typedef struct
170 {
171     char language[OIC_STRING_MAX_VALUE];    /**< IETF language tag using ISO 639X **/
172     char country[OIC_STRING_MAX_VALUE];     /**< ISO Country Code (ISO 3166-1 Alpha-2) **/
173     void *userdata;                         /**< Vender-specific data**/
174 } ESDevConfProvData;
175
176 /**
177  * @brief Data structure delivered from mediator, which provides Cloud server information
178  */
179 typedef struct
180 {
181     char authCode[OIC_STRING_MAX_VALUE];        /**< Auth code issued by OAuth2.0-compatible account server **/
182     char authProvider[OIC_STRING_MAX_VALUE];    /**< Auth provider ID **/
183     char ciServer[OIC_STRING_MAX_VALUE];        /**< Cloud interface server URL which an Enrollee is going to registered **/
184     void *userdata;                             /**< Vender-specific data**/
185 } ESCloudProvData;
186
187 /**
188  * @brief Data structure stored for Device property which includes a WiFi and device configuration.
189  */
190 typedef struct
191 {
192     /**
193      * @brief Data structure indicating WiFi configuration of Enrollee
194      */
195     struct
196     {
197         WIFI_MODE mode[NUM_WIFIMODE];
198         WIFI_FREQ freq;
199     } WiFi;
200
201     /**
202      * @brief Data structure indicating device configuration of Enrollee
203      */
204     struct
205     {
206         char deviceName[MAX_DEVICELEN];
207     } DevConf;
208 } ESDeviceProperty;
209
210 /**
211  * @brief Indicate enrollee and provisioning status. Provisioning status is shown in "provisioning
212  *        status" property in provisioning resource.
213  */
214 typedef enum
215 {
216     /**
217      * Default state of the device
218      */
219     ES_STATE_INIT = 0,
220
221     /**
222     * Status indicating being cnnecting to target network
223     */
224     ES_STATE_CONNECTING_TO_ENROLLER,
225
226     /**
227     * Status indicating successful conection to target network
228     */
229     ES_STATE_CONNECTED_TO_ENROLLER,
230
231     /**
232     * Status indicating failure connection to target network
233     */
234     ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
235
236     /**
237     * Status indicating successful registration to cloud
238     */
239     ES_STATE_REGISTERED_TO_CLOUD,
240
241     /**
242     * Status indicating failure registeration to cloud
243     */
244     ES_STATE_REGISTRRED_FAIL_TO_CLOUD
245 } ESEnrolleeState, ProvStatus;
246
247 /**
248  * @brief Indicate last error code to describe a reason of error during easy setup.
249  */
250 typedef enum
251 {
252     /**
253      * Init Error Code
254      */
255     ES_ERRCODE_NO_ERROR = 0,
256
257     /**
258     * Error Code that given WiFi's SSID is not found
259     */
260     ES_ERRCODE_SSID_NOT_FOUND,
261
262     /**
263     * Error Code that given WiFi's Password is wrong
264     */
265     ES_ERRCODE_PW_WRONG,
266
267     /**
268     * Error Code that IP address is not allocated
269     */
270     ES_ERRCODE_IP_NOT_ALLOCATED,
271
272     /**
273     * Error Code that there is no Internet connection
274     */
275     ES_ERRCODE_NO_INTERNETCONNECTION,
276
277     /**
278     * Error Code that Timeout occured
279     */
280     ES_ERRCODE_TIMEOUT,
281
282     /**
283     * Error Code that Unknown error occured
284     */
285     ES_ERRCODE_UNKNOWN
286 } ESErrorCode;
287
288 #ifdef __cplusplus
289 }
290 #endif
291
292 #endif //ES_COMMON_H_