Imported Upstream version 1.2.0
[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 "amsmgr.h"
29 #include <stdlib.h>
30 #include <stdint.h>
31
32 typedef struct AmsMgrContext AmsMgrContext_t;
33
34 typedef enum PEState
35 {
36     STOPPED = 0,              //Policy engine state machine is not running
37     AWAITING_REQUEST,         //Can process new request
38     AWAITING_AMS_RESPONSE,    //Can't process new request; waiting for AMS response
39     BUSY                      //Can't process new request as processing other requests
40 } PEState_t;
41
42 typedef struct PEContext
43 {
44     PEState_t   state;
45     OicUuid_t   subject;
46     char        resource[MAX_URI_LENGTH];
47     OicSecSvrType_t resourceType;
48     uint16_t    permission;
49     bool        matchingAclFound;
50     bool        amsProcessing;
51     SRMAccessResponse_t retVal;
52     AmsMgrContext_t     *amsMgrContext;
53
54 #ifdef _ENABLE_MULTIPLE_OWNER_
55     uint8_t* payload;
56     size_t payloadSize;
57 #endif //_ENABLE_MULTIPLE_OWNER_
58 } PEContext_t;
59
60 /**
61  * Check whether a request should be allowed.
62  *
63  * @param context is the pointer to Policy Engine context to use.
64  * @param subjectId is the pointer to Id of the requesting entity.
65  * @param resource is the pointer to URI of Resource being requested.
66  * @param permission is the requested permission.
67  *
68  * @return ::ACCESS_GRANTED if request should go through, otherwise some flavor of ACCESS_DENIED.
69  */
70 SRMAccessResponse_t CheckPermission(
71     PEContext_t     *context,
72     const OicUuid_t *subjectId,
73     const char      *resource,
74     const uint16_t  requestedPermission);
75
76 /**
77  * Initialize the Policy Engine. Call this before calling CheckPermission().
78  * TODO Eventually this and DeInit() need to be called from a new
79  *      "SRMInit(SRMContext_t *)" function, TBD after BeachHead.
80  * @param context is the pointer to Policy Engine context to initialize.
81  *
82  * @return ::OC_STACK_OK for Success, otherwise some error value.
83  */
84 OCStackResult InitPolicyEngine(PEContext_t *context);
85
86 /**
87  * De-Initialize the Policy Engine. Call this before exiting to allow Policy
88  * Engine to do cleanup on context.
89  *
90  * @param context is the pointer to Policy Engine context to de-initialize.
91  */
92 void DeInitPolicyEngine(PEContext_t *context);
93
94 /**
95  * Get CRUDN permission for a method.
96  *
97  * @param method is CRUDN permission being seeked.
98  *
99  * @return the uint16_t CRUDN permission .
100  */
101 uint16_t GetPermissionFromCAMethod_t(const CAMethod_t method);
102
103 /*
104  * This method reset Policy Engine context to default state and update
105  * it's state to @param state.
106  *
107  * @param context is the policy engine context.
108  * @param state set Policy engine state to this.
109  */
110 void SetPolicyEngineState(PEContext_t *context, const PEState_t state);
111
112 typedef OCStackResult (*GetSvrRownerId_t)(OicUuid_t *rowner);
113
114 #endif //IOTVT_SRM_PE_H