[Enrollee] Implement ESInitEnrollee() API
[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 #define MAXSSIDLEN 33
74 #define MAXNETCREDLEN 20
75
76 typedef enum
77 {
78     NO_PROVISION = 0,
79     CONNECTED_ENROLLER,
80     FAILED_CONNECTION
81 } PROV_STATUS;
82
83 typedef enum
84 {
85     WiFi_11A = 0,
86     WiFi_11B,
87     WiFi_11G,
88     WiFi_11N,
89     WiFi_11AC
90 } WIFI_MODE;
91
92 typedef enum
93 {
94     WiFi_24G = 0,
95     WiFi_5G,
96     WiFi_BOTH
97 } WIFI_FREQ;
98
99 typedef enum
100 {
101     NONE_AUTH = 0,
102     WEP,
103     WPA_PSK,
104     WPA2_PSK
105 } WIFI_AUTHTYPE;
106
107 typedef enum
108 {
109     NONE_ENC = 0,
110     WEP_64,
111     WEP_128,
112     TKIP,
113     AES,
114     TKIP_AES
115 } WIFI_ENCTYPE;
116
117 /**
118 * Device Roles defined for each device type used in easy setup
119 */
120 typedef enum
121 {
122     ENROLLEE,
123     MEDIATOR,
124     ENROLLER,
125 } DeviceRole;
126
127 /**
128 * On-boarding connection to create Adhoc network.
129 */
130 typedef enum
131 {
132     SOFTAP,
133     BLE,
134 } OBConnection;
135
136 typedef enum
137 {
138     ES_ERROR = -1,
139     ES_OK = 0,
140     ES_NETWORKFOUND = 1,
141     ES_NETWORKCONNECTED,
142     ES_NETWORKNOTCONNECTED,
143     ES_RESOURCECREATED = 11,
144     ES_RECVREQOFPROVRES = 21,
145     ES_RECVREQOFNETRES,
146     ES_RECVUPDATEOFPROVRES,
147     ES_RECVTRIGGEROFPROVRES,
148 } ESResult;
149
150 typedef enum
151 {
152     ES_WIFI_RESOURCE = 0x01,
153     ES_CLOUD_RESOURCE = 0x02,
154     ES_DEVCONF_RESOURCE = 0x04
155 } ESResourceMask;
156
157 typedef struct
158 {
159     char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
160     char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
161     WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
162     WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
163 } ESWiFiProvData;
164
165 typedef struct
166 {
167     char language[OIC_STRING_MAX_VALUE];
168     char country[OIC_STRING_MAX_VALUE];
169 } ESDevConfProvData;
170
171 typedef struct
172 {
173     char authCode[OIC_STRING_MAX_VALUE];
174     char authProvider[OIC_STRING_MAX_VALUE];
175     char ciServer[OIC_STRING_MAX_VALUE];
176 } ESCloudProvData;
177
178
179 // TODO : Need to be erased
180 typedef enum
181 {
182     /**
183      * Default state of the device
184      */
185     ES_INIT_STATE,
186
187     /**
188      * Device will move to this state once the on boarding begins
189      */
190     ES_ON_BOARDING_STATE,
191
192     /**
193      * Device will move to this state after successful on-boarding of the device
194      */
195     ES_ON_BOARDED_STATE,
196
197     /**
198      * Device will move to this state once the on boarding is done
199      */
200     ES_PROVISIONING_STATE,
201
202     /**
203      * Easy setup process is successful.
204      */
205     ES_PROVISIONED_STATE,
206
207     /**
208      * This state is arbitrary one, any time device can come into this state
209      * Device will move to this state if the ownership transfer initiated  by the Application
210      */
211     ES_OWNERSHIP_TRANSFERRING_STATE,
212
213     /**
214      * This state is arbitrary one, any time device can come into this state
215      * Device will move to this state if the ownership transfer is completed
216      */
217     ES_OWNERSHIP_TRANSFERRED_STATE,
218
219     /**
220      * This state is arbitrary one, any time device can come into this state
221      * Device will move to this state once the Application factory reset the device
222      */
223     ES_FACTORY_RESET_STATE,
224
225     /**
226      * Enrollee moves to this state after connecting to target network
227      */
228     ES_ON_BOARDED_TARGET_NETWORK_STATE,
229 }ESEnrolleeState;
230
231 /**
232  * Provisioning Device Status
233  */
234 typedef struct
235 {
236     // Address of remote server
237     OCDevAddr * addr;
238     // Indicates adaptor type on which the response was received
239     OCConnectivityType connType;
240 } EasySetupDeviceInfo;
241
242 /**
243  * Provosioning Status
244  */
245 typedef enum
246 {
247     DEVICE_PROVISIONED = 0,
248     DEVICE_NOT_PROVISIONED,
249     DEVICE_OWNED,
250     DEVICE_NOT_OWNED
251 } EasySetupState, ProvStatus;
252
253 /**
254  * Response from queries to remote servers.
255  */
256 typedef struct
257 {
258     // EasySetup Status
259     EasySetupState provStatus;
260     // EasySetup Device Info
261     EasySetupDeviceInfo provDeviceInfo;
262 } EasySetupInfo, ProvisioningInfo;
263
264 /**
265  * @brief  Network information of the Enroller
266  */
267 typedef union
268 {
269     /**
270      * @brief BT Mac Information
271      */
272     struct
273     {
274         char btMacAddress[NET_MACADDR_SIZE];   /**< BT mac address **/
275     } BT;
276
277     /**
278      * @brief LE MAC Information
279      */
280     struct
281     {
282         char leMacAddress[NET_MACADDR_SIZE];   /**< BLE mac address **/
283     } LE;
284
285     /**
286      * @brief IP Information
287      */
288     struct
289     {
290         char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
291         char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
292     } WIFI;
293 } ProvData;
294
295 /**
296  * @brief Network Information
297  */
298 typedef struct
299 {
300     ProvData provData;    /**< Enroller Network Info**/
301     OCConnectivityType connType;    /**< Connectivity Type**/
302 } ProvConfig;
303
304 /**
305  * Client applications implement this callback to consume responses received from Servers.
306  */
307 typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
308
309 /**
310  * @brief This structure represent configuration information to create wifi onboarding SoftAP or connection.
311 */
312
313
314 // Note : Below structure is not currently used but added for future purpose.
315 typedef struct {
316     char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the onboarding Adhoc Wifi network**/
317     char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the onboarding Adhoc wifi network**/
318     bool isSecured;                 /**< Secure connection**/
319 }WiFiOnboardingConfig;
320
321 /**
322  * @brief This structure represent onboarding connection instance.
323 */
324 typedef struct {
325  /*Actual use of ipAddress is for unicast discovery, but also used to identify the Enrollee device as of now,
326     device identification should be based on DeviceID in next release.*/
327    char ipAddress[IPV4_ADDR_SIZE]; /**< IP Address of the Enrollee **/
328    bool isSecured;                 /**< Secure connection**/
329 }WiFiOnboadingConnection;
330
331
332 #endif //ES_COMMON_H_