replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / doxmresource.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef IOTVT_SRM_DOXM_H
22 #define IOTVT_SRM_DOXM_H
23
24 #include "octypes.h"
25 #ifdef MULTIPLE_OWNER
26 #include "cacommon.h"
27 #endif //MULTIPLE_OWNER
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /**
34  * Initialize DOXM resource by loading data from persistent storage.
35  *
36  * @return ::OC_STACK_OK for Success, otherwise some error value.
37  */
38 OCStackResult InitDoxmResource();
39
40 /**
41  * Perform cleanup for DOXM resources.
42  *
43  * @return ::OC_STACK_OK for Success, otherwise some error value.
44  */
45 OCStackResult DeInitDoxmResource();
46
47 /**
48  * This method is used by SRM to retrieve DOXM resource data..
49  *
50  * @return reference to @ref OicSecDoxm_t, binary format of Doxm resource data.
51  */
52 const OicSecDoxm_t* GetDoxmResourceData();
53
54 /**
55  * This method converts CBOR DOXM into binary DOXM.
56  * The CBOR DOXM can be from persistent database or
57  * or received as PUT/POST request.
58  *
59  * @param cborPayload is a doxm data in cbor.
60  * @note Caller needs to invoke OCFree after done using the return pointer.
61  * @param doxm is the pointer to @ref OicSecDoxm_t.
62  * @param size of the cborPayload. In case value is 0, CBOR_SIZE value is assigned.
63  *
64  * @return ::OC_STACK_OK for Success, otherwise some error value.
65  */
66 OCStackResult CBORPayloadToDoxm(const uint8_t *cborPayload, size_t size,
67                                 OicSecDoxm_t **doxm);
68
69 /**
70  * This method converts DOXM data into CBOR format.
71  * Caller needs to invoke 'free' when finished done using
72  * return string.
73  *
74  * @param doxm Pointer to @ref OicSecDoxm_t.
75  * @note Caller needs to invoke OCFree after done using the return pointer.
76  * @param cborPayload is the payload of the cbor.
77  * @param cborSize is the size of the cbor payload. Passed parameter should not be NULL.
78  * @param rwOnly indicates whether convertingpayload has all properties or read-write properties only.
79  *
80  * @return ::OC_STACK_OK for Success, otherwise some error value.
81  */
82 OCStackResult DoxmToCBORPayload(const OicSecDoxm_t * doxm, uint8_t **cborPayload,
83                                 size_t *cborSize, bool rwOnly);
84
85 #if defined(__WITH_DTLS__) || defined (__WITH_TLS__)
86 /**
87  * API to save the seed value to generate device UUID.
88  *
89  * @param seed buffer of seed value.
90  * @param seedSize byte length of seed
91  *
92  * @return ::OC_STACK_OK for Success, otherwise some error value.
93  */
94 OCStackResult SetDoxmDeviceIDSeed(const uint8_t* seed, size_t seedSize);
95 #endif
96
97 /**
98  * This method returns the SRM device ID for this device.
99  *
100  * @return ::OC_STACK_OK for Success, otherwise some error value.
101  */
102 OCStackResult GetDoxmDeviceID(OicUuid_t *deviceID);
103
104 /**
105  * This method changes the SRM device ID for this device.
106  * This api will update device Id iff device is in unowned state.
107  * @return ::OC_STACK_OK for Success, otherwise some error value.
108  */
109 OCStackResult SetDoxmDeviceID(const OicUuid_t *deviceID);
110
111
112 /**
113  * Gets the OicUuid_t value for the owner of this device.
114  *
115  * @param devownerid a pointer to be assigned to the devownerid property
116  * @return ::OC_STACK_OK if devownerid is assigned correctly, else ::OC_STACK_ERROR.
117  */
118 OCStackResult GetDoxmDevOwnerId(OicUuid_t *devownerid);
119
120 /**
121  * Gets the bool state of "isOwned" property on the doxm resource.
122  *
123  * @param isOwned a pointer to be assigned to isOwned property
124  * @return ::OC_STACK_OK if isOwned is assigned correctly, else ::OC_STACK_ERROR.
125  */
126 OCStackResult GetDoxmIsOwned(bool *isOwned);
127
128 /**
129  * Gets the OicUuid_t value for the rowneruuid of the doxm resource.
130  *
131  * @param rowneruuid a pointer to be assigned to the rowneruuid property
132  * @return ::OC_STACK_OK if rowneruuid is assigned correctly, else ::OC_STACK_ERROR.
133  */
134 OCStackResult GetDoxmRownerId(OicUuid_t *rowneruuid);
135
136 #ifdef MULTIPLE_OWNER
137 /**
138  * Compare the UUID to SubOwner.
139  *
140  * @param[in] uuid device UUID
141  *
142  * @return true if uuid exists in the SubOwner list of doxm, else false.
143  */
144 bool IsSubOwner(const OicUuid_t* uuid);
145 #endif //MULTIPLE_OWNER
146
147 /** This function deallocates the memory for OicSecDoxm_t .
148  *
149  * @param doxm is the pointer to @ref OicSecDoxm_t.
150  */
151 void DeleteDoxmBinData(OicSecDoxm_t* doxm);
152
153 /**
154  * Function to restore doxm resurce to initial status.
155  * This function will use in case of error while ownership transfer
156  */
157 void RestoreDoxmToInitState();
158
159 #if defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER)
160 /**
161  * Callback function to handle MOT DTLS handshake result.
162  * @param[out]   object           remote device information.
163  * @param[out]   errorInfo        CA Error information.
164  */
165 void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object,
166                                 const CAErrorInfo_t *errorInfo);
167 #endif //__WITH_DTLS__ && MULTIPLE_OWNER
168
169 /**
170  * Internal function to change doxm resource to Ready for Normal Operation.
171  *
172  * @param newROwner new owner
173  *
174  * @retval ::OC_STACK_OK for Success, otherwise some error value
175  */
176 OCStackResult SetDoxmSelfOwnership(const OicUuid_t* newROwner);
177
178 /**
179  * Function to set a MOT status
180  *
181  * @param enable whether the MOT is enabled. (true=enable, false=disable)
182  *
183  * @retval ::OC_STACK_OK for Success, otherwise some error value
184  */
185 OCStackResult SetMOTStatus(bool enable);
186
187 /**
188  * Function to remove the Sub Owner (include ACL/Cred)
189  *
190  * @param subOwner UUID of Sub Owner to be removed.
191  *
192  * @retVal ::OC_STACK_OK for success, otherwise some error value.
193  */
194 OCStackResult RemoveSubOwner(const OicUuid_t* subOwner);
195
196 /**
197  * Function to set a max number of sub owner.
198  *
199  * @param maxSubOwner Max number of sub owner.
200  *
201  * @retVal ::OC_STACK_OK for success, otherwise some error value.
202  */
203 OCStackResult SetNumberOfSubOwner(size_t maxSubOwner);
204
205
206 #ifdef __cplusplus
207 }
208 #endif
209
210 #endif //IOTVT_SRM_DOXMR_H