[Easy-Setup] Changed the enrollee's cpp files to c files
[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 "ocstack.h"
25 #include "octypes.h"
26
27 // Defines
28 #define OIC_STRING_MAX_VALUE    100
29 #define IPV4_ADDR_SIZE          16
30 #define IP_PORT                 55555
31 #define NET_WIFI_SSID_SIZE      100
32 #define NET_WIFI_PWD_SIZE       100
33
34 /**
35  * @brief Mac address length for BT port
36  */
37 #define NET_MACADDR_SIZE 18
38
39 /**
40  * Attributes used to form a proper easysetup conforming JSON message.
41  */
42 #define OC_RSRVD_ES_PS                     "ps"
43 #define OC_RSRVD_ES_TNN                    "tnn"
44 #define OC_RSRVD_ES_CD                     "cd"
45 #define OC_RSRVD_ES_TR                     "tr"
46 #define OC_RSRVD_ES_TNT                    "tnt"
47 #define OC_RSRVD_ES_ANT                    "ant"
48
49 /**
50  * Easysetup defined resoruce types and uris.
51  */
52 #define OC_RSRVD_ES_PROV_RES_TYPE           "oic.r.prov"
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 #define ES_PS_TRIGGER_INIT_VALUE        0
62 #define ES_PS_TRIGGER_CONNECTION        1
63
64
65 /**
66 * Device Roles defined for each device type used in easy setup
67 */
68 typedef enum
69 {
70     ENROLLEE,
71     MEDIATOR,
72     ENROLLER,
73 } DeviceRole;
74
75 /**
76 * On-boarding connection to create Adhoc network.
77 */
78 typedef enum
79 {
80     SOFTAP,
81     BLE,
82 } OBConnection;
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 } ESResult;
97
98 typedef enum
99 {
100     /**
101      * Default state of the device
102      */
103     ES_INIT_STATE,
104
105     /**
106      * Device will move to this state once the on boarding begins
107      */
108     ES_ON_BOARDING_STATE,
109
110     /**
111      * Device will move to this state after successful on-boarding of the device
112      */
113     ES_ON_BOARDED_STATE,
114
115     /**
116      * Device will move to this state once the on boarding is done
117      */
118     ES_PROVISIONING_STATE,
119
120     /**
121      * Easy setup process is successful.
122      */
123     ES_PROVISIONED_STATE,
124
125     /**
126      * This state is arbitrary one, any time device can come into this state
127      * Device will move to this state if the ownership transfer initiated  by the Application
128      */
129     ES_OWNERSHIP_TRANSFERRING_STATE,
130
131     /**
132      * This state is arbitrary one, any time device can come into this state
133      * Device will move to this state if the ownership transfer is completed
134      */
135     ES_OWNERSHIP_TRANSFERRED_STATE,
136
137     /**
138      * This state is arbitrary one, any time device can come into this state
139      * Device will move to this state once the Application factory reset the device
140      */
141     ES_FACTORY_RESET_STATE,
142
143     /**
144      * Enrollee moves to this state after connecting to target network
145      */
146     ES_ON_BOARDED_TARGET_NETWORK_STATE,
147 }EnrolleeState;
148
149 /**
150  * Provisioning Device Status
151  */
152 typedef struct
153 {
154     // Address of remote server
155     OCDevAddr * addr;
156     // Indicates adaptor type on which the response was received
157     OCConnectivityType connType;
158 } EasySetupDeviceInfo;
159
160 /**
161  * Provosioning Status
162  */
163 typedef enum
164 {
165     DEVICE_PROVISIONED = 0,
166     DEVICE_NOT_PROVISIONED,
167     DEVICE_OWNED,
168     DEVICE_NOT_OWNED
169 } EasySetupState, ProvStatus;
170
171 /**
172  * Response from queries to remote servers.
173  */
174 typedef struct
175 {
176     // EasySetup Status
177     EasySetupState provStatus;
178     // EasySetup Device Info
179     EasySetupDeviceInfo provDeviceInfo;
180 } EasySetupInfo, ProvisioningInfo;
181
182 /**
183  * @brief  Network information of the Enroller
184  */
185 typedef union
186 {
187     /**
188      * @brief BT Mac Information
189      */
190     struct
191     {
192         char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
193     } BT;
194
195     /**
196      * @brief LE MAC Information
197      */
198     struct
199     {
200         char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
201     } LE;
202
203     /**
204      * @brief IP Information
205      */
206     struct
207     {
208         char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
209         char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
210     } WIFI;
211 } ProvData;
212
213 /**
214  * @brief Network Information
215  */
216 typedef struct
217 {
218     ProvData provData;    /**< Enroller Network Info**/
219     OCConnectivityType connType;    /**< Connectivity Type**/
220 } ProvConfig;
221
222 /**
223  * Client applications implement this callback to consume responses received from Servers.
224  */
225 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
226
227 /**
228  * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
229 */
230
231
232 // Note : Below structure is not currently used but added for future purpose.
233 typedef struct {
234     char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
235     char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
236     bool isSecured;                 /**< Secure connection**/
237 }WiFiOnboardingConfig;
238
239 /**
240  * @brief This structure represent onboarding connection instance.
241 */
242 typedef struct {
243  /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
244     device identification should be based on DeviceID in next release.*/
245    char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
246    bool isSecured;                 /**< Secure connection**/
247 }WiFiOnboadingConnection;
248
249 #endif //ES_COMMON_H_