Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / policyengine.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_PE_H
22 #define IOTVT_SRM_PE_H
23
24 #include "ocstack.h"
25 #include "logger.h"
26 #include "securevirtualresourcetypes.h"
27 #include "cainterface.h"
28 #include <stdlib.h>
29 #include <stdint.h>
30
31
32 typedef enum PEState
33 {
34     STOPPED = 0,
35     AWAITING_REQUEST,
36     BUSY
37 } PEState_t;
38
39 typedef struct PEContext
40 {
41     PEState_t   state;
42     OicUuid_t   *subject;
43     char        *resource;
44     uint16_t    permission;
45     bool        matchingAclFound;
46     SRMAccessResponse_t retVal;
47 } PEContext_t;
48
49 /**
50  * Check whether a request should be allowed.
51  *
52  * @param   context     Pointer to Policy Engine context to use.
53  * @param   subjectId   Pointer to Id of the requesting entity.
54  * @param   resource    Pointer to URI of Resource being requested.
55  * @param   permission  Requested permission.
56  *
57  * @return  ACCESS_GRANTED if request should go through,
58  *          otherwise some flavor of ACCESS_DENIED
59  */
60 SRMAccessResponse_t CheckPermission(
61     PEContext_t     *context,
62     const OicUuid_t *subjectId,
63     const char      *resource,
64     const uint16_t  requestedPermission);
65
66 /**
67  * Initialize the Policy Engine. Call this before calling CheckPermission().
68  * TODO Eventually this and DeInit() need to be called from a new
69  *      "SRMInit(SRMContext_t *)" function, TBD after BeachHead.
70  * @param   context     Pointer to Policy Engine context to initialize.
71  * @return  OC_STACK_OK for Success, otherwise some error value
72  */
73 OCStackResult InitPolicyEngine(PEContext_t *context);
74
75 /**
76  * De-Initialize the Policy Engine. Call this before exiting to allow Policy
77  * Engine to do cleanup on context.
78  * @param   context     Pointer to Policy Engine context to de-initialize.
79  * @return  none
80  */
81 void DeInitPolicyEngine(PEContext_t *context);
82
83 /**
84  * Return the uint16_t CRUDN permission corresponding to passed CAMethod_t.
85  */
86 uint16_t GetPermissionFromCAMethod_t(const CAMethod_t method);
87
88 #endif //IOTVT_SRM_PE_H