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