1 /* *****************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
19 * *****************************************************************/
\r
21 #ifndef OCPROVISIONINGMANAGER_H_
\r
22 #define OCPROVISIONINGMANAGER_H_
\r
24 #include "octypes.h"
\r
25 #include "pmtypes.h"
\r
26 #include "ownershiptransfermanager.h"
\r
27 #ifdef _ENABLE_MULTIPLE_OWNER_
\r
28 #include "securevirtualresourcetypes.h"
\r
29 #endif //_ENABLE_MULTIPLE_OWNER_
\r
33 #endif // __cplusplus
\r
36 * The function is responsible for initializaton of the provisioning manager. It will load
\r
37 * provisioning database which have owned device's list and their linked status.
\r
38 * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will
\r
39 * automatically try to update the deivce(s).
\r
41 * @param[in] dbPath file path of the sqlite3 db
\r
43 * @return OC_STACK_OK in case of success and other value otherwise.
\r
45 OCStackResult OCInitPM(const char* dbPath);
\r
48 * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
\r
49 * It will return the found device even though timeout is not exceeded.
\r
51 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
\r
52 * server before returning the device.
\r
53 * @param[in] deviceID deviceID of target device.
\r
54 * @param[out] ppFoundDevice OCProvisionDev_t of found device
\r
55 * @return OTM_SUCCESS in case of success and other value otherwise.
\r
57 OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t* deviceID,
\r
58 OCProvisionDev_t **ppFoundDevice);
\r
61 * The function is responsible for discovery of device is current subnet. It will list
\r
62 * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
\r
65 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
\r
66 * server before returning the list of devices.
\r
67 * @param[out] ppList List of candidate devices to be provisioned
\r
68 * @return OTM_SUCCESS in case of success and other value otherwise.
\r
70 OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList);
\r
73 * Do ownership transfer for un-owned device.
\r
75 * @param[in] ctx Application context would be returned in result callback
\r
76 * @param[in] targetDevices List of devices to perform ownership transfer.
\r
77 * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.
\r
78 * @return OC_STACK_OK in case of success and other value otherwise.
\r
80 OCStackResult OCDoOwnershipTransfer(void* ctx,
\r
81 OCProvisionDev_t *targetDevices,
\r
82 OCProvisionResultCB resultCallback);
\r
85 * API to set a allow status of OxM
\r
87 * @param[in] oxm Owership transfer method (ref. OicSecOxm_t)
\r
88 * @param[in] allowStatus allow status (true = allow, false = not allow)
\r
90 * @return OC_STACK_OK in case of success and other value otherwise.
\r
92 OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus);
\r
94 #ifdef _ENABLE_MULTIPLE_OWNER_
\r
96 * API to perfrom multiple ownership transfer for MOT enabled device.
\r
98 * @param[in] ctx Application context would be returned in result callback
\r
99 * @param[in] targetDevices List of devices to perform ownership transfer.
\r
100 * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.
\r
101 * @return OC_STACK_OK in case of success and other value otherwise.
\r
103 OCStackResult OCDoMultipleOwnershipTransfer(void* ctx,
\r
104 OCProvisionDev_t *targetDevices,
\r
105 OCProvisionResultCB resultCallback);
\r
106 #endif //_ENABLE_MULTIPLE_OWNER_
\r
109 * API to register for particular OxM.
\r
111 * @param[in] Ownership transfer method.
\r
112 * @param[in] Implementation of callback functions for owership transfer.
\r
113 * @return OC_STACK_OK in case of success and other value otherwise.
\r
115 OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData);
\r
118 * The function is responsible for discovery of owned device is current subnet. It will list
\r
119 * all the device in subnet which are owned by calling provisioning client.
\r
121 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
\r
122 * server before returning the list of devices.
\r
123 * @param[out] ppList List of device owned by provisioning tool.
\r
124 * @return OTM_SUCCESS in case of success and other value otherwise.
\r
126 OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);
\r
128 #ifdef _ENABLE_MULTIPLE_OWNER_
\r
130 * The function is responsible for discovery of MOT enabled device is current subnet.
\r
132 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
\r
133 * server before returning the list of devices.
\r
134 * @param[out] ppList List of MOT enabled devices.
\r
135 * @return OC_STACK_OK in case of success and other value otherwise.
\r
137 OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout, OCProvisionDev_t **ppList);
\r
140 * The function is responsible for discovery of Multiple Owned device is current subnet.
\r
142 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
\r
143 * server before returning the list of devices.
\r
144 * @param[out] ppList List of Multiple Owned devices.
\r
145 * @return OC_STACK_OK in case of success and other value otherwise.
\r
147 OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);
\r
148 #endif //_ENABLE_MULTIPLE_OWNER_
\r
151 * API to provision credentials between two devices and ACLs for the devices who act as a server.
\r
153 * @param[in] ctx Application context would be returned in result callback.
\r
154 * @param[in] type Type of credentials to be provisioned to the device.
\r
155 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
\r
156 * @param[in] acl ACL for device 1. If this is not required set NULL.
\r
157 * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
\r
158 * @param[in] acl ACL for device 2. If this is not required set NULL.
\r
159 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
160 * provisioning request recieves a response from first resource server.
\r
161 * @return OC_STACK_OK in case of success and other value otherwise.
\r
163 OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize,
\r
164 const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,
\r
165 const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,
\r
166 OCProvisionResultCB resultCallback);
\r
169 * API to send ACL information to device.
\r
171 * @param[in] ctx Application context would be returned in result callback.
\r
172 * @param[in] selectedDeviceInfo Selected target device.
\r
173 * @param[in] acl ACL to provision.
\r
174 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
\r
175 request recieves a response from resource server.
\r
176 * @return OC_STACK_OK in case of success and other value otherwise.
\r
178 OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl,
\r
179 OCProvisionResultCB resultCallback);
\r
182 * function to save ACL which has several ACE into Acl of SVR.
\r
184 * @param acl ACL to be saved in Acl of SVR.
\r
185 * @return OC_STACK_OK in case of success and other value otherwise.
\r
187 OCStackResult OCSaveACL(const OicSecAcl_t* acl);
\r
190 * this function requests CRED information to resource.
\r
192 * @param[in] ctx Application context would be returned in result callback.
\r
193 * @param[in] selectedDeviceInfo Selected target device.
\r
194 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
\r
195 request recieves a response from resource server.
\r
196 * @return OC_STACK_OK in case of success and other value otherwise.
\r
198 OCStackResult OCGetCredResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,
\r
199 OCProvisionResultCB resultCallback);
\r
202 * this function requests ACL information to resource.
\r
204 * @param[in] ctx Application context would be returned in result callback.
\r
205 * @param[in] selectedDeviceInfo Selected target device.
\r
206 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
\r
207 request recieves a response from resource server.
\r
208 * @return OC_STACK_OK in case of success and other value otherwise.
\r
210 OCStackResult OCGetACLResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,
\r
211 OCProvisionResultCB resultCallback);
\r
214 * this function sends Direct-Pairing Configuration to a device.
\r
216 * @param[in] ctx Application context would be returned in result callback.
\r
217 * @param[in] selectedDeviceInfo Selected target device.
\r
218 * @param[in] pconf PCONF pointer.
\r
219 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
\r
220 request recieves a response from resource server.
\r
221 * @return OC_STACK_OK in case of success and other value otherwise.
\r
223 OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf,
\r
224 OCProvisionResultCB resultCallback);
\r
227 * API to provision credential to devices.
\r
229 * @param[in] ctx Application context would be returned in result callback.
\r
230 * @param[in] type Type of credentials to be provisioned to the device.
\r
231 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
\r
232 @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
\r
233 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
234 * provisioning request recieves a response from first resource server.
\r
235 * @return OC_STACK_OK in case of success and other value otherwise.
\r
237 OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,
\r
238 const OCProvisionDev_t *pDev1,
\r
239 const OCProvisionDev_t *pDev2,
\r
240 OCProvisionResultCB resultCallback);
\r
242 #ifdef _ENABLE_MULTIPLE_OWNER_
\r
244 * API to provision preconfigured PIN to device(NOT LIST).
\r
245 * If device does not support the Preconfigured PIN OxM,
\r
246 * OCProvisionPreconfigPin API will update the device's Doxm
\r
247 * and then try preconfigured PIN provisioning once again.
\r
249 * @param[in] ctx Application context would be returned in result callback.
\r
250 * @param[in] targetDeviceInfo Selected target device.
\r
251 * @param[in] preconfigPin string of preconfigured PIN.
\r
252 * @param[in] preconfigPinLen string length of 'preconfigPin'.
\r
253 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
254 * provisioning request recieves a response from first resource server.
\r
255 * @return OC_STACK_OK in case of success and other value otherwise.
\r
257 OCStackResult OCProvisionPreconfigPin(void *ctx,
\r
258 OCProvisionDev_t *targetDeviceInfo,
\r
259 const char *preconfigPin,
\r
260 size_t preconfigPinLen,
\r
261 OCProvisionResultCB resultCallback);
\r
264 * API to add preconfigured PIN to local SVR DB.
\r
266 * @param[in] targetDeviceInfo Selected target device.
\r
267 * @param[in] preconfigPin Preconfig PIN which is used while multiple owner authentication
\r
268 * @param[in] preconfigPinLen Byte length of preconfigPin
\r
269 * @return OC_STACK_OK in case of success and other value otherwise.
\r
271 OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo,
\r
272 const char *preconfigPin,
\r
273 size_t preconfigPinLen);
\r
276 * API to update 'doxm.mom' to resource server.
\r
278 * @param[in] targetDeviceInfo Selected target device.
\r
279 * @param[in] momType Mode of multiple ownership transfer (ref. oic.sec.mom)
\r
280 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
281 * POST 'mom' request recieves a response from resource server.
\r
282 * @return OC_STACK_OK in case of success and other value otherwise.
\r
284 OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
\r
285 const OicSecMomType_t momType, OCProvisionResultCB resultCallback);
\r
288 * API to update 'doxm.oxmsel' to resource server.
\r
290 * @param[in] targetDeviceInfo Selected target device.
\r
291 * @param[in] oxmSelValue Method of multiple ownership transfer (ref. oic.sec.oxm)
\r
292 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
293 * POST 'oxmsel' request recieves a response from resource server.
\r
294 * @return OC_STACK_OK in case of success and other value otherwise.
\r
296 OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
\r
297 const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback);
\r
298 #endif //_ENABLE_MULTIPLE_OWNER_
\r
301 * Function to unlink devices.
\r
302 * This function will remove the credential & relasionship between the two devices.
\r
304 * @param[in] ctx Application context would be returned in result callback
\r
305 * @param[in] pTargetDev1 fitst device information to be unlinked.
\r
306 * @param[in] pTargetDev2 second device information to be unlinked.
\r
307 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
308 * device unlink is finished.
\r
309 * @return OC_STACK_OK in case of success and other value otherwise.
\r
311 OCStackResult OCUnlinkDevices(void* ctx,
\r
312 const OCProvisionDev_t* pTargetDev1,
\r
313 const OCProvisionDev_t* pTargetDev2,
\r
314 OCProvisionResultCB resultCallback);
\r
317 * Function for device revocation
\r
318 * This function will remove credential of target device from all devices in subnet.
\r
320 * @param[in] ctx Application context would be returned in result callback
\r
321 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
\r
322 * @param[in] pTargetDev Device information to be revoked.
\r
323 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
324 * credential revocation is finished.
\r
325 * @return OC_STACK_OK in case of success and other value otherwise.
\r
326 * if OC_STACK_OK is returned, the caller of this API should wait for callback.
\r
327 * OC_STACK_CONTINUE means operation is success but no need to wait for callback.
\r
329 OCStackResult OCRemoveDevice(void* ctx,
\r
330 unsigned short waitTimeForOwnedDeviceDiscovery,
\r
331 const OCProvisionDev_t* pTargetDev,
\r
332 OCProvisionResultCB resultCallback);
\r
335 * Function to device revocation
\r
336 * This function will remove credential of target device from all devices in subnet.
\r
338 * @param[in] ctx Application context would be returned in result callback
\r
339 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
\r
340 * @param[in] pTargetDev Device information to be revoked.
\r
341 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
342 * credential revocation is finished.
\r
343 * @return OC_STACK_OK in case of success and other value otherwise.
\r
345 OCStackResult OCRemoveDeviceWithUuid(void* ctx,
\r
346 unsigned short waitTimeForOwnedDeviceDiscovery,
\r
347 const OicUuid_t* pTargetUuid,
\r
348 OCProvisionResultCB resultCallback);
\r
351 * Function to reset the target device.
\r
352 * This function will remove credential and ACL of target device from all devices in subnet.
\r
354 * @param[in] ctx Application context would be returned in result callback
\r
355 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
\r
356 * @param[in] pTargetDev Device information to be revoked.
\r
357 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
358 * credential revocation is finished.
\r
359 * @return OC_STACK_OK in case of success and other value otherwise.
\r
361 OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
\r
362 const OCProvisionDev_t* pTargetDev,
\r
363 OCProvisionResultCB resultCallback);
\r
366 * API to get status of all the devices in current subnet. The status include endpoint information
\r
367 * and doxm information which can be extracted duing owned and unowned discovery. Along with this
\r
368 * information. The API will provide information about devices' status
\r
369 * Device can have following states
\r
370 * - ON/OFF: Device is switched on or off.
\r
372 * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out
\r
373 * variables pOwnedDevList and pUnownedDevList.
\r
375 * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time
\r
376 * will be used for unowned discovery and remaining half for owned discovery. So the wait time should be
\r
377 * equal to or more than 2.
\r
378 * @param[out] pOwnedDevList list of owned devices.
\r
379 * @param[out] pUnownedDevList list of unowned devices.
\r
380 * @return OC_STACK_OK in case of success and other value otherwise.
\r
382 OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
\r
383 OCProvisionDev_t** pOwnedDevList,
\r
384 OCProvisionDev_t** pUnownedDevList);
\r
386 * This method is used to get linked devices' IDs.
\r
388 * @param[in] uuidOfDevice a target device's uuid.
\r
389 * @param[out] uuidList information about the list of linked devices' uuids.
\r
390 * @param[out] numOfDevices total number of linked devices.
\r
391 * @return OC_STACK_OK in case of success and other value otherwise.
\r
393 OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice,
\r
394 OCUuidList_t** uuidList,
\r
395 size_t* numOfDevices);
\r
398 * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API.
\r
400 * @param[in] pList Pointer to OCProvisionDev_t which should be deleted.
\r
402 void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList);
\r
405 * API to delete memory allocated to OicUuid_t list.
\r
407 * @param[in] pList Pointer to OicUuid_t list which should be deleted.
\r
409 void OCDeleteUuidList(OCUuidList_t* pList);
\r
412 * This function deletes ACL data.
\r
414 * @param pAcl Pointer to OicSecAcl_t structure.
\r
416 void OCDeleteACLList(OicSecAcl_t* pAcl);
\r
419 * This function deletes PDACL data.
\r
421 * @param pPdAcl Pointer to OicSecPdAcl_t structure.
\r
423 void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl);
\r
425 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
\r
427 * this function sends CRL information to resource.
\r
429 * @param[in] ctx Application context would be returned in result callback.
\r
430 * @param[in] selectedDeviceInfo Selected target device.
\r
431 * @param[in] crl CRL to provision.
\r
432 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
\r
433 request recieves a response from resource server.
\r
434 * @return OC_STACK_OK in case of success and other value otherwise.
\r
436 OCStackResult OCProvisionCRL(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecCrl_t *crl,
\r
437 OCProvisionResultCB resultCallback);
\r
440 * function to provision Trust certificate chain to devices.
\r
442 * @param[in] ctx Application context would be returned in result callback.
\r
443 * @param[in] type Type of credentials to be provisioned to the device.
\r
444 * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
\r
445 * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
\r
446 * @param[in] resultCallback callback provided by API user, callback will be called when
\r
447 * provisioning request recieves a response from first resource server.
\r
448 * @return OC_STACK_OK in case of success and other value otherwise.
\r
450 OCStackResult OCProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
\r
451 const OCProvisionDev_t *selectedDeviceInfo,
\r
452 OCProvisionResultCB resultCallback);
\r
454 * function to save Trust certificate chain into Cred of SVR.
\r
456 * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
\r
457 * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
\r
458 * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
\r
459 * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
\r
460 * @return OC_STACK_OK in case of success and other value otherwise.
\r
462 OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
\r
463 OicEncodingType_t encodingType, uint16_t *credId);
\r
465 * function to register callback, for getting notification for TrustCertChain change.
\r
467 * @param[in] TrustCertChainChangeCB notifier callback function
\r
468 * @return OC_STACK_OK in case of success and other value otherwise.
\r
470 OCStackResult OCRegisterTrustCertChainNotifier(void *cb, TrustCertChainChangeCB CB);
\r
473 * function to de-register TrustCertChain notification callback.
\r
475 void OCRemoveTrustCertChainNotifier(void);
\r
478 * Function to read Trust certificate chain from SVR.
\r
479 * Caller must free when done using the returned trust certificate
\r
480 * @param[in] credId CredId of trust certificate chain in SVR.
\r
481 * @param[out] trustCertChain Trust certificate chain.
\r
482 * @param[out] chainSize Size of trust certificate chain
\r
483 * @return OC_STACK_OK in case of success and other value otherwise.
\r
485 OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
\r
486 size_t *chainSize);
\r
488 #endif // __WITH_DTLS__ || __WITH_TLS__
\r
493 #endif // __cplusplus
\r
495 #endif /* OCPROVISIONINGMANAGER_H_ */
\r