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_CXX_H
22 #define _OCPROVISIONINGMANAGER_CXX_H
26 #include "pinoxmcommon.h"
27 #include "ocprovisioningmanager.h"
29 #include "OCPlatform_impl.h"
33 class OCSecureResource;
35 typedef std::vector<std::shared_ptr<OCSecureResource>> DeviceList_t;
36 typedef std::vector<OicUuid_t> UuidList_t;
37 typedef std::vector<OCProvisionResult_t> PMResultList_t;
38 typedef std::function<void(PMResultList_t *result, int hasError)> ResultCallBack;
40 struct ProvisionContext
42 ResultCallBack callback;
43 ProvisionContext(ResultCallBack cb) : callback(cb){}
47 * @brief: This class is for credential's to be set to devices.
48 * The types supported are
50 * 1: symmetric pair-wise key
51 * 2: symmetric group key
53 * 8: signed asymmetric key (aka certificate)
58 OicSecCredType_t type;
61 Credential() = default;
62 Credential(OicSecCredType_t type, size_t size) : type(type), keySize(size)
65 OicSecCredType_t getCredentialType() const
70 size_t getCredentialKeySize() const
75 void setCredentialType(OicSecCredType_t type)
80 void setCredentialKeySize(size_t keySize)
82 this->keySize = keySize;
90 * The API is responsible for initializaton of the provisioning manager. It will load
91 * provisioning database which have owned device's list and their linked status.
93 * @param[in] dbPath file path of the sqlite3 db
95 * @return OC_STACK_OK in case of success and other value otherwise.
97 static OCStackResult provisionInit(const std::string& dbPath);
100 * API is responsible for discovery of devices in it's subnet. It will list
101 * all the device in subnet which are not yet owned.
103 * @param[in] timeout Timeout in seconds, time util which function will listen to
104 * responses from client before returning the list of devices.
105 * @param[out] list List of candidate devices to be provisioned
106 * @return OC_STACK_OK in case of success and other value otherwise.
108 static OCStackResult discoverUnownedDevices(unsigned short timeout,
112 * API is responsible for discovery of devices in it's subnet. It will list
113 * all the device in subnet which are already owned by calling provioning client
115 * @param[in] timeout Timeout in seconds, time util which function will listen to
116 * responses from client before returning the list of devices.
117 * @param[out] list List of owned devices
118 * @return OC_STACK_OK in case of success and other value otherwise.
120 static OCStackResult discoverOwnedDevices(unsigned short timeout,
124 * API for registering Ownershipt transfer methods for a particular transfer Type
126 * @param[in] oxm Ownership transfer method
127 * @param[in] callbackData Methods for ownership transfer
128 * @param[in] InputPinCallback Method to input pin for verification
129 * @return OC_STACK_OK in case of success and other value otherwise.
131 static OCStackResult setOwnerTransferCallbackData(OicSecOxm_t oxm,
132 OTMCallbackData_t* callbackData, InputPinCallback inputPin);
135 * API to get status of all the devices in current subnet. The status include endpoint
136 * information and doxm information which can be extracted duing owned and unowned
137 * discovery. Along with this information, API will provide information about
139 * Device can have following states
140 * - ON/OFF: Device is switched on or off.
142 * @param[in] timeout waitime for the API.
143 * @param[out] pOwnedDevList list of owned devices.
144 * @param[out] pUnownedDevList list of unowned devices.
145 * @return OC_STACK_OK in case of success and other value otherwise.
147 static OCStackResult getDevInfoFromNetwork(unsigned short timeout,
148 DeviceList_t &ownedDevList,
149 DeviceList_t &unownedDevList);
154 * This class represents a Secure virtual Device, which can be provisioned by the
155 * provisioning client.
157 class OCSecureResource
160 std::weak_ptr<std::recursive_mutex> m_csdkLock;
161 OCProvisionDev_t *devPtr; // pointer to device.
165 OCSecureResource(std::weak_ptr<std::recursive_mutex> csdkLock, OCProvisionDev_t *dPtr);
170 * API to provision credentials between two devices and ACLs for the devices who
173 * @param[in] cred Type of credentials & key size to be provisioned to the device.
174 * @param[in] acl1 ACL for device 1. If this is not required set NULL.
175 * @param[in] device2 Second device to be provsioned.
176 * @param[in] acl2 ACL for device 2. If this is not required set NULL.
177 * @param[in] resultCallback Callback will be called when provisioning request recieves
178 * a response from first resource server.
179 * @return OC_STACK_OK in case of success and other value otherwise.
181 OCStackResult provisionPairwiseDevices(const Credential &cred, const OicSecAcl_t* acl1,
182 const OCSecureResource &device2, const OicSecAcl_t* acl2,
183 ResultCallBack resultCallback);
186 * API to do ownership transfer for un-owned device.
188 * @param[in] resultCallback Result callback function to be invoked when
189 * ownership transfer finished.
190 * @return OC_STACK_OK in case of success and other value otherwise.
192 OCStackResult doOwnershipTransfer(ResultCallBack resultCallback);
195 * API to send ACL information to resource.
197 * @param[in] acl ACL to provision.
198 * @param[in] resultCallback callback will be called when provisioning request
199 * recieves a response from resource server.
200 * @return OC_STACK_OK in case of success and other value otherwise.
202 OCStackResult provisionACL(const OicSecAcl_t* acl,
203 ResultCallBack resultCallback);
206 * API to provision credential to devices.
208 * @param[in] cred Type of credentials to be provisioned to the device.
209 * @param[in] device2 Second device' instance,respresenting resourceto be provsioned.
210 * @param[in] resultCallback callback will be called when provisioning request recieves
211 * a response from first resource server.
212 * @return OC_STACK_OK in case of success and other value otherwise.
214 OCStackResult provisionCredentials(const Credential &cred,
215 const OCSecureResource &device2,
216 ResultCallBack resultCallback);
219 * API to remove the credential & relasionship between the two devices.
221 * @param[in] pTargetDev2 second device information to be unlinked.
222 * @param[in] resultCallback callback provided by API user, callback will be called when
223 * device unlink is finished.
224 * @return OC_STACK_OK in case of success and other value otherwise.
226 OCStackResult unlinkDevices(const OCSecureResource &device2,
227 ResultCallBack resultCallback);
230 * API to remove device credential from all devices in subnet.
232 * @param[in] resultCallback callback provided by API user, callback will be called when
233 * credential revocation is finished.
234 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device
235 * discovery.(seconds)
236 * @return OC_STACK_OK in case of success and other value otherwise.
238 OCStackResult removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery,
239 ResultCallBack resultCallback);
242 * This method is used to get linked devices' IDs.
244 * @param[out] uuidList information about the list of linked devices' uuids.
245 * @param[out] numOfDevices total number of linked devices.
246 * @return OC_STACK_OK in case of success and other value otherwise.
248 OCStackResult getLinkedDevices(UuidList_t &uuidList);
251 * API to get the DeviceID of this resource
253 std::string getDeviceID();
255 OCProvisionDev_t* getDevPtr()const;
258 * This function returns the Device's IP addr.
260 std::string getDevAddr();
263 * This function returns the Device's Status
265 int getDeviceStatus();
268 * This function provides the OWNED status of the device.
270 bool getOwnedStatus();
274 * Common callback wrapper, which will be called from OC-APIs.
276 static void callbackWrapper(void* ctx, int nOfRes,
277 OCProvisionResult_t *arr, bool hasError);
279 void validateSecureResource();
283 #endif //_OCPROVISIONINGMANAGER_CXX_H