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