Merge "Merge branch 'easysetup'"
[platform/upstream/iotivity.git] / service / easy-setup / inc / 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 <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 #define ES_PS_TRIGGER_INIT_VALUE        0
70 #define ES_PS_TRIGGER_CONNECTION        1
71
72
73 /**
74 * Device Roles defined for each device type used in easy setup
75 */
76 typedef enum
77 {
78     ENROLLEE,
79     MEDIATOR,
80     ENROLLER,
81 } DeviceRole;
82
83 /**
84 * On-boarding connection to create Adhoc network.
85 */
86 typedef enum
87 {
88     SOFTAP,
89     BLE,
90 } OBConnection;
91
92 typedef enum
93 {
94     ES_ERROR = -1,
95     ES_OK = 0,
96     ES_NETWORKFOUND = 1,
97     ES_NETWORKCONNECTED,
98     ES_NETWORKNOTCONNECTED,
99     ES_RESOURCECREATED = 11,
100     ES_RECVREQOFPROVRES = 21,
101     ES_RECVREQOFNETRES,
102     ES_RECVUPDATEOFPROVRES,
103     ES_RECVTRIGGEROFPROVRES,
104 } ESResult;
105
106 typedef enum
107 {
108     /**
109      * Default state of the device
110      */
111     ES_INIT_STATE,
112
113     /**
114      * Device will move to this state once the on boarding begins
115      */
116     ES_ON_BOARDING_STATE,
117
118     /**
119      * Device will move to this state after successful on-boarding of the device
120      */
121     ES_ON_BOARDED_STATE,
122
123     /**
124      * Device will move to this state once the on boarding is done
125      */
126     ES_PROVISIONING_STATE,
127
128     /**
129      * Easy setup process is successful.
130      */
131     ES_PROVISIONED_STATE,
132
133     /**
134      * This state is arbitrary one, any time device can come into this state
135      * Device will move to this state if the ownership transfer initiated  by the Application
136      */
137     ES_OWNERSHIP_TRANSFERRING_STATE,
138
139     /**
140      * This state is arbitrary one, any time device can come into this state
141      * Device will move to this state if the ownership transfer is completed
142      */
143     ES_OWNERSHIP_TRANSFERRED_STATE,
144
145     /**
146      * This state is arbitrary one, any time device can come into this state
147      * Device will move to this state once the Application factory reset the device
148      */
149     ES_FACTORY_RESET_STATE,
150
151     /**
152      * Enrollee moves to this state after connecting to target network
153      */
154     ES_ON_BOARDED_TARGET_NETWORK_STATE,
155 }EnrolleeState;
156
157 /**
158  * Provisioning Device Status
159  */
160 typedef struct
161 {
162     // Address of remote server
163     OCDevAddr * addr;
164     // Indicates adaptor type on which the response was received
165     OCConnectivityType connType;
166 } EasySetupDeviceInfo;
167
168 /**
169  * Provosioning Status
170  */
171 typedef enum
172 {
173     DEVICE_PROVISIONED = 0,
174     DEVICE_NOT_PROVISIONED,
175     DEVICE_OWNED,
176     DEVICE_NOT_OWNED
177 } EasySetupState, ProvStatus;
178
179 /**
180  * Response from queries to remote servers.
181  */
182 typedef struct
183 {
184     // EasySetup Status
185     EasySetupState provStatus;
186     // EasySetup Device Info
187     EasySetupDeviceInfo provDeviceInfo;
188 } EasySetupInfo, ProvisioningInfo;
189
190 /**
191  * @brief  Network information of the Enroller
192  */
193 typedef union
194 {
195     /**
196      * @brief BT Mac Information
197      */
198     struct
199     {
200         char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
201     } BT;
202
203     /**
204      * @brief LE MAC Information
205      */
206     struct
207     {
208         char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
209     } LE;
210
211     /**
212      * @brief IP Information
213      */
214     struct
215     {
216         char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
217         char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
218     } WIFI;
219 } ProvData;
220
221 /**
222  * @brief Network Information
223  */
224 typedef struct
225 {
226     ProvData provData;    /**< Enroller Network Info**/
227     OCConnectivityType connType;    /**< Connectivity Type**/
228 } ProvConfig;
229
230 /**
231  * Client applications implement this callback to consume responses received from Servers.
232  */
233 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
234
235 /**
236  * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
237 */
238
239
240 // Note : Below structure is not currently used but added for future purpose.
241 typedef struct {
242     char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
243     char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
244     bool isSecured;                 /**< Secure connection**/
245 }WiFiOnboardingConfig;
246
247 /**
248  * @brief This structure represent onboarding connection instance.
249 */
250 typedef struct {
251  /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
252     device identification should be based on DeviceID in next release.*/
253    char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
254    bool isSecured;                 /**< Secure connection**/
255 }WiFiOnboadingConnection;
256
257 #endif //ES_COMMON_H_