1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 IOTVT_SRM_DOXM_H
22 #define IOTVT_SRM_DOXM_H
27 #endif //MULTIPLE_OWNER
33 // NOTE that this enum must match the gDoxmPropertyAccessModes
34 // table in doxmresource.c
43 #endif // MULTIPLE_OWNER
51 * Initialize DOXM resource by loading data from persistent storage.
53 * @return ::OC_STACK_OK for Success, otherwise some error value.
55 OCStackResult InitDoxmResource();
58 * Perform cleanup for DOXM resources.
60 * @return ::OC_STACK_OK for Success, otherwise some error value.
62 OCStackResult DeInitDoxmResource();
65 * This method is used by SRM to retrieve DOXM resource data.
67 * @return reference to @ref OicSecDoxm_t, binary format of Doxm resource data.
69 const OicSecDoxm_t* GetDoxmResourceData();
72 * This method converts CBOR DOXM into binary DOXM.
73 * The CBOR DOXM can be from persistent database or
74 * or received as PUT/POST request.
76 * @param cborPayload is a doxm data in cbor.
77 * @note Caller needs to invoke OCFree after done using the return pointer.
78 * @param doxm is the pointer to @ref OicSecDoxm_t.
79 * @param size of the cborPayload. In case value is 0, CBOR_SIZE value is assigned.
81 * @return ::OC_STACK_OK for Success, otherwise some error value.
83 OCStackResult CBORPayloadToDoxm(const uint8_t *cborPayload, size_t size,
87 * Converts DOXM into CBOR payload, including only the
88 * Properties marked "true" in the propertiesToInclude array.
90 * @param doxm pointer to the initialized doxm structure.
91 * @param payload pointer to doxm cbor payload.
92 * @param size of the cbor payload converted. It is 0 in case of error,
93 * else a positive value if succcessful.
94 * @param propertiesToInclude Array of bools, size "DOXM_PROPERTY_COUNT",
95 * where "true" indicates the corresponding property should be
96 * included in the CBOR representation that is created.
98 * @return ::OC_STACK_OK for Success, otherwise some error value.
100 OCStackResult DoxmToCBORPayloadPartial(const OicSecDoxm_t *doxm,
101 uint8_t **payload, size_t *size, const bool *propertiesToInclude);
105 * Converts DOXM into cbor payload, including all Properties for a
106 * full representation.
108 * @param doxm pointer to the initialized doxm structure.
109 * @param payload pointer to doxm cbor payload.
110 * @param size of the cbor payload converted. It is 0 in case of error,
111 * else a positive value if succcessful.
113 * @return ::OC_STACK_OK for Success, otherwise some error value.
115 OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm,
116 uint8_t **payload, size_t *size);
118 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
120 * API to save the seed value to generate device UUID.
122 * @param seed buffer of seed value.
123 * @param seedSize byte length of seed
125 * @return ::OC_STACK_OK for Success, otherwise some error value.
127 OCStackResult SetDoxmDeviceIDSeed(const uint8_t* seed, size_t seedSize);
131 * Get the doxm.deviceuuid value for this device.
133 * @param[out] deviceuuid ptr to contain a copy of doxm.deviceuuid value.
134 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
136 OCStackResult GetDoxmDeviceID(OicUuid_t *deviceuuid);
139 * Set the doxm.deviceuuid value for this device.
141 * @param[in] deviceuuid ptr to value to be copied into doxm.deviceuuid.
142 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
144 OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceuuid);
147 * Get the doxm.devowneruuid value for this device.
149 * @param[out] devowneruuid ptr to contain a copy of doxm.devowneruuid value.
150 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
152 OCStackResult GetDoxmDevOwnerId(OicUuid_t *devowneruuid);
155 * Set the doxm.deviceuuid value for this device.
157 * @param[in] deviceuuid ptr to value to be copied into doxm.deviceuuid.
158 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
160 OCStackResult SetDoxmDevOwnerId(const OicUuid_t *devowneruuid);
163 * Get the doxm.isowned value for this device.
165 * @param[out] isowned ptr to contain a copy of doxm.isowned value.
166 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
168 OCStackResult GetDoxmIsOwned(bool *isowned);
171 * Set the doxm.isowned value for this device.
173 * @param[in] isowned ptr to value to be copied into doxm.isowned.
174 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
176 OCStackResult SetDoxmIsOwned(const bool isowned);
179 * Get the doxm.rowneruuid value for this device.
181 * @param[out] rowneruuid ptr to contain a copy of rowneruuid value.
182 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
184 OCStackResult GetDoxmRownerId(OicUuid_t *rowneruuid);
187 * Set the doxm.rowneruuid value for this device.
189 * @param[in] rowneruuid ptr to value to be copied into doxm.rowneruuid.
190 * @return ::OC_STACK_OK if value is copied successfully, else ::OC_STACK_ERROR.
192 OCStackResult SetDoxmRownerId(const OicUuid_t *rowneruuid);
194 #ifdef MULTIPLE_OWNER
196 * Compare the UUID to SubOwner.
198 * @param[in] uuid device UUID
200 * @return true if uuid exists in the SubOwner list of doxm, else false.
202 bool IsSubOwner(const OicUuid_t* uuid);
205 * Function to set a MOT status
207 * @param enable whether the MOT is enabled. (true=enable, false=disable)
209 OCStackResult SetMOTStatus(bool enable);
211 #endif //MULTIPLE_OWNER
213 /** This function deallocates the memory for OicSecDoxm_t .
215 * @param doxm is the pointer to @ref OicSecDoxm_t.
217 void DeleteDoxmBinData(OicSecDoxm_t* doxm);
219 /** This function checks if two sets of /oic/sec/doxm properties are identical.
221 * @param doxm1 is a pointer to the first @ref OicSecDoxm_t data.
222 * @param doxm2 is a pointer to the second @ref OicSecDoxm_t data.
224 * @return true if all of the properties are identical, else false.
226 bool AreDoxmBinPropertyValuesEqual(OicSecDoxm_t* doxm1, OicSecDoxm_t* doxm2);
229 * Function to restore doxm resurce to initial status.
230 * This function will use in case of error while ownership transfer
232 void RestoreDoxmToInitState();
234 #if defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER)
236 * Callback function to handle MOT DTLS handshake result.
237 * @param[out] object remote device information.
238 * @param[out] errorInfo CA Error information.
240 CAResult_t MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object,
241 const CAErrorInfo_t *errorInfo);
242 #endif //__WITH_DTLS__ && MULTIPLE_OWNER
245 * Internal function to change doxm resource to Ready for Normal Operation.
247 * @param newROwner new owner
249 * @retval ::OC_STACK_OK for Success, otherwise some error value
251 OCStackResult SetDoxmSelfOwnership(const OicUuid_t* newROwner);
254 * Internal function to update the writable properties of an /oic/sec/doxm
255 * struct with the values from another /oic/sec/doxm struct.
257 * @param src is a pointer to the source @ref OicSecDoxm_t data.
258 * @param dst is a pointer to the destination @ref OicSecDoxm_t data.
260 * @retval ::OC_STACK_OK for Success, otherwise some error value
262 OCStackResult DoxmUpdateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst);
268 #endif //IOTVT_SRM_DOXMR_H