Merge branch 'master' into extended-easysetup
[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              "/.well-known/ocf/prov"
67 #define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.wk.wifi"
68 #define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
69 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.wk.cloudserver"
70 #define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
71 #define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.wk.devconf"
72 #define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
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 typedef enum
82 {
83     WiFi_11A = 0,
84     WiFi_11B,
85     WiFi_11G,
86     WiFi_11N,
87     WiFi_11AC,
88     WiFi_EOF = 999,
89 } WIFI_MODE;
90
91 typedef enum
92 {
93     WiFi_24G = 0,
94     WiFi_5G,
95     WiFi_BOTH
96 } WIFI_FREQ;
97
98 typedef enum
99 {
100     NONE_AUTH = 0,
101     WEP,
102     WPA_PSK,
103     WPA2_PSK
104 } WIFI_AUTHTYPE;
105
106 typedef enum
107 {
108     NONE_ENC = 0,
109     WEP_64,
110     WEP_128,
111     TKIP,
112     AES,
113     TKIP_AES
114 } WIFI_ENCTYPE;
115
116 typedef enum
117 {
118     ES_ERROR = -1,
119     ES_OK = 0,
120     ES_NETWORKFOUND = 1,
121     ES_NETWORKCONNECTED,
122     ES_NETWORKNOTCONNECTED,
123     ES_RESOURCECREATED = 11,
124     ES_RECVREQOFPROVRES = 21,
125     ES_RECVREQOFNETRES,
126     ES_RECVUPDATEOFPROVRES,
127     ES_RECVTRIGGEROFPROVRES,
128     ES_UNAUTHORIZED = 31
129 } ESResult;
130
131 typedef enum
132 {
133     ES_WIFI_RESOURCE = 0x01,
134     ES_CLOUD_RESOURCE = 0x02,
135     ES_DEVCONF_RESOURCE = 0x04
136 } ESResourceMask;
137
138 typedef struct
139 {
140     char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
141     char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
142     WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
143     WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
144 } ESWiFiProvData;
145
146 typedef struct
147 {
148     char language[OIC_STRING_MAX_VALUE];
149     char country[OIC_STRING_MAX_VALUE];
150 } ESDevConfProvData;
151
152 typedef struct
153 {
154     char authCode[OIC_STRING_MAX_VALUE];
155     char authProvider[OIC_STRING_MAX_VALUE];
156     char ciServer[OIC_STRING_MAX_VALUE];
157     char serverID[OIC_STRING_MAX_VALUE];
158 } ESCloudProvData;
159
160 typedef struct
161 {
162     struct
163     {
164         WIFI_MODE mode[NUM_WIFIMODE];
165         WIFI_FREQ freq;
166     } WiFi;
167     struct
168     {
169         char deviceName[MAX_DEVICELEN];
170     } DevConf;
171 } ESDeviceProperty;
172
173 typedef enum
174 {
175     /**
176      * Default state of the device
177      */
178     ES_STATE_INIT = 0,
179
180     /**
181     * Status indicating being cnnecting to target network
182     */
183     ES_STATE_CONNECTING_TO_ENROLLER,
184
185     /**
186     * Status indicating successful conection to target network
187     */
188     ES_STATE_CONNECTED_TO_ENROLLER,
189
190     /**
191     * Status indicating failure connection to target network
192     */
193     ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
194
195     /**
196     * Status indicating successful registration to cloud
197     */
198     ES_STATE_REGISTERED_TO_CLOUD,
199
200     /**
201     * Status indicating failure registeration to cloud
202     */
203     ES_STATE_REGISTRRED_FAIL_TO_CLOUD
204 } ESEnrolleeState, ProvStatus;
205
206 typedef enum
207 {
208     /**
209      * Init Error Code
210      */
211     ES_ERRCODE_NO_ERROR = 0,
212
213     /**
214     * Error Code that given WiFi's SSID is not found
215     */
216     ES_ERRCODE_SSID_NOT_FOUND,
217
218     /**
219     * Error Code that given WiFi's Password is wrong
220     */
221     ES_ERRCODE_PW_WRONG,
222
223     /**
224     * Error Code that IP address is not allocated
225     */
226     ES_ERRCODE_IP_NOT_ALLOCATED,
227
228     /**
229     * Error Code that there is no Internet connection
230     */
231     ES_ERRCODE_NO_INTERNETCONNECTION,
232
233     /**
234     * Error Code that Timeout occured
235     */
236     ES_ERRCODE_TIMEOUT,
237
238     /**
239     * Error Code that Unknown error occured
240     */
241     ES_ERRCODE_UNKNOWN
242 } ESErrorCode;
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif //ES_COMMON_H_