[IOT-2928][IOT-3017][IOT-3022]
[iotivity.git] / resource / csdk / security / provisioning / include / cloud / occloudprovisioning.h
1 /* *****************************************************************
2  *
3  * Copyright 2016 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 #ifndef OC_CLOUD_PROVISIONING_H
21 #define OC_CLOUD_PROVISIONING_H
22
23 #include "octypes.h"
24 #include "ocprovisioningmanager.h"
25 #include "experimental/securevirtualresourcetypes.h"
26 #include "auth.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif // __cplusplus
31
32 typedef void (*OCCloudResponseCB )(void* ctx, OCClientResponse* response, void* data);
33
34 typedef struct cloudAce cloudAce_t;
35
36 struct cloudAce {
37     char *aceId;
38     OicUuid_t subjectuuid;
39     uint16_t stype;
40     uint16_t permission;
41     OicSecRsrc_t *resources;
42     OicSecValidity_t *validities;
43     cloudAce_t *next;
44 };
45
46 typedef struct {
47     char **array;
48     size_t length;
49 }stringArray_t;
50
51 typedef struct {
52     stringArray_t gidlist;
53     stringArray_t midlist;
54 }stringArrayPair_t;
55
56 typedef struct {
57     stringArrayPair_t invite;
58     stringArrayPair_t invited;
59 }inviteResponse_t;
60
61 typedef struct CloudData
62 {
63     void *ctx;                                  /**< Pointer to user context.**/
64     const OCProvisionDev_t *targetDev;          /**< Pointer to OCProvisionDev_t.**/
65     OicSecCred_t *credInfo;                     /**< Array of pointers to OicSecCred_t.**/
66     OCProvisionResultCB resultCallback;         /**< Pointer to result callback.**/
67     OCProvisionResult_t *resArr;                /**< Result array.**/
68     int numOfResults;                           /**< Number of results in result array.**/
69     const char* cloudURI;                       /**< Cloud URI.**/
70     const char* oauthProvider;                  /**< Authorisation provider name.**/
71     const char* accessToken;                    /**< Access token that can be validated by the Cloud.**/
72     const char* sid;                            /**< Cloud UUID.**/
73 } CloudData_t;
74
75 /**
76  * Certificate-Issue request function
77  *
78  * @param[in] ctx               user-defined context
79  * @param[in] cloudUri          cloud host and port
80  * @param[in] callback          optional result callback, can be NULL if not required
81  * @return  OCStackResult application result
82  */
83 OCStackResult OCCloudCertificateIssueRequest(void* ctx,
84                                              const char *cloudUri,
85                                              OCCloudResponseCB callback);
86
87 /**
88  * CRL GET request function
89  *
90  * @param[in] ctx               user-defined context
91  * @param[in] cloudUri          cloud host and port
92  * @param[in] callback          optional result callback, can be NULL if not required
93  * @return  OCStackResult application result
94  */
95 OCStackResult OCCloudGetCRL(void* ctx,
96                             const char *cloudUri,
97                             OCCloudResponseCB callback);
98
99 /**
100  * CRL POST request function (with Serial Numbers list to revoke)
101  *
102  * @param[in] ctx               user-defined context
103  * @param[in] thisUpdate        mandatory parameter thisUpdate
104  * @param[in] nextUpdate        mandatory parameter nextUpdate
105  * @param[in] crl               optional parameter crl
106  * @param[in] serialNumbers     optional parameter serial numbers
107  * @param[in] cloudUri          cloud host and port
108  * @param[in] callback          optional result callback, can be NULL if not required
109  * @return  OCStackResult application result
110  */
111 OCStackResult OCCloudPostCRL(void* ctx,
112                              const char *thisUpdate,
113                              const char *nextUpdate,
114                              const OCByteString *crl,
115                              const stringArray_t *serialNumbers,
116                              const char *cloudUri,
117                              OCCloudResponseCB callback);
118
119 /**
120  * ACL id retrieve by device id
121  *
122  * @param[in] ctx               user-defined context
123  * @param[in] deviceId          mandatory parameter device id
124  * @param[in] cloudUri          cloud host and port
125  * @param[in] callback          optional result callback, can be NULL if not required
126  * @return  OCStackResult application result
127  */
128 OCStackResult OCCloudGetAclIdByDevice(void* ctx,
129                                       const char *deviceId,
130                                       const char *cloudUri,
131                                       OCCloudResponseCB callback);
132
133 /**
134  * ACL id create
135  *
136  * @param[in] ctx               user-defined context
137  * @param[in] ownerId           mandatory parameter owner id
138  * @param[in] deviceId          mandatory parameter device id
139  * @param[in] cloudUri          cloud host and port
140  * @param[in] callback          optional result callback, can be NULL if not required
141  * @return  OCStackResult application result
142  */
143 OCStackResult OCCloudAclIdCreate(void* ctx,
144                                  const char *ownerId,
145                                  const char *deviceId,
146                                  const char *cloudUri,
147                                  OCCloudResponseCB callback);
148
149 /**
150  * ACL id delete
151  *
152  * @param[in] ctx               user-defined context
153  * @param[in] aclId             mandatory parameter acl id
154  * @param[in] cloudUri          cloud host and port
155  * @param[in] callback          optional result callback, can be NULL if not required
156  * @return  OCStackResult application result
157  */
158 OCStackResult OCCloudAclIdDelete(void* ctx,
159                                  const char *aclId,
160                                  const char *cloudUri,
161                                  OCCloudResponseCB callback);
162
163 /**
164  * ACL individual get info
165  *
166  * @param[in] ctx               user-defined context
167  * @param[in] aclId             mandatory parameter acl id
168  * @param[in] cloudUri          cloud host and port
169  * @param[in] callback          optional result callback, can be NULL if not required
170  * @return  OCStackResult application result
171  */
172 OCStackResult OCCloudAclIndividualGetInfo(void* ctx,
173                                           const char *aclId,
174                                           const char *cloudUri,
175                                           OCCloudResponseCB callback);
176
177 /**
178  * ACL individual update ACE
179  *
180  * @param[in] ctx               user-defined context
181  * @param[in] aclId             mandatory parameter acl id
182  * @param[in] aces              mandatory parameter aces
183  * @param[in] cloudUri          cloud host and port
184  * @param[in] callback          optional result callback, can be NULL if not required
185  * @return  OCStackResult application result
186  */
187 OCStackResult OCCloudAclIndividualAclUpdate(void* ctx,
188                                             const char *aclId,
189                                             const cloudAce_t *aces,
190                                             const char *cloudUri,
191                                             OCCloudResponseCB callback);
192
193 /**
194  * ACL individual update
195  *
196  * @param[in] ctx               user-defined context
197  * @param[in] aclId             mandatory parameter acl id
198  * @param[in] aceId             mandatory parameter target ace id
199  * @param[in] aces              mandatory parameter aces
200  * @param[in] cloudUri          cloud host and port
201  * @param[in] callback          optional result callback, can be NULL if not required
202  * @return  OCStackResult application result
203  */
204 OCStackResult OCCloudAclIndividualAceUpdate(void* ctx,
205                                             const char *aclId,
206                                             const char *aceId,
207                                             const cloudAce_t *aces,
208                                             const char *cloudUri,
209                                             OCCloudResponseCB callback);
210
211 /**
212  * ACL individual delete - replaces ACE with given aceid with provided ACE
213  *
214  * @param[in] ctx               user-defined context
215  * @param[in] aclId             mandatory parameter acl id
216  * @param[in] cloudUri          cloud host and port
217  * @param[in] callback          optional result callback, can be NULL if not required
218  * @return  OCStackResult application result
219  */
220 OCStackResult OCCloudAclAcesDelete(void* ctx,
221                                          const char *aclId,
222                                          const char *cloudUri,
223                                          OCCloudResponseCB callback);
224
225 /**
226  * ACL individual delete ACE
227  *
228  * @param[in] ctx               user-defined context
229  * @param[in] aclId             mandatory parameter acl id
230  * @param[in] aceId             target ace id
231  * @param[in] cloudUri          cloud host and port
232  * @param[in] callback          optional result callback, can be NULL if not required
233  * @return  OCStackResult application result
234  */
235 OCStackResult OCCloudAclIndividualAceDelete(void* ctx,
236                                          const char *aclId,
237                                          const char *aceId,
238                                          const char *cloudUri,
239                                          OCCloudResponseCB callback);
240
241 /**
242  * ACL post group request function
243  *
244  * @param[in] ctx               user-defined context
245  * @param[in] groupType         mandatory parameter group type
246  * @param[in] groupMasterId     optional parameter group master id
247  * @param[in] cloudUri          cloud host and port
248  * @param[in] callback          optional result callback, can be NULL if not required
249  * @return  OCStackResult application result
250  */
251 OCStackResult OCCloudAclCreateGroup(void* ctx,
252                                     const char *groupType,
253                                     const char *groupMasterId,
254                                     const char *cloudUri,
255                                     OCCloudResponseCB callback);
256
257 /**
258  * ACL get group request function
259  *
260  * @param[in] ctx               user-defined context
261  * @param[in] memberId          member id
262  * @param[in] cloudUri          cloud host and port
263  * @param[in] callback          optional result callback, can be NULL if not required
264  * @return  OCStackResult application result
265  */
266 OCStackResult OCCloudAclFindMyGroup(void* ctx,
267                                     const char *memberId,
268                                     const char *cloudUri,
269                                     OCCloudResponseCB callback);
270
271 /**
272  * ACL delete group request function
273  *
274  * @param[in] ctx               user-defined context
275  * @param[in] groupId           mandatory parameter group id
276  * @param[in] groupMasterId     optional parameter group master id
277  * @param[in] cloudUri          cloud host and port
278  * @param[in] callback          optional result callback, can be NULL if not required
279  * @return  OCStackResult application result
280  */
281 OCStackResult OCCloudAclDeleteGroup(void* ctx,
282                                     const char *groupId,
283                                     const char *groupMasterId,
284                                     const char *cloudUri,
285                                     OCCloudResponseCB callback);
286
287 /**
288  * ACL join to invited group request function
289  *
290  * @param[in] ctx               user-defined context
291  * @param[in] groupId           mandatory parameter group id
292  * @param[in] cloudUri          cloud host and port
293  * @param[in] callback          optional result callback, can be NULL if not required
294  * @return  OCStackResult application result
295  */
296 OCStackResult OCCloudAclJoinToInvitedGroup(void* ctx,
297                                            const char *groupId,
298                                            const char *cloudUri,
299                                            OCCloudResponseCB callback);
300
301 /**
302  * ACL observe group request function
303  *
304  * @param[in] ctx               user-defined context
305  * @param[in] groupId           mandatory parameter group id
306  * @param[in] cloudUri          cloud host and port
307  * @param[in] callback          optional result callback, can be NULL if not required
308  * @return  OCStackResult application result
309  */
310 OCStackResult OCCloudAclObserveGroup(void* ctx,
311                                      const char *groupId,
312                                      const char *cloudUri,
313                                      OCCloudResponseCB callback);
314
315 /**
316  * ACL share device into group request function
317  *
318  * @param[in] ctx               user-defined context
319  * @param[in] groupId           mandatory parameter group id
320  * @param[in] memberIds         mandatory parameter members list
321  * @param[in] deviceIds         mandatory parameter devices list
322  * @param[in] cloudUri          cloud host and port
323  * @param[in] callback          optional result callback, can be NULL if not required
324  * @return  OCStackResult application result
325  */
326 OCStackResult OCCloudAclShareDeviceIntoGroup(void* ctx,
327                                              const char *groupId,
328                                              const stringArray_t *memberIds,
329                                              const stringArray_t *deviceIds,
330                                              const char *cloudUri,
331                                              OCCloudResponseCB callback);
332
333 /**
334  * ACL delete device from group request function
335  *
336  * @param[in] ctx               user-defined context
337  * @param[in] groupId           mandatory parameter group id
338  * @param[in] memberIds         mandatory parameter members list
339  * @param[in] deviceIds         mandatory parameter devices list
340  * @param[in] cloudUri          cloud host and port
341  * @param[in] callback          optional result callback, can be NULL if not required
342  * @return  OCStackResult application result
343  */
344 OCStackResult OCCloudAclDeleteDeviceFromGroup(void* ctx,
345                                               const char *groupId,
346                                               const stringArray_t *memberIds,
347                                               const stringArray_t *deviceIds,
348                                               const char *cloudUri,
349                                               OCCloudResponseCB callback);
350
351 /**
352  * ACL get group info request function
353  *
354  * @param[in] ctx               user-defined context
355  * @param[in] groupId           mandatory parameter group id
356  * @param[in] memberId          optional parameter member id
357  * @param[in] cloudUri          cloud host and port
358  * @param[in] callback          optional result callback, can be NULL if not required
359  * @return  OCStackResult application result
360  */
361 OCStackResult OCCloudAclGroupGetInfo(void* ctx,
362                                      const char *groupId,
363                                      const char *memberId,
364                                      const char *cloudUri,
365                                      OCCloudResponseCB callback);
366
367 /**
368  * ACL invite user to group request function
369  *
370  * @param[in] ctx               user-defined context
371  * @param[in] userId            optional parameter user id
372  * @param[in] groupIds          mandatory parameter groups list
373  * @param[in] memberIds         mandatory parameter members list
374  * @param[in] cloudUri          cloud host and port
375  * @param[in] callback          optional result callback, can be NULL if not required
376  * @return  OCStackResult application result
377  */
378 OCStackResult OCCloudAclInviteUser(void* ctx,
379                                    const char *userId,
380                                    const stringArray_t *groupIds,
381                                    const stringArray_t *memberIds,
382                                    const char *cloudUri,
383                                    OCCloudResponseCB callback);
384
385 /**
386  * ACL get invitation request function
387  *
388  * @param[in] ctx               user-defined context
389  * @param[in] userId            optional parameter user id
390  * @param[in] cloudUri          cloud host and port
391  * @param[in] callback          optional result callback, can be NULL if not required
392  * @return  OCStackResult application result
393  */
394 OCStackResult OCCloudAclGetInvitation(void* ctx,
395                                       const char *userId,
396                                       const char *cloudUri,
397                                       OCCloudResponseCB callback);
398
399 /**
400  * ACL delete invitation request function (by receiver)
401  *
402  * @param[in] ctx               user-defined context
403  * @param[in] userId            optional parameter user id
404  * @param[in] groupId           mandatory parameter group id
405  * @param[in] cloudUri          cloud host and port
406  * @param[in] callback          optional result callback, can be NULL if not required
407  * @return  OCStackResult application result
408  */
409 OCStackResult OCCloudAclDeleteInvitation(void* ctx,
410                                          const char *userId,
411                                          const char *groupId,
412                                          const char *cloudUri,
413                                          OCCloudResponseCB callback);
414
415 /**
416  * ACL cancel invitation request function (by sender)
417  *
418  * @param[in] ctx               user-defined context
419  * @param[in] userId            optional parameter user id
420  * @param[in] groupId           mandatory parameter group id
421  * @param[in] memberId          mandatory parameter member id
422  * @param[in] cloudUri          cloud host and port
423  * @param[in] callback          optional result callback, can be NULL if not required
424  * @return  OCStackResult application result
425  */
426 OCStackResult OCCloudAclCancelInvitation(void* ctx,
427                                          const char *userId,
428                                          const char *groupId,
429                                          const char *memberId,
430                                          const char *cloudUri,
431                                          OCCloudResponseCB callback);
432
433 /**
434  * ACL check that given request can be applied to resource
435  *
436  * @param[in] ctx               user-defined context
437  * @param[in] subjectId         mandatory parameter subject id
438  * @param[in] deviceId          mandatory parameter device id
439  * @param[in] method            mandatory parameter method
440  * @param[in] uri               mandatory parameter uri
441  * @param[in] cloudUri          cloud host and port
442  * @param[in] callback          optional result callback, can be NULL if not required
443  * @return  OCStackResult application result
444  */
445 OCStackResult OCCloudAclPolicyCheck(void* ctx,
446                                     const char *subjectId,
447                                     const char *deviceId,
448                                     const char *method,
449                                     const char *uri,
450                                     const char *cloudUri,
451                                     OCCloudResponseCB callback);
452
453 /**
454  * Provision cloud configuration
455  *
456  * @param[in] ctx               user-defined context
457  * @param[in] pDev              provision device
458  * @param[in] cloud             struct containing provisioned parameters
459  * @param[in] resultCallback    optional result callback, can be NULL if not required
460  * @return  OCStackResult application result
461  */
462 OCStackResult OCProvisionCloudConfig(void *ctx,
463                                      const OCProvisionDev_t *pDev,
464                                      const OicCloud_t *cloud,
465                                      OCClientResponseHandler resultCallback);
466
467 /**
468  * Get cloud status of the selected device
469  *
470  * @param[in] ctx               user-defined context
471  * @param[in] pDev              provision device
472  * @param[in] cloud             struct containing cloud URL
473  * @param[in] resultCallback    optional result callback, can be NULL if not required
474  * @return  OCStackResult application result
475  */
476 OCStackResult OCGetCloudStatusRequest(void *ctx,
477                                       const OCProvisionDev_t *pDev,
478                                       const OicCloud_t *cloud,
479                                       OCClientResponseHandler resultCallback);
480
481 /**
482  * Delete CoAPCloudConf and cloud related ACLs from the selected device by cloud id
483  *
484  * @param[in] ctx               user-defined context
485  * @param[in] pDev              provision device
486  * @param[in] cloud             struct containing cloud UUID
487  * @param[in] resultCallback    optional result callback, can be NULL if not required
488  * @return  OCStackResult application result
489  */
490 OCStackResult OCRemoveCloudConfig(void *ctx,
491                                   const OCProvisionDev_t *pDev,
492                                   const OicCloud_t *cloud,
493                                   OCProvisionResultCB resultCallback);
494
495 #ifdef __cplusplus
496 }
497 #endif // __cplusplus
498 #endif //OC_CLOUD_PROVISIONING_H