replace : iotivity -> iotivity-sec
[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, bool writableOnly);
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 #ifdef MULTIPLE_OWNER
68 /**
69  * Function to check the pstat access of SubOwner
70  *
71  * @param[in] cborPayload CBOR payload of pstat
72  * @param[in] size Byte length of cborPayload
73  *
74  * @return ::true for valid access, otherwise invalid access
75  */
76 bool IsValidPstatAccessForSubOwner(const uint8_t *cborPayload, size_t size);
77 #endif
78
79
80 /** This function deallocates the memory for OicSecPstat_t.
81  *
82  * @param pstat is the pointer to @ref OicSecPstat_t.
83  */
84 void DeletePstatBinData(OicSecPstat_t* pstat);
85
86 /**
87  * Function to restore pstat resurce to initial status.
88  * This function will use in case of error while ownership transfer
89  */
90 void RestorePstatToInitState();
91
92 /**
93  * Internal function to update resource owner
94  *
95  * @param newROwner new owner
96  *
97  * @retval ::OC_STACK_OK for Success, otherwise some error value
98  */
99 OCStackResult SetPstatRownerId(const OicUuid_t* newROwner);
100
101 /**
102  * Gets the OicUuid_t value for the rownerid of the pstat resource.
103  *
104  * @param rowneruuid a pointer to be assigned to the rowneruuid property
105  * @return ::OC_STACK_OK if rowneruuid is assigned correctly, else ::OC_STACK_ERROR.
106  */
107 OCStackResult GetPstatRownerId(OicUuid_t *rowneruuid);
108
109 /**
110  * This function returns the "isop" status of the device.
111  *
112  * @return true iff pstat.isop == 1, else false
113  */
114 bool GetPstatIsop();
115
116 /**
117  * Internal function to change pastat resource to Ready for Normal Operation.
118  *
119  * @param newROwner new owner
120  *
121  * @retval ::OC_STACK_OK for Success, otherwise some error value
122  */
123 OCStackResult SetPstatSelfOwnership(const OicUuid_t* newROwner);
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif //IOTVT_SRM_PSTATR_H