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