SVACE issue fix and renaming of files as per naming standards
[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 #endif
29
30 #include "ocstack.h"
31 #include "octypes.h"
32
33 using namespace std;
34
35 // Defines
36 #define OIC_STRING_MAX_VALUE    100
37 #define IPV4_ADDR_SIZE          16
38 #define IP_PORT                 55555
39 #define NET_WIFI_SSID_SIZE      100
40 #define NET_WIFI_PWD_SIZE       100
41
42 /**
43  * @brief Mac address length for BT port
44  */
45 #define NET_MACADDR_SIZE 18
46
47 /**
48  * Attributes used to form a proper easysetup conforming JSON message.
49  */
50 #define OC_RSRVD_ES_PS                     "ps"
51 #define OC_RSRVD_ES_TNN                    "tnn"
52 #define OC_RSRVD_ES_CD                     "cd"
53 #define OC_RSRVD_ES_TR                     "tr"
54 #define OC_RSRVD_ES_TNT                    "tnt"
55 #define OC_RSRVD_ES_ANT                    "ant"
56
57 /**
58  * Easysetup defined resoruce types and uris.
59  */
60 #define OC_RSRVD_ES_PROV_RES_TYPE           "oic.r.prov"
61 #define OC_RSRVD_ES_URI_PROV               "/oic/prov"
62 #define OC_RSRVD_ES_URI_NET                "/oic/net"
63
64 /**
65  * @brief Defines for Provisioning status accepted values
66  */
67 #define ES_PS_NEED_PROVISIONING         1
68 #define ES_PS_PROVISIONING_COMPLETED    2
69
70 #ifndef WITH_ARDUINO
71 namespace OIC
72 {
73     namespace Service
74     {
75
76         /**
77         * Device Roles defined for each device type used in easy setup
78         */
79         typedef enum
80         {
81             ENROLLEE,
82             MEDIATOR,
83             ENROLLER,
84         } DeviceRole;
85
86         /**
87         * On-boarding connection to create Adhoc network.
88         */
89         typedef enum
90         {
91             SOFTAP,
92             BLE,
93         } OBConnection;
94
95         typedef enum
96         {
97             ES_ERROR = -1,
98             ES_OK = 0,
99             ES_NETWORKFOUND = 1,
100             ES_NETWORKCONNECTED,
101             ES_NETWORKNOTCONNECTED,
102             ES_RESOURCECREATED = 11,
103             ES_RECVREQOFPROVRES = 21,
104             ES_RECVREQOFNETRES,
105             ES_RECVUPDATEOFPROVRES,
106             ES_RECVTRIGGEROFPROVRES,
107         } ESResult;
108
109         typedef enum
110         {
111             /**
112              * Default state of the device
113              */
114             ES_INIT_STATE,
115
116             /**
117              * Device will move to this state once the on boarding begins
118              */
119             ES_ON_BOARDING_STATE,
120
121             /**
122              * Device will move to this state after successful on-boarding of the device
123              */
124             ES_ON_BOARDED_STATE,
125
126             /**
127              * Device will move to this state once the on boarding is done
128              */
129             ES_PROVISIONING_STATE,
130
131             /**
132              * Easy setup process is successful.
133              */
134             ES_PROVISIONED_STATE,
135
136             /**
137              * This state is arbitrary one, any time device can come into this state
138              * Device will move to this state if the ownership transfer initiated  by the Application
139              */
140             ES_OWNERSHIP_TRANSFERRING_STATE,
141
142             /**
143              * This state is arbitrary one, any time device can come into this state
144              * Device will move to this state if the ownership transfer is completed
145              */
146             ES_OWNERSHIP_TRANSFERRED_STATE,
147
148             /**
149              * This state is arbitrary one, any time device can come into this state
150              * Device will move to this state once the Application factory reset the device
151              */
152             ES_FACTORY_RESET_STATE,
153
154             /**
155              * Enrollee moves to this state after connecting to target network
156              */
157             ES_ON_BOARDED_TARGET_NETWORK_STATE,
158         }EnrolleeState;
159
160         /**
161          * Provisioning Device Status
162          */
163         typedef struct
164         {
165             // Address of remote server
166             OCDevAddr * addr;
167             // Indicates adaptor type on which the response was received
168             OCConnectivityType connType;
169         } EasySetupDeviceInfo;
170
171         /**
172          * Provosioning Status
173          */
174         typedef enum
175         {
176             DEVICE_PROVISIONED = 0,
177             DEVICE_NOT_PROVISIONED,
178             DEVICE_OWNED,
179             DEVICE_NOT_OWNED
180         } EasySetupState, ProvStatus;
181
182         /**
183          * Response from queries to remote servers.
184          */
185         typedef struct
186         {
187             // EasySetup Status
188             EasySetupState provStatus;
189             // EasySetup Device Info
190             EasySetupDeviceInfo provDeviceInfo;
191         } EasySetupInfo, ProvisioningInfo;
192
193         /**
194          * @brief  Network information of the Enroller
195          */
196         typedef union
197         {
198             /**
199              * @brief BT Mac Information
200              */
201             struct
202             {
203                 char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
204             } BT;
205
206             /**
207              * @brief LE MAC Information
208              */
209             struct
210             {
211                 char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
212             } LE;
213
214             /**
215              * @brief IP Information
216              */
217             struct
218             {
219                 char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
220                 char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
221             } WIFI;
222         } ProvData;
223
224         /**
225          * @brief Network Information
226          */
227         typedef struct
228         {
229             ProvData provData;    /**< Enroller Network Info**/
230             OCConnectivityType connType;    /**< Connectivity Type**/
231         } ProvConfig;
232
233         /**
234          * Client applications implement this callback to consume responses received from Servers.
235          */
236         typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
237
238         /**
239          * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
240         */
241
242         // Note : Below structure is not currently used but added for future purpose.
243         typedef struct
244         {
245             char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
246             char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
247             bool isSecured;                 /**< Secure connection**/
248         }WiFiOnboardingConfig;
249
250         /**
251          * @brief This structure represent onboarding connection instance.
252         */
253         typedef struct
254         {
255          /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
256             device identification should be based on DeviceID in next release.*/
257            char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
258            bool isSecured;                 /**< Secure connection**/
259         }WiFiOnboadingConnection;
260
261         typedef enum
262         {
263             ES_PROVISIONING_ERROR = -1,
264             ES_NEED_PROVISIONING,
265             ES_PROVISIONED_ALREADY,
266             ES_PROVISIONING_SUCCESS
267         } ESState;
268
269         typedef enum
270         {
271             ES_UNKNOWN = 0,
272             ES_ONBOARDED,
273             ES_OWNED,
274             ES_PROVISIONED
275         } CurrentESState;
276
277         typedef enum
278         {
279             ES_SEC_UNKNOWN = 0,
280             ES_SEC_OWNED,
281             ES_SEC_ACL_PROVISIONED,
282             ES_SEC_CREDS_PROVISIONED
283         } EnrolleeSecState;
284
285         /**
286          * Security Provisioning Status
287          */
288         class SecProvisioningResult
289         {
290         public:
291             std::shared_ptr< SecProvisioningResult > shared_ptr;
292             SecProvisioningResult(std::string deviceUUID, ESResult result) :
293                 m_devUUID(deviceUUID), m_result(result)
294             {
295
296             }
297
298             std::string getDeviceUUID()
299             {
300                 return m_devUUID;
301             }
302
303             ESResult getResult()
304             {
305                 return m_result;
306             }
307         private:
308             std::string m_devUUID;
309             ESResult m_result;
310         };
311
312         /**
313          * Callback function definition for providing Enrollee security status .
314          */
315         typedef std::function< void(std::shared_ptr<SecProvisioningResult>) > EnrolleeSecStatusCb;
316
317         /**
318          * Callback definition to be invoked when the security stack expects a pin from application.
319          */
320         typedef std::function< void(std::string&) > SecurityPinCb;
321
322         /**
323          * Callback definition to be invoked when the stack expects a db path.
324          */
325         typedef std::function< void(std::string&) > SecProvisioningDbPathCb;
326
327         class ProvisioningStatus
328         {
329         public:
330             std::shared_ptr< ProvisioningStatus > shared_ptr;
331             ProvisioningStatus(ESResult result, ESState esState) :
332                     m_result(result), m_esState(esState)
333             {
334
335             }
336
337             ESResult getESResult()
338             {
339                 return m_result;
340             }
341
342             ESState getESState()
343             {
344                 return m_esState;
345             }
346         private:
347             ESResult m_result;
348             ESState m_esState;
349         };
350
351         class EasySetupStatus
352         {
353         public:
354             std::shared_ptr< EasySetupStatus > shared_ptr;
355             EasySetupStatus(const EasySetupState& easySetupState,
356                     const ProvConfig& provConfig) :
357                     m_easySetupState(easySetupState), m_ProvConfig(provConfig)
358             {
359
360             }
361
362             ProvConfig getProvConfig()
363             {
364                 return m_ProvConfig;
365             }
366
367             EasySetupState getEasySetupState()
368             {
369                 return m_easySetupState;
370             }
371         private:
372             EasySetupState m_easySetupState;
373             ProvConfig m_ProvConfig;
374         };
375     }
376 }
377 #endif //WITH_ARDUINO
378
379 #endif //ES_COMMON_RICH_H_