7acf8b14053db7bafb6fa124a6a77d0a672a9683
[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_TRIGGER                              "tr"
44 #define OC_RSRVD_ES_SSID                                     "tnn"
45 #define OC_RSRVD_ES_CRED                                   "cd"
46 #define OC_RSRVD_ES_SUPPORTEDWIFIMODE       "swmt"
47 #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ        "swf"
48 #define OC_RSRVD_ES_AUTHTYPE                          "wat"
49 #define OC_RSRVD_ES_ENCTYPE                             "wet"
50 #define OC_RSRVD_ES_AUTHCODE                         "ac"
51 #define OC_RSRVD_ES_AUTHPROVIDER                  "apn"
52 #define OC_RSRVD_ES_CISERVER                            "cisurl"
53 #define OC_RSRVD_ES_DEVNAME                            "dn"
54 #define OC_RSRVD_ES_LANGUAGE                          "lang"
55 #define OC_RSRVD_ES_COUNTRY                            "cont"
56 #define OC_RSRVD_ES_TNT                                      "tnt"
57 #define OC_RSRVD_ES_ANT                                     "ant"
58
59 /**
60  * Easysetup defined resoruce types and uris.
61  */
62 #define OC_RSRVD_ES_PROV_RES_TYPE                 "ocf.r.prov"
63 #define OC_RSRVD_ES_URI_PROV                           "/.well-known/ocf/prov"
64 #define OC_RSRVD_ES_RES_TYPE_WIFI                   "ocf.r.wifi"
65 #define OC_RSRVD_ES_URI_WIFI                             "/.well-known/ocf/prov/wifi"
66 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
67 #define OC_RSRVD_ES_URI_CLOUDSERVER            "/.well-known/ocf/prov/cloudserver"
68 #define OC_RSRVD_ES_RES_TYPE_DEVCONF          "ocf.r.devconf"
69 #define OC_RSRVD_ES_URI_DEVCONF                    "/.well-known/ocf/prov/devconf"
70
71 /**
72  * @brief Defines for Provisioning status accepted values
73  */
74 #define ES_PS_NEED_PROVISIONING         1
75 #define ES_PS_PROVISIONING_COMPLETED    2
76 #define ES_PS_TRIGGER_INIT_VALUE        0
77 #define ES_PS_TRIGGER_CONNECTION        1
78
79 #ifndef WITH_ARDUINO
80 namespace OIC
81 {
82     namespace Service
83     {
84         typedef enum
85         {
86             ES_ERROR = -1,
87             ES_OK = 0,
88             ES_NETWORKFOUND = 1,
89             ES_NETWORKCONNECTED,
90             ES_NETWORKNOTCONNECTED,
91             ES_RESOURCECREATED = 11,
92             ES_RECVREQOFPROVRES = 21,
93             ES_RECVREQOFNETRES,
94             ES_RECVUPDATEOFPROVRES,
95             ES_RECVTRIGGEROFPROVRES,
96             ES_UNAUTHORIZED = 31
97         } ESResult;
98
99         /**
100          * @brief  WIFI Authentication tlype of the Enroller
101          */
102         typedef enum
103         {
104             NONE_AUTH = 0,
105             WEP,
106             WPA_PSK,
107             WPA2_PSK
108         } WIFI_AUTHTYPE;
109
110         /**
111          * @brief  WIFI ecnrytion type of the Enroller
112          */
113         typedef enum
114         {
115             NONE_ENC = 0,
116             WEP_64,
117             WEP_128,
118             TKIP,
119             AES,
120             TKIP_AES
121         } WIFI_ENCTYPE;
122
123         typedef enum
124         {
125             WIFI_24G = 0,
126             WIFI_5G,
127             WIFI_BOTH
128         } WIFI_FREQ;
129
130         typedef enum
131         {
132             WIFI_11A = 0,
133             WIFI_11B,
134             WIFI_11G,
135             WIFI_11N,
136             WIFI_11AC
137         } WIFI_MODE;
138
139         typedef struct
140         {
141             string authCode;
142             string authProvider;
143             string ciServer;
144         } CloudProvInfo;
145
146         typedef struct
147         {
148             struct
149             {
150                 string ssid; /**< ssid of the Enroller**/
151                 string pwd; /**< pwd of the Enroller**/
152                 WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
153                 WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
154             } WIFI;
155
156             struct
157             {
158                 string language;
159                 string country;
160             } Device;
161         } DataProvInfo;
162
163         typedef struct
164         {
165             string id;
166             string name;
167             string language;
168             string country;
169         } DeviceConfig;
170
171         typedef struct
172         {
173             vector<WIFI_MODE> types;
174             WIFI_FREQ freq;
175         } NetworkInfo;
176
177         typedef enum
178         {
179             ES_PROVISIONING_ERROR = -1,
180             ES_NEED_PROVISIONING,
181             ES_PROVISIONED_ALREADY,
182             ES_PROVISIONING_SUCCESS
183         } ESDataProvState;
184
185         typedef enum
186         {
187             ES_CLOUD_PROVISIONING_ERROR = -1,
188             ES_CLOUD_PROVISIONING_SUCCESS,
189             ES_CLOUD_ENROLLEE_FOUND,
190             ES_CLOUD_ENROLLEE_NOT_FOUND
191         }ESCloudProvState;
192
193         typedef enum
194         {
195             ES_SEC_UNKNOWN = 0,
196             ES_SEC_OWNED,
197             ES_SEC_ACL_PROVISIONED,
198             ES_SEC_CREDS_PROVISIONED
199         } EnrolleeSecState;
200
201         /**
202          * Security Provisioning Status
203          */
204         class SecProvisioningStatus
205         {
206         public:
207             SecProvisioningStatus(string deviceUUID, ESResult result) :
208                 m_devUUID(deviceUUID), m_result(result)
209             {
210             }
211
212             const string getDeviceUUID()
213             {
214                 return m_devUUID;
215             }
216
217             ESResult getESResult()
218             {
219                 return m_result;
220             }
221         private:
222             string m_devUUID;
223             ESResult m_result;
224         };
225
226         class PropertyData
227         {
228         public:
229             PropertyData()
230             {
231             }
232
233             PropertyData(DeviceConfig devConfig, NetworkInfo netInfo, bool cloudable) :
234                 m_devConfig(devConfig), m_netInfo(netInfo), m_cloudable(cloudable)
235             {
236             }
237
238             const DeviceConfig& getDevConf() const
239             {
240                 return m_devConfig;
241             }
242
243             const NetworkInfo& getNetInfo() const
244             {
245                 return m_netInfo;
246             }
247
248             const bool isCloudable() const
249             {
250                 return m_cloudable;
251             }
252
253         private:
254             DeviceConfig m_devConfig;
255             NetworkInfo m_netInfo;
256             bool m_cloudable;
257         };
258
259         class RequestPropertyDataStatus
260         {
261         public:
262             RequestPropertyDataStatus(ESResult result, const PropertyData& data) :
263                     m_result(result), m_propertyData(data)
264             {
265             }
266
267             ESResult getESResult()
268             {
269                 return m_result;
270             }
271
272             const PropertyData& getPropertyData()
273             {
274                 return m_propertyData;
275             }
276
277         private:
278             ESResult m_result;
279             PropertyData m_propertyData;
280         };
281
282         class DataProvisioningStatus
283         {
284         public:
285             DataProvisioningStatus(ESResult result, ESDataProvState dataProvState) :
286                     m_result(result), m_state(dataProvState)
287             {
288             }
289
290             ESResult getESResult()
291             {
292                 return m_result;
293             }
294
295             ESDataProvState getESDataProvState()
296             {
297                 return m_state;
298             }
299
300         private:
301             ESResult m_result;
302             ESDataProvState m_state;
303         };
304
305         class CloudProvisioningStatus
306         {
307         public:
308             CloudProvisioningStatus(ESResult result, ESCloudProvState state) :
309                     m_result(result), m_esCloudState(state)
310             {
311             }
312
313             ESResult getESResult()
314             {
315                 return m_result;
316             }
317
318             ESCloudProvState getESCloudState()
319             {
320                 return m_esCloudState;
321             }
322
323         private:
324             ESResult m_result;
325             ESCloudProvState m_esCloudState;
326         };
327
328         /**
329          * Callback function definition for providing Enrollee security status .
330          */
331         typedef function< void(shared_ptr< RequestPropertyDataStatus >) > RequestPropertyDataStatusCb;
332
333         /**
334          * Callback function definition for providing Enrollee security status .
335          */
336         typedef function< void(shared_ptr< DataProvisioningStatus >) > DataProvStatusCb;
337
338         /**
339          * Callback function definition for providing Enrollee security status .
340          */
341         typedef function< void(shared_ptr< CloudProvisioningStatus >) > CloudProvStatusCb;
342
343         /**
344          * Callback function definition for providing Enrollee security status .
345          */
346         typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
347
348         /**
349          * Callback definition to be invoked when the security stack expects a pin from application.
350          */
351         typedef function< void(string&) > SecurityPinCb;
352
353         /**
354          * Callback definition to be invoked when the stack expects a db path.
355          */
356         typedef function< void(string&) > SecProvisioningDbPathCb;
357
358     }
359 }
360 #endif //WITH_ARDUINO
361
362 #endif //ES_COMMON_RICH_H_