Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / amsmgr.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_AMSMGR_H
22 #define IOTVT_SRM_AMSMGR_H
23
24 #include <stdlib.h>
25 #include <stdint.h>
26
27 #include "ocstack.h"
28 #include "logger.h"
29 #include "policyengine.h"
30 #include "securevirtualresourcetypes.h"
31 #include "cainterface.h"
32
33 typedef struct PEContext PEContext_t;
34 /**
35  * The AMS context.
36  */
37 typedef struct AmsMgrContext
38 {
39     OicUuid_t           amsDeviceId;  /**< DeviceID of the oic.sec.ams service. */
40     CAEndpoint_t        *endpoint;
41     CARequestInfo_t     *requestInfo;
42 } AmsMgrContext_t;
43
44 /**
45  * This method updates AmsMgr context's endpoint & requestInfo.
46  *
47  * @param context is the policy engine context.
48  * @param endpoint is the CA Endpoint info of the requester.
49  * @param requestInfo is the CA RequestInfo of the requester.
50  *
51  * @return ::OC_STACK_OK if successful, else other value in case of error.
52  */
53 OCStackResult UpdateAmsMgrContext(PEContext_t *context,
54                                   const CAEndpoint_t *endpoint,
55                                   const CARequestInfo_t *requestInfo);
56
57 /**
58  * This method is called by PolicyEngine to Discover AMS service.
59  * It sends muticast discovery request such as
60  * /oic/sec/doxm?deviceid="AMSSrvcDeviceID" to discover AMS service
61  * with deviceId="AMSSrvcDeviceID".
62  *
63  * @param context is the policy engine context.
64  *
65  * @return ::OC_STACK_OK,If able to successfully send multicast discovery request.
66  * else ::OC_STACK_ERROR, If unable to successfully send multicast discovery request
67  * due to error.
68  */
69 OCStackResult DiscoverAmsService(PEContext_t *context);
70
71 /**
72  * This method sends unicast request to retrieve the secured port info of the
73  * discovered AMS service. It sends unicast discovery request such as
74  * /oic/res?rt="oic.sec.doxm" to the discovered AMS service.
75  *
76  * @param context is the policy engine context.
77  *
78  * @return ::OC_STACK_OK,If able to successfully send unicast discovery request.
79  * else ::OC_STACK_ERROR, If unable to successfully send unicast discovery request
80  * due to error.
81  */
82 OCStackResult SendUnicastSecurePortDiscovery(PEContext_t *context,
83                                              OCDevAddr *devAddr,
84                                              OCConnectivityType connType);
85
86 /**
87  * This method sends unicast request to AMS service to get ACL for
88  * the Subject and/or Resource. It sends unicast request such as
89  * /oic/sec/acl?sub="subjectId";rsrc="/a/led" to get the ACL for
90  * the subject & resource.
91  *
92  * @param context is the policy engine context.
93  *
94  * @return ::OC_STACK_OK, If able to successfully send unicast ACL request.
95  * ::OC_STACK_ERROR, If unable to successfully send unicast ACL request due to error.
96  *
97  */
98 OCStackResult SendAclReq(PEContext_t *context,
99                          OCDevAddr *devAddr,
100                          OCConnectivityType connType,
101                          uint16_t securedPort);
102
103 /*
104  * This method is used by Policy engine to checks Amacl resource.
105  * If Amacl is found then it fills up context->amsMgrContext->amsDeviceId
106  * with amsID of the Amacl else leaves it empty.
107  *
108  * @param context is the policy engine context.
109  *
110  * @return true, if Amacl for the resource is found. false, if Amacl for the
111  * resource is not found
112  */
113 bool FoundAmaclForRequest(PEContext_t *context);
114
115 /*
116  * This method is used by Policy engine to process AMS request.
117  *
118  * @param context is the policy engine context.
119  */
120 void ProcessAMSRequest(PEContext_t *context);
121
122 /*
123  * This method is used by Policy engine to free AMS context requestInfo/
124  *
125  * @param requestInfo is the pointer to @ref CARequestInfo_t.
126  */
127 void FreeCARequestInfo(CARequestInfo_t *requestInfo);
128
129 #endif //IOTVT_SRM_AMSMGR_H