1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include "resourcemanager.h"
23 #include "securevirtualresourcetypes.h"
24 #include "aclresource.h"
25 #include "pstatresource.h"
26 #include "doxmresource.h"
27 #include "credresource.h"
28 #include "svcresource.h"
29 #include "amaclresource.h"
30 #include "oic_malloc.h"
31 #include "oic_string.h"
35 //#ifdef DIRECT_PAIRING
36 #include "pconfresource.h"
37 #include "dpairingresource.h"
38 //#endif // DIRECT_PAIRING
39 #include "verresource.h"
44 #include "crlresource.h"
45 #endif // __WITH_X509__
47 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
48 OCEntityHandlerResult ehRet, const char *rspPayload)
50 OIC_LOG (DEBUG, TAG, "SRM sending SRM response");
51 OCEntityHandlerResponse response = {.requestHandle = NULL};
54 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
56 response.requestHandle = ehRequest->requestHandle;
57 response.resourceHandle = ehRequest->resource;
58 response.ehResult = ehRet;
59 response.payload = (OCPayload*)(&ocPayload);
60 response.payload->type = PAYLOAD_TYPE_SECURITY;
61 ((OCSecurityPayload*)response.payload)->securityData = (char *)rspPayload;
62 response.persistentBufferFlag = 0;
64 return OCDoResponse(&response);
66 return OC_STACK_ERROR;
69 OCStackResult SendSRMCBORResponse(const OCEntityHandlerRequest *ehRequest,
70 OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size)
72 OIC_LOG(DEBUG, TAG, "SRM sending SRM response");
73 OCEntityHandlerResponse response = {.requestHandle = NULL};
74 OCStackResult ret = OC_STACK_ERROR;
78 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
80 response.requestHandle = ehRequest->requestHandle;
81 response.resourceHandle = ehRequest->resource;
82 response.ehResult = ehRet;
83 response.payload = (OCPayload *)(&ocPayload);
84 response.payload->type = PAYLOAD_TYPE_SECURITY;
85 ((OCSecurityPayload *)response.payload)->securityData1 = cborPayload;
86 ((OCSecurityPayload *)response.payload)->payloadSize = size;
87 response.persistentBufferFlag = 0;
89 ret = OCDoResponse(&response);
94 OCStackResult InitSecureResources( )
99 * doxm resource should be initialized first as it contains the DeviceID
100 * which MAY be used during initialization of other resources.
103 ret = InitDoxmResource();
105 if(OC_STACK_OK == ret)
107 ret = InitPstatResource();
109 if(OC_STACK_OK == ret)
111 ret = InitACLResource();
113 if(OC_STACK_OK == ret)
115 ret = InitCredResource();
118 if(OC_STACK_OK == ret)
120 ret = InitCRLResource();
122 #endif // __WITH_X509__
123 if(OC_STACK_OK == ret)
125 ret = InitSVCResource();
127 if(OC_STACK_OK == ret)
129 ret = InitAmaclResource();
131 //#ifdef DIRECT_PAIRING
132 if(OC_STACK_OK == ret)
134 ret = InitPconfResource();
136 if(OC_STACK_OK == ret)
138 ret = InitDpairingResource();
140 //#endif // DIRECT_PAIRING
141 if(OC_STACK_OK == ret)
143 ret = InitVerResource();
145 if(OC_STACK_OK != ret)
147 //TODO: Update the default behavior if one of the SVR fails
148 DestroySecureResources();
153 OCStackResult DestroySecureResources( )
156 DeInitCredResource();
157 DeInitDoxmResource();
158 DeInitPstatResource();
161 #endif // __WITH_X509__
163 DeInitAmaclResource();
164 //#ifdef DIRECT_PAIRING
165 DeInitPconfResource();
166 DeInitDpairingResource();
167 //#endif // DIRECT_PAIRING