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 // Defines
28 #define OIC_STRING_MAX_VALUE    100
29 #define IPV4_ADDR_SIZE          16
30 #define IP_PORT                 55555
31
32 /**
33  * @brief Mac address length for BT port
34  */
35 #define NET_MACADDR_SIZE 18
36
37 /**
38  * Attributes used to form a proper easysetup conforming JSON message.
39  */
40 #define OC_RSRVD_ES_PROVSTATUS             "ps"
41 #define OC_RSRVD_ES_LAST_ERRORCODE         "lec"
42 #define OC_RSRVD_ES_ERRORMESSAGE           "em"
43 #define OC_RSRVD_ES_LINKS                  "links"
44 #define OC_RSRVD_ES_TRIGGER                "tr"
45 #define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
46 #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
47 #define OC_RSRVD_ES_SSID                   "tnn"
48 #define OC_RSRVD_ES_CRED                   "cd"
49 #define OC_RSRVD_ES_AUTHTYPE               "wat"
50 #define OC_RSRVD_ES_ENCTYPE                "wet"
51 #define OC_RSRVD_ES_AUTHCODE               "ac"
52 #define OC_RSRVD_ES_AUTHPROVIDER           "apn"
53 #define OC_RSRVD_ES_CISERVER               "cisurl"
54 #define OC_RSRVD_ES_DEVNAME                "dn"
55 #define OC_RSRVD_ES_LANGUAGE               "lang"
56 #define OC_RSRVD_ES_COUNTRY                "cont"
57
58 /**
59  * Easysetup defined resoruce types and uris.
60  */
61 #define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.r.prov"
62 #define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
63 #define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.r.wifi"
64 #define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
65 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
66 #define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
67 #define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.r.devconf"
68 #define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
69
70 #define NUM_WIFIMODE    10
71 #define MAX_SSIDLEN 33
72 #define MAX_CREDLEN 20
73
74 #define MAX_DEVICELEN 100
75 #define MAX_ERRMSGLEN 100
76 #define MAX_WEBLINKLEN 100
77
78 typedef enum
79 {
80     NO_PROVISION = 0,
81     CONNECTED_ENROLLER,
82     FAILED_CONNECTION
83 } PROV_STATUS;
84
85 typedef enum
86 {
87     WiFi_11A = 0,
88     WiFi_11B,
89     WiFi_11G,
90     WiFi_11N,
91     WiFi_11AC,
92     WiFi_EOF = 999,
93 } WIFI_MODE;
94
95 typedef enum
96 {
97     WiFi_24G = 0,
98     WiFi_5G,
99     WiFi_BOTH
100 } WIFI_FREQ;
101
102 typedef enum
103 {
104     NONE_AUTH = 0,
105     WEP,
106     WPA_PSK,
107     WPA2_PSK
108 } WIFI_AUTHTYPE;
109
110 typedef enum
111 {
112     NONE_ENC = 0,
113     WEP_64,
114     WEP_128,
115     TKIP,
116     AES,
117     TKIP_AES
118 } WIFI_ENCTYPE;
119
120 /**
121 * Device Roles defined for each device type used in easy setup
122 */
123 typedef enum
124 {
125     ENROLLEE,
126     MEDIATOR,
127     ENROLLER,
128 } DeviceRole;
129
130 /**
131 * On-boarding connection to create Adhoc network.
132 */
133 typedef enum
134 {
135     SOFTAP,
136     BLE,
137 } OBConnection;
138
139 typedef enum
140 {
141     ES_ERROR = -1,
142     ES_OK = 0,
143     ES_NETWORKFOUND = 1,
144     ES_NETWORKCONNECTED,
145     ES_NETWORKNOTCONNECTED,
146     ES_RESOURCECREATED = 11,
147     ES_RECVREQOFPROVRES = 21,
148     ES_RECVREQOFNETRES,
149     ES_RECVUPDATEOFPROVRES,
150     ES_RECVTRIGGEROFPROVRES,
151     ES_UNAUTHORIZED = 31
152 } ESResult;
153
154 typedef enum
155 {
156     ES_WIFI_RESOURCE = 0x01,
157     ES_CLOUD_RESOURCE = 0x02,
158     ES_DEVCONF_RESOURCE = 0x04
159 } ESResourceMask;
160
161 typedef struct
162 {
163     char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
164     char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
165     WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
166     WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
167 } ESWiFiProvData;
168
169 typedef struct
170 {
171     char language[OIC_STRING_MAX_VALUE];
172     char country[OIC_STRING_MAX_VALUE];
173 } ESDevConfProvData;
174
175 typedef struct
176 {
177     char authCode[OIC_STRING_MAX_VALUE];
178     char authProvider[OIC_STRING_MAX_VALUE];
179     char ciServer[OIC_STRING_MAX_VALUE];
180 } ESCloudProvData;
181
182 typedef struct
183 {
184     struct
185     {
186         WIFI_MODE mode[NUM_WIFIMODE];
187         WIFI_FREQ freq;
188     } WiFi;
189     struct
190     {
191         char deviceName[MAX_DEVICELEN];
192     } DevConf;
193 } ESDeviceProperty;
194
195 typedef enum
196 {
197     /**
198      * Default state of the device
199      */
200     ES_STATE_INIT = 1,
201
202     /**
203     * Status indicating successful cnnection to target network
204     */
205     ES_STATE_CONNECTED_TO_ENROLLER,
206
207     /**
208     * Status indicating failure connection to target network
209     */
210     ES_STATE_CONNECTED_FAIL_TO_ENROLLER,
211
212     /**
213     * Status indicating successful registration to cloud
214     */
215     ES_STATE_REGISTERED_TO_CLOUD,
216
217     /**
218     * Status indicating failure registeration to cloud
219     */
220     ES_STATE_REGISTRRED_FAIL_TO_CLOUD
221 } ESEnrolleeState;
222
223 typedef enum
224 {
225     /**
226     * Error Code that given WiFi's SSID is not found
227     */
228     ES_ERRCODE_SSID_NOT_FOUND = 1,
229
230     /**
231     * Error Code that given WiFi's Password is wrong
232     */
233     ES_ERRCODE_PW_WRONG,
234
235     /**
236     * Error Code that IP address is not allocated
237     */
238     ES_ERRCODE_IP_NOT_ALLOCATED,
239
240     /**
241     * Error Code that there is no Internet connection
242     */
243     ES_ERRCODE_NO_INTERNETCONNECTION,
244
245     /**
246     * Error Code that Timeout occured
247     */
248     ES_ERRCODE_TIMEOUT,
249
250     /**
251     * Error Code that Unknown error occured
252     */
253     ES_ERRCODE_UNKNOWN,
254
255     /**
256     * No Error Occured
257     */
258     ES_ERRCODE_NONE = 999
259 } ESErrorCode;
260
261 typedef struct
262 {
263     // Address of remote server
264     OCDevAddr * addr;
265     // Indicates adaptor type on which the response was received
266     OCConnectivityType connType;
267 } EasySetupDeviceInfo;
268
269 /**
270  * Provosioning Status
271  */
272 typedef enum
273 {
274     ES_NEED_PROVISION = 1,
275     ES_CONNECTED_TO_ENROLLER,
276     ES_CONNECTED_FAIL_TO_ENROLLER,
277     ES_REGISTERED_TO_CLOUD,
278     ES_REGISTERED_FAIL_TO_CLOUD
279 } EasySetupState, ProvStatus;
280
281 /**
282  * Response from queries to remote servers.
283  */
284 typedef struct
285 {
286     // EasySetup Status
287     EasySetupState provStatus;
288     // EasySetup Device Info
289     EasySetupDeviceInfo provDeviceInfo;
290 } EasySetupInfo, ProvisioningInfo;
291
292 /**
293  * @brief  Network information of the Enroller
294  */
295 typedef union
296 {
297     /**
298      * @brief BT Mac Information
299      */
300     struct
301     {
302         char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
303     } BT;
304
305     /**
306      * @brief LE MAC Information
307      */
308     struct
309     {
310         char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
311     } LE;
312
313     /**
314      * @brief IP Information
315      */
316     struct
317     {
318         char ssid[MAX_SSIDLEN]; /**< ssid of the Enroller**/
319         char pwd[MAX_CREDLEN]; /**< pwd of the Enroller**/
320     } WIFI;
321 } ProvData;
322
323 /**
324  * @brief Network Information
325  */
326 typedef struct
327 {
328     ProvData provData;    /**< Enroller Network Info**/
329     OCConnectivityType connType;    /**< Connectivity Type**/
330 } ProvConfig;
331
332 /**
333  * Client applications implement this callback to consume responses received from Servers.
334  */
335 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
336
337 /**
338  * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
339 */
340
341
342 // Note : Below structure is not currently used but added for future purpose.
343 typedef struct {
344     char ssid[MAX_SSIDLEN]; /**< ssid of the onboarding Adhoc Wifi network**/
345     char pwd[MAX_CREDLEN]; /**< pwd of the onboarding Adhoc wifi network**/
346     bool isSecured;                 /**< Secure connection**/
347 }WiFiOnboardingConfig;
348
349 /**
350  * @brief This structure represent onboarding connection instance.
351 */
352 typedef struct {
353  /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
354     device identification should be based on DeviceID in next release.*/
355    char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
356    bool isSecured;                 /**< Secure connection**/
357 }WiFiOnboadingConnection;
358
359
360 #endif //ES_COMMON_H_