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