Add PKIX provisioning
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / ocprovisioningmanager.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 OCPROVISIONINGMANAGER_H_
22 #define OCPROVISIONINGMANAGER_H_
23
24 #include "octypes.h"
25 #include "pmtypes.h"
26 #include "ownershiptransfermanager.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif // __cplusplus
31
32 /**
33  * The function is responsible for initializaton of the provisioning manager. It will load
34  * provisioning database which have owned device's list and their linked status.
35  * In addition, if there is a device(s) which has not up-to-date credentials, this function will
36  * automatically try to update the deivce(s).
37  *
38  * @param[in] dbPath file path of the sqlite3 db
39  *
40  * @return OC_STACK_OK in case of success and other value otherwise.
41  */
42 OCStackResult OCProvisionInit(const char* dbPath);
43
44 /**
45  * The function is responsible for discovery of device is current subnet. It will list
46  * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
47  * OCMode.
48  *
49  * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
50  *                    client before returning the list of devices.
51  * @param[out] ppList List of candidate devices to be provisioned
52  * @return OTM_SUCCESS in case of success and other value otherwise.
53  */
54 OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList);
55
56 /**
57  * Do ownership transfer for un-owned device.
58  *
59  * @param[in] ctx Application context would be returned in result callback
60  * @param[in] targetDevices List of devices to perform ownership transfer.
61  * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.
62  * @return OC_STACK_OK in case of success and other value otherwise.
63  */
64 OCStackResult OCDoOwnershipTransfer(void* ctx,
65                                     OCProvisionDev_t *targetDevices,
66                                     OCProvisionResultCB resultCallback);
67
68 /**
69  * API to register for particular OxM.
70  *
71  * @param[in] Ownership transfer method.
72  * @param[in] Implementation of callback functions for owership transfer.
73  * @return  OC_STACK_OK in case of success and other value otherwise.
74  */
75 OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData);
76
77 /**
78  * The function is responsible for discovery of owned device is current subnet. It will list
79  * all the device in subnet which are owned by calling provisioning client.
80  *
81  * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
82  *                    client before returning the list of devices.
83  * @param[out] ppList List of device owned by provisioning tool.
84  * @return OTM_SUCCESS in case of success and other value otherwise.
85  */
86 OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);
87
88 /**
89  * API to provision credentials between two devices and ACLs for the devices who act as a server.
90  *
91  * @param[in] ctx Application context would be returned in result callback.
92  * @param[in] type Type of credentials to be provisioned to the device.
93  * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
94  * @param[in] acl ACL for device 1. If this is not required set NULL.
95  * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
96  * @param[in] acl ACL for device 2. If this is not required set NULL.
97  * @param[in] resultCallback callback provided by API user, callback will be called when
98  *            provisioning request recieves a response from first resource server.
99  * @return  OC_STACK_OK in case of success and other value otherwise.
100  */
101 OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize,
102                                          const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,
103                                          const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,
104                                          OCProvisionResultCB resultCallback);
105
106 /**
107  * API to send ACL information to device.
108  *
109  * @param[in] ctx Application context would be returned in result callback.
110  * @param[in] selectedDeviceInfo Selected target device.
111  * @param[in] acl ACL to provision.
112  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
113               request recieves a response from resource server.
114  * @return  OC_STACK_OK in case of success and other value otherwise.
115  */
116 OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl,
117                              OCProvisionResultCB resultCallback);
118
119 /**
120  * API to provision credential to devices.
121  *
122  * @param[in] ctx Application context would be returned in result callback.
123  * @param[in] type Type of credentials to be provisioned to the device.
124  * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
125    @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
126  * @param[in] resultCallback callback provided by API user, callback will be called when
127  *            provisioning request recieves a response from first resource server.
128  * @return  OC_STACK_OK in case of success and other value otherwise.
129  */
130 OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,
131                                       const OCProvisionDev_t *pDev1,
132                                       const OCProvisionDev_t *pDev2,
133                                       OCProvisionResultCB resultCallback);
134
135 /**
136  * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API.
137  *
138  * @param[in] ppList Pointer to OCProvisionDev_t which should be deleted.
139  */
140 void OCDeleteDiscoveredDevices(OCProvisionDev_t **ppList);
141
142 /**
143  * API to delete memory allocated to OCProvisionResult_t list in callback function.
144  *
145  * @note: This function must be called in the callback implementation after checking results.
146  *
147  * @param[in] pList Pointer to OCProvisionResult_t list which should be deleted.
148  */
149 void OCDeleteProvisionResults(OCProvisionResult_t *pList);
150
151 #ifdef __WITH_X509__
152 /**
153  * this function sends CRL information to resource.
154  *
155  * @param[in] ctx Application context would be returned in result callback.
156  * @param[in] selectedDeviceInfo Selected target device.
157  * @param[in] crl CRL to provision.
158  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
159               request recieves a response from resource server.
160  * @return  OC_STACK_OK in case of success and other value otherwise.
161  */
162 OCStackResult OCProvisionCRL(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecCrl_t *crl,
163                              OCProvisionResultCB resultCallback);
164 #endif // __WITH_X509__
165
166 #ifdef __cplusplus
167 }
168 #endif // __cplusplus
169
170 #endif /* OCPROVISIONINGMANAGER_H_ */