Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / pstatresource.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_PSTATR_H
22 #define IOTVT_SRM_PSTATR_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /**
29  * Initialize Pstat resource by loading data from persistent storage.
30  *
31  * @return ::OC_STACK_OK for Success, otherwise some error value.
32  */
33 OCStackResult InitPstatResource();
34
35 /**
36  * Perform cleanup for Pstat resources.
37  *
38  * @return ::OC_STACK_OK for Success, otherwise some error value.
39  */
40 OCStackResult DeInitPstatResource();
41
42 /**
43  * This method converts PSTAT into the cbor payload.
44  *
45  * @param pstat pointer to the initialized pstat structure.
46  * @param cborPayload pointer to pstat cbor payload.
47  * @param size of the cbor payload converted. It is 0 in case of error,
48  * else a positive value if succcessful.
49  *
50  * @return ::OC_STACK_OK for Success, otherwise some error value.
51  */
52  OCStackResult PstatToCBORPayload(const OicSecPstat_t *pstat, uint8_t **cborPayload,
53                                   size_t *cborSize);
54
55 /**
56  * This method converts cbor into PSTAT data.
57  *
58  * @param cborPayload is the pstat data in cbor format.
59  * @param size of the cborPayload. In case 0 is provided it assigns CBOR_SIZE (255) value.
60  * @param pstat pointer to @ref OicSecPstat_t.
61   *
62   * @return ::OC_STACK_OK for Success, otherwise some error value.
63  */
64  OCStackResult CBORPayloadToPstat(const uint8_t *cborPayload, const size_t cborSize,
65                                   OicSecPstat_t **pstat);
66
67 /** This function deallocates the memory for OicSecPstat_t.
68  *
69  * @param pstat is the pointer to @ref OicSecPstat_t.
70  */
71 void DeletePstatBinData(OicSecPstat_t* pstat);
72
73 /**
74  * Function to restore pstat resurce to initial status.
75  * This function will use in case of error while ownership transfer
76  */
77 void RestorePstatToInitState();
78
79 /**
80  * Internal function to update resource owner
81  *
82  * @param newROwner new owner
83  *
84  * @retval ::OC_STACK_OK for Success, otherwise some error value
85  */
86 OCStackResult SetPstatRownerId(const OicUuid_t* newROwner);
87
88 /**
89  * Gets the OicUuid_t value for the rownerid of the pstat resource.
90  *
91  * @param rowneruuid a pointer to be assigned to the rowneruuid property
92  * @return ::OC_STACK_OK if rowneruuid is assigned correctly, else ::OC_STACK_ERROR.
93  */
94 OCStackResult GetPstatRownerId(OicUuid_t *rowneruuid);
95
96 /**
97  * This function returns the "isop" status of the device.
98  *
99  * @return true iff pstat.isop == 1, else false
100  */
101 bool GetPstatIsop();
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif //IOTVT_SRM_PSTATR_H