Update resource models of easy setup in Enrollee side
[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_PROVSTATUS             "ps"
43 #define OC_RSRVD_ES_ERRORCODE              "ec"
44 #define OC_RSRVD_ES_TRIGGER                "tr"
45 #define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
46 #define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
47 #define OC_RSRVD_ES_SSID                   "tnn"
48 #define OC_RSRVD_ES_CRED                   "cd"
49 #define OC_RSRVD_ES_AUTHTYPE               "wat"
50 #define OC_RSRVD_ES_ENCTYPE                "wet"
51 #define OC_RSRVD_ES_AUTHCODE               "ac"
52 #define OC_RSRVD_ES_AUTHPROVIDER           "apn"
53 #define OC_RSRVD_ES_CISERVER               "cisurl"
54 #define OC_RSRVD_ES_DEVNAME                "dn"
55 #define OC_RSRVD_ES_LANGUAGE               "lang"
56 #define OC_RSRVD_ES_COUNTRY                "cont"
57
58 /**
59  * Easysetup defined resoruce types and uris.
60  */
61 #define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.r.prov"
62 #define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
63 #define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.r.wifi"
64 #define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
65 #define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
66 #define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
67 #define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.r.devconf"
68 #define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
69
70 #define OC_RSRVD_ES_URI_NET               "/oic/net"
71
72 #define NUM_WIFIMODE    10
73
74 typedef enum
75 {
76     NO_PROVISION = 0,
77     CONNECTED_ENROLLER,
78     FAILED_CONNECTION
79 } PROV_STATUS;
80
81 typedef enum
82 {
83     WiFi_11A = 0,
84     WiFi_11B,
85     WiFi_11G,
86     WiFi_11N,
87     WiFi_11AC
88 } WIFI_MODE;
89
90 typedef enum
91 {
92     WiFi_24G = 0,
93     WiFi_5G,
94     WiFi_BOTH
95 } WIFI_FREQ;
96
97 typedef enum
98 {
99     NONE_AUTH = 0,
100     WEP,
101     WPA_PSK,
102     WPA2_PSK
103 } WIFI_AUTHTYPE;
104
105 typedef enum
106 {
107     NONE_ENC = 0,
108     WEP_64,
109     WEP_128,
110     TKIP,
111     AES,
112     TKIP_AES
113 } WIFI_ENCTYPE;
114
115 /**
116 * Device Roles defined for each device type used in easy setup
117 */
118 typedef enum
119 {
120     ENROLLEE,
121     MEDIATOR,
122     ENROLLER,
123 } DeviceRole;
124
125 /**
126 * On-boarding connection to create Adhoc network.
127 */
128 typedef enum
129 {
130     SOFTAP,
131     BLE,
132 } OBConnection;
133
134 typedef enum
135 {
136     ES_ERROR = -1,
137     ES_OK = 0,
138     ES_NETWORKFOUND = 1,
139     ES_NETWORKCONNECTED,
140     ES_NETWORKNOTCONNECTED,
141     ES_RESOURCECREATED = 11,
142     ES_RECVREQOFPROVRES = 21,
143     ES_RECVREQOFNETRES,
144     ES_RECVUPDATEOFPROVRES,
145     ES_RECVTRIGGEROFPROVRES,
146 } ESResult;
147
148 typedef enum
149 {
150     /**
151      * Default state of the device
152      */
153     ES_INIT_STATE,
154
155     /**
156      * Device will move to this state once the on boarding begins
157      */
158     ES_ON_BOARDING_STATE,
159
160     /**
161      * Device will move to this state after successful on-boarding of the device
162      */
163     ES_ON_BOARDED_STATE,
164
165     /**
166      * Device will move to this state once the on boarding is done
167      */
168     ES_PROVISIONING_STATE,
169
170     /**
171      * Easy setup process is successful.
172      */
173     ES_PROVISIONED_STATE,
174
175     /**
176      * This state is arbitrary one, any time device can come into this state
177      * Device will move to this state if the ownership transfer initiated  by the Application
178      */
179     ES_OWNERSHIP_TRANSFERRING_STATE,
180
181     /**
182      * This state is arbitrary one, any time device can come into this state
183      * Device will move to this state if the ownership transfer is completed
184      */
185     ES_OWNERSHIP_TRANSFERRED_STATE,
186
187     /**
188      * This state is arbitrary one, any time device can come into this state
189      * Device will move to this state once the Application factory reset the device
190      */
191     ES_FACTORY_RESET_STATE,
192
193     /**
194      * Enrollee moves to this state after connecting to target network
195      */
196     ES_ON_BOARDED_TARGET_NETWORK_STATE,
197 }ESEnrolleeState;
198
199 /**
200  * Provisioning Device Status
201  */
202 typedef struct
203 {
204     // Address of remote server
205     OCDevAddr * addr;
206     // Indicates adaptor type on which the response was received
207     OCConnectivityType connType;
208 } EasySetupDeviceInfo;
209
210 /**
211  * Provosioning Status
212  */
213 typedef enum
214 {
215     DEVICE_PROVISIONED = 0,
216     DEVICE_NOT_PROVISIONED,
217     DEVICE_OWNED,
218     DEVICE_NOT_OWNED
219 } EasySetupState, ProvStatus;
220
221 /**
222  * Response from queries to remote servers.
223  */
224 typedef struct
225 {
226     // EasySetup Status
227     EasySetupState provStatus;
228     // EasySetup Device Info
229     EasySetupDeviceInfo provDeviceInfo;
230 } EasySetupInfo, ProvisioningInfo;
231
232 /**
233  * @brief  Network information of the Enroller
234  */
235 typedef union
236 {
237     /**
238      * @brief BT Mac Information
239      */
240     struct
241     {
242         char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
243     } BT;
244
245     /**
246      * @brief LE MAC Information
247      */
248     struct
249     {
250         char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
251     } LE;
252
253     /**
254      * @brief IP Information
255      */
256     struct
257     {
258         char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
259         char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
260     } WIFI;
261 } ProvData;
262
263 /**
264  * @brief Network Information
265  */
266 typedef struct
267 {
268     ProvData provData;    /**< Enroller Network Info**/
269     OCConnectivityType connType;    /**< Connectivity Type**/
270 } ProvConfig;
271
272 /**
273  * Client applications implement this callback to consume responses received from Servers.
274  */
275 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
276
277 /**
278  * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
279 */
280
281
282 // Note : Below structure is not currently used but added for future purpose.
283 typedef struct {
284     char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
285     char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
286     bool isSecured;                 /**< Secure connection**/
287 }WiFiOnboardingConfig;
288
289 /**
290  * @brief This structure represent onboarding connection instance.
291 */
292 typedef struct {
293  /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
294     device identification should be based on DeviceID in next release.*/
295    char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
296    bool isSecured;                 /**< Secure connection**/
297 }WiFiOnboadingConnection;
298
299 #endif //ES_COMMON_H_