Merge branch 'master' into extended-easysetup
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / inc / ESRichCommon.h
1 //******************************************************************
2 //
3 // Copyright 2016 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_RICH_H_
22 #define ES_COMMON_RICH_H_
23
24 #include <iostream>
25 #include <string>
26 #ifndef WITH_ARDUINO
27 #include <memory>
28 #include <vector>
29 #endif
30
31 #include "ocstack.h"
32 #include "octypes.h"
33
34 using namespace std;
35
36 // Defines
37 #define IP_PORT                 55555
38
39 /**
40  * Attributes used to form a proper easysetup conforming JSON message
41  */
42 #define OC_RSRVD_ES_PROVSTATUS             "ps"
43 #define OC_RSRVD_ES_LAST_ERRORCODE         "lec"
44 #define OC_RSRVD_ES_LINKS                  "links"
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                "ctry"
57
58 /**
59  * Easysetup defined resoruce types and uris
60  */
61 #define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.wk.prov"
62 #define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
63 #define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.wk.wifi"
64 #define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
65 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.wk.cloudserver"
66 #define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
67 #define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.wk.devconf"
68 #define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
69
70 #ifndef WITH_ARDUINO
71 namespace OIC
72 {
73     namespace Service
74     {
75         typedef enum
76         {
77             ES_ERROR = -1,
78             ES_OK = 0,
79             ES_NETWORKFOUND = 1,
80             ES_NETWORKCONNECTED,
81             ES_NETWORKNOTCONNECTED,
82             ES_RESOURCECREATED = 11,
83             ES_RECVREQOFPROVRES = 21,
84             ES_RECVREQOFNETRES,
85             ES_RECVUPDATEOFPROVRES,
86             ES_RECVTRIGGEROFPROVRES,
87             ES_UNAUTHORIZED = 31
88         } ESResult;
89
90         /**
91          * @brief  WIFI Authentication tlype of the Enroller
92          */
93         typedef enum
94         {
95             NONE_AUTH = 0,
96             WEP,
97             WPA_PSK,
98             WPA2_PSK
99         } WIFI_AUTHTYPE;
100
101         /**
102          * @brief  WIFI encryption type of the Enroller
103          */
104         typedef enum
105         {
106             NONE_ENC = 0,
107             WEP_64,
108             WEP_128,
109             TKIP,
110             AES,
111             TKIP_AES
112         } WIFI_ENCTYPE;
113
114         typedef enum
115         {
116             WIFI_24G = 0,
117             WIFI_5G,
118             WIFI_BOTH
119         } WIFI_FREQ;
120
121         typedef enum
122         {
123             WIFI_11A = 0,
124             WIFI_11B,
125             WIFI_11G,
126             WIFI_11N,
127             WIFI_11AC
128         } WIFI_MODE;
129
130         typedef struct
131         {
132             string authCode;
133             string authProvider;
134             string ciServer;
135         } CloudProp;
136
137         typedef struct
138         {
139             struct
140             {
141                 string ssid; /**< ssid of the Enroller**/
142                 string pwd; /**< pwd of the Enroller**/
143                 WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
144                 WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
145             } WIFI;
146
147             struct
148             {
149                 string language;
150                 string country;
151             } Device;
152         } DeviceProp;
153
154         typedef struct
155         {
156             string name;
157             string language;
158             string country;
159         } DeviceConfig;
160
161         typedef struct
162         {
163             vector<WIFI_MODE> types;
164             WIFI_FREQ freq;
165         } WiFiConfig;
166
167         typedef enum
168         {
169             ES_PROVISIONING_ERROR = -1,
170             ES_NEED_PROVISIONING,
171             ES_PROVISIONED_ALREADY,
172             ES_PROVISIONING_SUCCESS
173         } ESDeviceProvState;
174
175         typedef enum
176         {
177             ES_CLOUD_PROVISIONING_ERROR = -1,
178             ES_CLOUD_PROVISIONING_SUCCESS,
179             ES_CLOUD_ENROLLEE_FOUND,
180             ES_CLOUD_ENROLLEE_NOT_FOUND
181         }ESCloudProvState;
182
183
184         /**
185          * Security Provisioning Status
186          */
187         class SecProvisioningStatus
188         {
189         public:
190             SecProvisioningStatus(string deviceUUID, ESResult result) :
191                 m_devUUID(deviceUUID), m_result(result)
192             {
193             }
194
195             const string getDeviceUUID()
196             {
197                 return m_devUUID;
198             }
199
200             ESResult getESResult()
201             {
202                 return m_result;
203             }
204         private:
205             string m_devUUID;
206             ESResult m_result;
207         };
208
209         class EnrolleeConf
210         {
211         public:
212             EnrolleeConf()
213             {
214             }
215
216             EnrolleeConf(DeviceConfig devConfig, WiFiConfig wifiConfig, bool cloudable) :
217                 m_devConfig(devConfig), m_wifiConfig(wifiConfig), m_cloudable(cloudable)
218             {
219             }
220
221             const DeviceConfig& getDevConf() const
222             {
223                 return m_devConfig;
224             }
225
226             const WiFiConfig& getWiFiConf() const
227             {
228                 return m_wifiConfig;
229             }
230
231             bool isCloudable() const
232             {
233                 return m_cloudable;
234             }
235
236         private:
237             DeviceConfig m_devConfig;
238             WiFiConfig m_wifiConfig;
239             bool m_cloudable;
240         };
241
242         class GetConfigurationStatus
243         {
244         public:
245             GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
246                     m_result(result), m_enrolleeConf(conf)
247             {
248             }
249
250             ESResult getESResult()
251             {
252                 return m_result;
253             }
254
255             const EnrolleeConf& getEnrolleeConf()
256             {
257                 return m_enrolleeConf;
258             }
259
260         private:
261             ESResult m_result;
262             EnrolleeConf m_enrolleeConf;
263         };
264
265         class DevicePropProvisioningStatus
266         {
267         public:
268             DevicePropProvisioningStatus(ESResult result) :
269                     m_result(result)
270             {
271             }
272
273             ESResult getESResult()
274             {
275                 return m_result;
276             }
277
278
279         private:
280             ESResult m_result;
281         };
282
283         class CloudPropProvisioningStatus
284         {
285         public:
286             CloudPropProvisioningStatus(ESResult result, ESCloudProvState state) :
287                     m_result(result), m_esCloudState(state)
288             {
289             }
290
291             ESResult getESResult()
292             {
293                 return m_result;
294             }
295
296             ESCloudProvState getESCloudState()
297             {
298                 return m_esCloudState;
299             }
300
301         private:
302             ESResult m_result;
303             ESCloudProvState m_esCloudState;
304         };
305
306         /**
307          * Callback function definition for providing Enrollee security status
308          */
309         typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
310
311         /**
312          * Callback function definition for providing Enrollee security status
313          */
314         typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
315
316         /**
317          * Callback function definition for providing Enrollee security status
318          */
319         typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
320
321         /**
322          * Callback function definition for providing Enrollee security status
323          */
324         typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
325
326         /**
327          * Callback definition to be invoked when the security stack expects a pin from application
328          */
329         typedef function< void(string&) > SecurityPinCb;
330
331         /**
332          * Callback definition to be invoked when the stack expects a db path
333          */
334         typedef function< void(string&) > SecProvisioningDbPathCb;
335
336     }
337 }
338 #endif //WITH_ARDUINO
339
340 #endif //ES_COMMON_RICH_H_