1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * *****************************************************************/
21 #ifndef OCPROVISIONINGMANAGER_H_
22 #define OCPROVISIONINGMANAGER_H_
26 #include "casecurityinterface.h"
27 #include "ownershiptransfermanager.h"
29 #include "securevirtualresourcetypes.h"
30 #endif //MULTIPLE_OWNER
37 * The function is responsible for initializaton of the provisioning manager. It will load
38 * provisioning database which have owned device's list and their linked status.
39 * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will
40 * automatically try to update the deivce(s).
42 * @param[in] dbPath file path of the sqlite3 db
44 * @return OC_STACK_OK in case of success and other value otherwise.
46 OCStackResult OCInitPM(const char *dbPath);
49 * API to termiante the provisioning manager
54 * API to cleanup PDM in case of timeout.
55 * It will remove the PDM_DEVICE_INIT state devices from PDM.
57 * @return OC_STACK_OK in case of success and other value otherwise.
59 OCStackResult OCPDMCleanupForTimeout();
62 * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
63 * It will return the found device even though timeout is not exceeded.
65 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
66 * server before returning the device.
67 * @param[in] deviceID deviceID of target device.
68 * @param[out] ppFoundDevice OCProvisionDev_t of found device
69 * @return OTM_SUCCESS in case of success and other value otherwise.
71 OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t *deviceID,
72 OCProvisionDev_t **ppFoundDevice);
75 * The function is responsible for discovery of owned/unowned device is specified endpoint/MAC
77 * It will return the found device even though timeout is not exceeded.
79 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
80 * server before returning the device.
81 * @param[in] deviceID deviceID of target device.
82 * @param[in] hostAddress MAC address of target device.
83 * @param[in] connType ConnectivityType for discovery.
84 * @param[out] ppFoundDevice OCProvisionDev_t of found device.
85 * @return OTM_SUCCESS in case of success and other value otherwise.
87 OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t *deviceID,
88 const char *hostAddress, OCConnectivityType connType,
89 OCProvisionDev_t **ppFoundDevice);
92 * The function is responsible for discovery of device is current subnet. It will list
93 * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
96 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
97 * server before returning the list of devices.
98 * @param[out] ppList List of candidate devices to be provisioned
99 * @return OTM_SUCCESS in case of success and other value otherwise.
101 OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList);
104 * Do ownership transfer for un-owned device.
106 * @param[in] ctx Application context would be returned in result callback
107 * @param[in] targetDevices List of devices to perform ownership transfer.
108 * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.
109 * @return OC_STACK_OK in case of success and other value otherwise.
111 OCStackResult OCDoOwnershipTransfer(void *ctx,
112 OCProvisionDev_t *targetDevices,
113 OCProvisionResultCB resultCallback);
116 * API to set a allow status of OxM
118 * @param[in] oxm Owership transfer method (ref. OicSecOxm_t)
119 * @param[in] allowStatus allow status (true = allow, false = not allow)
121 * @return OC_STACK_OK in case of success and other value otherwise.
123 OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus);
126 #ifdef MULTIPLE_OWNER
128 * API to perfrom multiple ownership transfer for MOT enabled device.
130 * @param[in] ctx Application context would be returned in result callback
131 * @param[in] targetDevices List of devices to perform ownership transfer.
132 * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished.
133 * @return OC_STACK_OK in case of success and other value otherwise.
135 OCStackResult OCDoMultipleOwnershipTransfer(void *ctx,
136 OCProvisionDev_t *targetDevices,
137 OCProvisionResultCB resultCallback);
140 * API to remove sub-owner from resource server
142 * @param[in] ctx Application context would be returned in result callback
143 * @param[in] targetDeviceInfo Selected target device.
144 * @param[in] subOwner sub-owner UUID to be removed
145 * @param[in] resultCallback callback provided by API user, callback will be invoked when
146 * DELETE 'subowneruuid' request recieves a response from resource server.
147 * @return OC_STACK_OK in case of success and other value otherwise.
149 OCStackResult OCRemoveSubOwner(void *ctx,
150 const OCProvisionDev_t *targetDeviceInfo,
151 const OicUuid_t *subOwner,
152 OCProvisionResultCB resultCallback);
155 * API to remove all sub-owner from resource server
157 * @param[in] ctx Application context would be returned in result callback
158 * @param[in] targetDeviceInfo Selected target device.
159 * @param[in] resultCallback callback provided by API user, callback will be invoked when
160 * DELETE 'subowneruuid' request recieves a response from resource server.
161 * @return OC_STACK_OK in case of success and other value otherwise.
163 OCStackResult OCRemoveAllSubOwner(void *ctx,
164 const OCProvisionDev_t *targetDeviceInfo,
165 OCProvisionResultCB resultCallback);
167 #endif //MULTIPLE_OWNER
170 * API to register for particular OxM.
172 * @param[in] Ownership transfer method.
173 * @param[in] Implementation of callback functions for owership transfer.
174 * @return OC_STACK_OK in case of success and other value otherwise.
176 OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t *callbackData);
179 * The function is responsible for discovery of owned device is current subnet. It will list
180 * all the device in subnet which are owned by calling provisioning client.
182 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
183 * server before returning the list of devices.
184 * @param[out] ppList List of device owned by provisioning tool.
185 * @return OTM_SUCCESS in case of success and other value otherwise.
187 OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);
189 #ifdef MULTIPLE_OWNER
191 * The function is responsible for discovery of MOT enabled device is current subnet.
193 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
194 * server before returning the list of devices.
195 * @param[out] ppList List of MOT enabled devices.
196 * @return OC_STACK_OK in case of success and other value otherwise.
198 OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout,
199 OCProvisionDev_t **ppList);
202 * The function is responsible for discovery of Multiple Owned device is current subnet.
204 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
205 * server before returning the list of devices.
206 * @param[out] ppList List of Multiple Owned devices.
207 * @return OC_STACK_OK in case of success and other value otherwise.
209 OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList);
210 #endif //MULTIPLE_OWNER
213 * API to provision credentials between two devices and ACLs for the devices who act as a server.
215 * @param[in] ctx Application context would be returned in result callback.
216 * @param[in] type Type of credentials to be provisioned to the device.
217 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
218 * @param[in] acl ACL for device 1. If this is not required set NULL.
219 * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned.
220 * @param[in] acl ACL for device 2. If this is not required set NULL.
221 * @param[in] resultCallback callback provided by API user, callback will be called when
222 * provisioning request recieves a response from first resource server.
223 * @return OC_STACK_OK in case of success and other value otherwise.
225 OCStackResult OCProvisionPairwiseDevices(void *ctx, OicSecCredType_t type, size_t keySize,
226 const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,
227 const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,
228 OCProvisionResultCB resultCallback);
231 * API to send ACL information to device.
233 * @param[in] ctx Application context would be returned in result callback.
234 * @param[in] selectedDeviceInfo Selected target device.
235 * @param[in] acl ACL to provision.
236 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
237 request recieves a response from resource server.
238 * @return OC_STACK_OK in case of success and other value otherwise.
240 OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
242 OCProvisionResultCB resultCallback);
245 * function to save ACL which has several ACE into Acl of SVR.
247 * @param acl ACL to be saved in Acl of SVR.
248 * @return OC_STACK_OK in case of success and other value otherwise.
250 OCStackResult OCSaveACL(const OicSecAcl_t *acl);
253 * this function requests CRED information to resource.
255 * @param[in] ctx Application context would be returned in result callback.
256 * @param[in] selectedDeviceInfo Selected target device.
257 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
258 request recieves a response from resource server.
259 * @return OC_STACK_OK in case of success and other value otherwise.
261 OCStackResult OCGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
262 OCProvisionResultCB resultCallback);
265 * this function requests ACL information to resource.
267 * @param[in] ctx Application context would be returned in result callback.
268 * @param[in] selectedDeviceInfo Selected target device.
269 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
270 request recieves a response from resource server.
271 * @return OC_STACK_OK in case of success and other value otherwise.
273 OCStackResult OCGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
274 OCProvisionResultCB resultCallback);
277 * this function sends Direct-Pairing Configuration to a device.
279 * @param[in] ctx Application context would be returned in result callback.
280 * @param[in] selectedDeviceInfo Selected target device.
281 * @param[in] pconf PCONF pointer.
282 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
283 request recieves a response from resource server.
284 * @return OC_STACK_OK in case of success and other value otherwise.
286 OCStackResult OCProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
287 OicSecPconf_t *pconf,
288 OCProvisionResultCB resultCallback);
291 * API to provision credential to devices.
293 * @param[in] ctx Application context would be returned in result callback.
294 * @param[in] type Type of credentials to be provisioned to the device.
295 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
296 @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
297 * @param[in] resultCallback callback provided by API user, callback will be called when
298 * provisioning request recieves a response from first resource server.
299 * @return OC_STACK_OK in case of success and other value otherwise.
301 OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,
302 const OCProvisionDev_t *pDev1,
303 const OCProvisionDev_t *pDev2,
304 OCProvisionResultCB resultCallback);
306 #ifdef MULTIPLE_OWNER
308 * API to provision preconfigured PIN to device(NOT LIST).
309 * If device does not support the Preconfigured PIN OxM,
310 * OCProvisionPreconfigPin API will update the device's Doxm
311 * and then try preconfigured PIN provisioning once again.
313 * @param[in] ctx Application context would be returned in result callback.
314 * @param[in] targetDeviceInfo Selected target device.
315 * @param[in] preconfigPin string of preconfigured PIN.
316 * @param[in] preconfigPinLen string length of 'preconfigPin'.
317 * @param[in] resultCallback callback provided by API user, callback will be called when
318 * provisioning request recieves a response from first resource server.
319 * @return OC_STACK_OK in case of success and other value otherwise.
321 OCStackResult OCProvisionPreconfigPin(void *ctx,
322 OCProvisionDev_t *targetDeviceInfo,
323 const char *preconfigPin,
324 size_t preconfigPinLen,
325 OCProvisionResultCB resultCallback);
328 * API to add preconfigured PIN to local SVR DB.
330 * @param[in] targetDeviceInfo Selected target device.
331 * @param[in] preconfigPin Preconfig PIN which is used while multiple owner authentication
332 * @param[in] preconfigPinLen Byte length of preconfigPin
333 * @return OC_STACK_OK in case of success and other value otherwise.
335 OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo,
336 const char *preconfigPin,
337 size_t preconfigPinLen);
340 * API to update 'doxm.mom' to resource server.
342 * @param[in] targetDeviceInfo Selected target device.
343 * @param[in] momType Mode of multiple ownership transfer (ref. oic.sec.mom)
344 * @param[in] resultCallback callback provided by API user, callback will be called when
345 * POST 'mom' request recieves a response from resource server.
346 * @return OC_STACK_OK in case of success and other value otherwise.
348 OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
349 const OicSecMomType_t momType, OCProvisionResultCB resultCallback);
352 * API to update 'doxm.oxmsel' to resource server.
354 * @param[in] targetDeviceInfo Selected target device.
355 * @param[in] oxmSelValue Method of multiple ownership transfer (ref. oic.sec.oxm)
356 * @param[in] resultCallback callback provided by API user, callback will be called when
357 * POST 'oxmsel' request recieves a response from resource server.
358 * @return OC_STACK_OK in case of success and other value otherwise.
360 OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
361 const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback);
362 #endif //MULTIPLE_OWNER
365 * Function to unlink devices.
366 * This function will remove the credential & relasionship between the two devices.
368 * @param[in] ctx Application context would be returned in result callback
369 * @param[in] pTargetDev1 fitst device information to be unlinked.
370 * @param[in] pTargetDev2 second device information to be unlinked.
371 * @param[in] resultCallback callback provided by API user, callback will be called when
372 * device unlink is finished.
373 * @return OC_STACK_OK in case of success and other value otherwise.
375 OCStackResult OCUnlinkDevices(void *ctx,
376 const OCProvisionDev_t *pTargetDev1,
377 const OCProvisionDev_t *pTargetDev2,
378 OCProvisionResultCB resultCallback);
381 * Function for device revocation
382 * This function will remove credential of target device from all devices in subnet.
384 * @param[in] ctx Application context would be returned in result callback
385 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
386 * @param[in] pTargetDev Device information to be revoked.
387 * @param[in] resultCallback callback provided by API user, callback will be called when
388 * credential revocation is finished.
389 * @return OC_STACK_OK in case of success and other value otherwise.
390 * if OC_STACK_OK is returned, the caller of this API should wait for callback.
391 * OC_STACK_CONTINUE means operation is success but no need to wait for callback.
393 OCStackResult OCRemoveDevice(void *ctx,
394 unsigned short waitTimeForOwnedDeviceDiscovery,
395 const OCProvisionDev_t *pTargetDev,
396 OCProvisionResultCB resultCallback);
399 * Function to device revocation
400 * This function will remove credential of target device from all devices in subnet.
402 * @param[in] ctx Application context would be returned in result callback
403 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
404 * @param[in] pTargetDev Device information to be revoked.
405 * @param[in] resultCallback callback provided by API user, callback will be called when
406 * credential revocation is finished.
407 * @return OC_STACK_OK in case of success and other value otherwise.
409 OCStackResult OCRemoveDeviceWithUuid(void *ctx,
410 unsigned short waitTimeForOwnedDeviceDiscovery,
411 const OicUuid_t *pTargetUuid,
412 OCProvisionResultCB resultCallback);
415 * Function to reset the target device.
416 * This function will remove credential and ACL of target device from all devices in subnet.
418 * @param[in] ctx Application context would be returned in result callback
419 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
420 * @param[in] pTargetDev Device information to be revoked.
421 * @param[in] resultCallback callback provided by API user, callback will be called when
422 * credential revocation is finished.
423 * @return OC_STACK_OK in case of success and other value otherwise.
425 OCStackResult OCResetDevice(void *ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
426 const OCProvisionDev_t *pTargetDev,
427 OCProvisionResultCB resultCallback,
428 OCClientContextDeleter deleteCallback);
431 * This function resets SVR DB to its factory setting.
433 *@return OC_STACK_OK in case of successful reset and other value otherwise.
435 OCStackResult OCResetSVRDB(void);
438 * This function configures SVR DB as self-ownership.
440 *@return OC_STACK_OK in case of successful configue and other value otherwise.
442 OCStackResult OCConfigSelfOwnership(void);
445 * API to get status of all the devices in current subnet. The status include endpoint information
446 * and doxm information which can be extracted duing owned and unowned discovery. Along with this
447 * information. The API will provide information about devices' status
448 * Device can have following states
449 * - ON/OFF: Device is switched on or off.
451 * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out
452 * variables pOwnedDevList and pUnownedDevList.
454 * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time
455 * will be used for unowned discovery and remaining half for owned discovery. So the wait time should be
456 * equal to or more than 2.
457 * @param[out] pOwnedDevList list of owned devices.
458 * @param[out] pUnownedDevList list of unowned devices.
459 * @return OC_STACK_OK in case of success and other value otherwise.
461 OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
462 OCProvisionDev_t **pOwnedDevList,
463 OCProvisionDev_t **pUnownedDevList);
465 * This method is used to get linked devices' IDs.
467 * @param[in] uuidOfDevice a target device's uuid.
468 * @param[out] uuidList information about the list of linked devices' uuids.
469 * @param[out] numOfDevices total number of linked devices.
470 * @return OC_STACK_OK in case of success and other value otherwise.
472 OCStackResult OCGetLinkedStatus(const OicUuid_t *uuidOfDevice,
473 OCUuidList_t **uuidList,
474 size_t *numOfDevices);
477 * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API.
479 * @param[in] pList Pointer to OCProvisionDev_t which should be deleted.
481 void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList);
484 * API to delete memory allocated to OicUuid_t list.
486 * @param[in] pList Pointer to OicUuid_t list which should be deleted.
488 void OCDeleteUuidList(OCUuidList_t *pList);
491 * This function deletes ACL data.
493 * @param pAcl Pointer to OicSecAcl_t structure.
495 void OCDeleteACLList(OicSecAcl_t *pAcl);
498 * This function deletes PDACL data.
500 * @param pPdAcl Pointer to OicSecPdAcl_t structure.
502 void OCDeletePdAclList(OicSecPdAcl_t *pPdAcl);
504 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
506 * function to provision Trust certificate chain to devices.
508 * @param[in] ctx Application context would be returned in result callback.
509 * @param[in] type Type of credentials to be provisioned to the device.
510 * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
511 * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
512 * @param[in] resultCallback callback provided by API user, callback will be called when
513 * provisioning request recieves a response from first resource server.
514 * @return OC_STACK_OK in case of success and other value otherwise.
516 OCStackResult OCProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
517 const OCProvisionDev_t *selectedDeviceInfo,
518 OCProvisionResultCB resultCallback);
520 * function to save Trust certificate chain into Cred of SVR.
522 * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
523 * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
524 * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
525 * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
526 * @return OC_STACK_OK in case of success and other value otherwise.
528 OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
529 OicEncodingType_t encodingType, uint16_t *credId);
531 * function to register callback, for getting notification for TrustCertChain change.
533 * @param[in] TrustCertChainChangeCB notifier callback function
534 * @return OC_STACK_OK in case of success and other value otherwise.
536 OCStackResult OCRegisterTrustCertChainNotifier(void *cb, TrustCertChainChangeCB CB);
539 * function to de-register TrustCertChain notification callback.
541 void OCRemoveTrustCertChainNotifier(void);
544 * Function to read Trust certificate chain from SVR.
545 * Caller must free when done using the returned trust certificate
546 * @param[in] credId CredId of trust certificate chain in SVR.
547 * @param[out] trustCertChain Trust certificate chain.
548 * @param[out] chainSize Size of trust certificate chain
549 * @return OC_STACK_OK in case of success and other value otherwise.
551 OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
555 * Function to select appropriate security provisioning method.
557 * @param[in] supportedMethods Array of supported methods
558 * @param[in] numberOfMethods number of supported methods
559 * @param[out] selectedMethod Selected methods
560 * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)
561 * @return OC_STACK_OK on success
563 OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,
564 size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType);
567 * This function sets the callback to utilize peer certificate information
569 OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback);
571 #endif // __WITH_DTLS__ || __WITH_TLS__
576 #endif // __cplusplus
578 #endif /* OCPROVISIONINGMANAGER_H_ */