Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / ocprovisioningmanager.h
1 /* *****************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *     http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  * *****************************************************************/\r
20 \r
21 #ifndef OCPROVISIONINGMANAGER_H_\r
22 #define OCPROVISIONINGMANAGER_H_\r
23 \r
24 #include "octypes.h"\r
25 #include "pmtypes.h"\r
26 #include "ownershiptransfermanager.h"\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif // __cplusplus\r
31 \r
32 /**\r
33  * The function is responsible for initializaton of the provisioning manager. It will load\r
34  * provisioning database which have owned device's list and their linked status.\r
35  * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will\r
36  * automatically try to update the deivce(s).\r
37  *\r
38  * @param[in] dbPath file path of the sqlite3 db\r
39  *\r
40  * @return OC_STACK_OK in case of success and other value otherwise.\r
41  */\r
42 OCStackResult OCInitPM(const char* dbPath);\r
43 \r
44 /**\r
45  * The function is responsible for discovery of device is current subnet. It will list\r
46  * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as\r
47  * OCMode.\r
48  *\r
49  * @param[in] timeout Timeout in seconds, value till which function will listen to responses from\r
50  *                    server before returning the list of devices.\r
51  * @param[out] ppList List of candidate devices to be provisioned\r
52  * @return OTM_SUCCESS in case of success and other value otherwise.\r
53  */\r
54 OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList);\r
55 \r
56 /**\r
57  * Do ownership transfer for un-owned device.\r
58  *\r
59  * @param[in] ctx Application context would be returned in result callback\r
60  * @param[in] targetDevices List of devices to perform ownership transfer.\r
61  * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.\r
62  * @return OC_STACK_OK in case of success and other value otherwise.\r
63  */\r
64 OCStackResult OCDoOwnershipTransfer(void* ctx,\r
65                                     OCProvisionDev_t *targetDevices,\r
66                                     OCProvisionResultCB resultCallback);\r
67 \r
68 /**\r
69  * API to register for particular OxM.\r
70  *\r
71  * @param[in] Ownership transfer method.\r
72  * @param[in] Implementation of callback functions for owership transfer.\r
73  * @return OC_STACK_OK in case of success and other value otherwise.\r
74  */\r
75 OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData);\r
76 \r
77 /**\r
78  * The function is responsible for discovery of owned device is current subnet. It will list\r
79  * all the device in subnet which are owned by calling provisioning client.\r
80  *\r
81  * @param[in] timeout Timeout in seconds, value till which function will listen to responses from\r
82  *                    server before returning the list of devices.\r
83  * @param[out] ppList List of device owned by provisioning tool.\r
84  * @return OTM_SUCCESS in case of success and other value otherwise.\r
85  */\r
86 OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);\r
87 \r
88 /**\r
89  * API to provision credentials between two devices and ACLs for the devices who act as a server.\r
90  *\r
91  * @param[in] ctx Application context would be returned in result callback.\r
92  * @param[in] type Type of credentials to be provisioned to the device.\r
93  * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.\r
94  * @param[in] acl ACL for device 1. If this is not required set NULL.\r
95  * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.\r
96  * @param[in] acl ACL for device 2. If this is not required set NULL.\r
97  * @param[in] resultCallback callback provided by API user, callback will be called when\r
98  *            provisioning request recieves a response from first resource server.\r
99  * @return OC_STACK_OK in case of success and other value otherwise.\r
100  */\r
101 OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize,\r
102                                          const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,\r
103                                          const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,\r
104                                          OCProvisionResultCB resultCallback);\r
105 \r
106 /**\r
107  * API to send ACL information to device.\r
108  *\r
109  * @param[in] ctx Application context would be returned in result callback.\r
110  * @param[in] selectedDeviceInfo Selected target device.\r
111  * @param[in] acl ACL to provision.\r
112  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning\r
113               request recieves a response from resource server.\r
114  * @return OC_STACK_OK in case of success and other value otherwise.\r
115  */\r
116 OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl,\r
117                              OCProvisionResultCB resultCallback);\r
118 \r
119 /**\r
120  * this function requests CRED information to resource.\r
121  *
122  * @param[in] ctx Application context would be returned in result callback.
123  * @param[in] selectedDeviceInfo Selected target device.\r
124  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
125               request recieves a response from resource server.
126  * @return  OC_STACK_OK in case of success and other value otherwise.
127  */
128 OCStackResult OCGetCredResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,\r
129                              OCProvisionResultCB resultCallback);\r
130 /**
131  * this function requests ACL information to resource.
132  *
133  * @param[in] ctx Application context would be returned in result callback.
134  * @param[in] selectedDeviceInfo Selected target device.
135  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
136               request recieves a response from resource server.
137  * @return  OC_STACK_OK in case of success and other value otherwise.
138  */
139 OCStackResult OCGetACLResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,
140                              OCProvisionResultCB resultCallback);
141
142 \r
143 /**\r
144  * this function sends Direct-Pairing Configuration to a device.\r
145  *\r
146  * @param[in] ctx Application context would be returned in result callback.\r
147  * @param[in] selectedDeviceInfo Selected target device.\r
148  * @param[in] pconf PCONF pointer.\r
149  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning\r
150               request recieves a response from resource server.\r
151  * @return  OC_STACK_OK in case of success and other value otherwise.\r
152  */\r
153 OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf,\r
154                              OCProvisionResultCB resultCallback);\r
155 \r
156 /**\r
157  * API to provision credential to devices.\r
158  *\r
159  * @param[in] ctx Application context would be returned in result callback.\r
160  * @param[in] type Type of credentials to be provisioned to the device.\r
161  * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.\r
162    @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.\r
163  * @param[in] resultCallback callback provided by API user, callback will be called when\r
164  *            provisioning request recieves a response from first resource server.\r
165  * @return OC_STACK_OK in case of success and other value otherwise.\r
166  */\r
167 OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,\r
168                                       const OCProvisionDev_t *pDev1,\r
169                                       const OCProvisionDev_t *pDev2,\r
170                                       OCProvisionResultCB resultCallback);\r
171 \r
172 /**\r
173  * Function to unlink devices.\r
174  * This function will remove the credential & relasionship between the two devices.\r
175  *\r
176  * @param[in] ctx Application context would be returned in result callback\r
177  * @param[in] pTargetDev1 fitst device information to be unlinked.\r
178  * @param[in] pTargetDev2 second device information to be unlinked.\r
179  * @param[in] resultCallback callback provided by API user, callback will be called when\r
180  *            device unlink is finished.\r
181  * @return OC_STACK_OK in case of success and other value otherwise.\r
182  */\r
183 OCStackResult OCUnlinkDevices(void* ctx,\r
184                               const OCProvisionDev_t* pTargetDev1,\r
185                               const OCProvisionDev_t* pTargetDev2,\r
186                               OCProvisionResultCB resultCallback);\r
187 \r
188 /**\r
189  * Function for device revocation\r
190  * This function will remove credential of target device from all devices in subnet.\r
191  *\r
192  * @param[in] ctx Application context would be returned in result callback\r
193  * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)\r
194  * @param[in] pTargetDev Device information to be revoked.\r
195  * @param[in] resultCallback callback provided by API user, callback will be called when\r
196  *            credential revocation is finished.\r
197  * @return OC_STACK_OK in case of success and other value otherwise.\r
198  *         if OC_STACK_OK is returned, the caller of this API should wait for callback.\r
199  *         OC_STACK_CONTINUE means operation is success but no need to wait for callback.\r
200  */\r
201 OCStackResult OCRemoveDevice(void* ctx,\r
202                              unsigned short waitTimeForOwnedDeviceDiscovery,\r
203                              const OCProvisionDev_t* pTargetDev,\r
204                              OCProvisionResultCB resultCallback);\r
205 \r
206 /*\r
207 * Function to device revocation\r
208 * This function will remove credential of target device from all devices in subnet.\r
209 *\r
210 * @param[in] ctx Application context would be returned in result callback\r
211 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)\r
212 * @param[in] pTargetDev Device information to be revoked.\r
213 * @param[in] resultCallback callback provided by API user, callback will be called when\r
214 *            credential revocation is finished.\r
215  * @return  OC_STACK_OK in case of success and other value otherwise.\r
216 */\r
217 OCStackResult OCRemoveDeviceWithUuid(void* ctx,\r
218                                      unsigned short waitTimeForOwnedDeviceDiscovery,\r
219                                      const OicUuid_t* pTargetUuid,\r
220                                      OCProvisionResultCB resultCallback);\r
221 \r
222 /**\r
223  * API to get status of all the devices in current subnet. The status include endpoint information\r
224  * and doxm information which can be extracted duing owned and unowned discovery. Along with this\r
225  * information. The API will provide information about devices' status\r
226  * Device can have following states\r
227  *  - ON/OFF: Device is switched on or off.\r
228  *\r
229  * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out\r
230  * variables pOwnedDevList and pUnownedDevList.\r
231  *\r
232  * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time\r
233  * will be used for unowned discovery and remaining half for owned discovery. So the wait time should be
234  * equal to or more than 2.
235  * @param[out] pOwnedDevList  list of owned devices.\r
236  * @param[out] pUnownedDevList  list of unowned devices.\r
237  * @return OC_STACK_OK in case of success and other value otherwise.\r
238  */\r
239 OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,\r
240                                        OCProvisionDev_t** pOwnedDevList,\r
241                                        OCProvisionDev_t** pUnownedDevList);\r
242 /**\r
243  * This method is used to get linked devices' IDs.\r
244  *\r
245  * @param[in] uuidOfDevice a target device's uuid.\r
246  * @param[out] uuidList information about the list of linked devices' uuids.\r
247  * @param[out] numOfDevices total number of linked devices.\r
248  * @return OC_STACK_OK in case of success and other value otherwise.\r
249  */\r
250 OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice,\r
251                                   OCUuidList_t** uuidList,\r
252                                   size_t* numOfDevices);\r
253 \r
254 /**\r
255  * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API.\r
256  *\r
257  * @param[in] pList Pointer to OCProvisionDev_t which should be deleted.\r
258  */\r
259 void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList);\r
260 \r
261 /**\r
262  * API to delete memory allocated to OicUuid_t list.\r
263  *\r
264  * @param[in] pList Pointer to OicUuid_t list which should be deleted.\r
265  */\r
266 void OCDeleteUuidList(OCUuidList_t* pList);\r
267 \r
268 /**\r
269  * This function deletes ACL data.\r
270  *\r
271  * @param pAcl Pointer to OicSecAcl_t structure.\r
272  */\r
273 void OCDeleteACLList(OicSecAcl_t* pAcl);
274 \r
275 /**\r
276  * This function deletes PDACL data.\r
277  *\r
278  * @param pPdAcl Pointer to OicSecPdAcl_t structure.\r
279  */\r
280 void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl);\r
281
282 #ifdef __WITH_X509__
283 /**
284  * this function sends CRL information to resource.
285  *
286  * @param[in] ctx Application context would be returned in result callback.
287  * @param[in] selectedDeviceInfo Selected target device.
288  * @param[in] crl CRL to provision.
289  * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
290               request recieves a response from resource server.
291  * @return  OC_STACK_OK in case of success and other value otherwise.
292  */
293 OCStackResult OCProvisionCRL(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecCrl_t *crl,
294                              OCProvisionResultCB resultCallback);
295 #endif // __WITH_X509__
296 \r
297 \r
298 #ifdef __cplusplus\r
299 }\r
300 #endif // __cplusplus\r
301 \r
302 #endif /* OCPROVISIONINGMANAGER_H_ */\r