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
43 #include "crlresource.h"
44 #endif // __WITH_X509__
46 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
47 OCEntityHandlerResult ehRet, const char *rspPayload)
49 OIC_LOG (DEBUG, TAG, "SRM sending SRM response");
50 OCEntityHandlerResponse response = {.requestHandle = NULL};
53 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
55 response.requestHandle = ehRequest->requestHandle;
56 response.resourceHandle = ehRequest->resource;
57 response.ehResult = ehRet;
58 response.payload = (OCPayload*)(&ocPayload);
59 response.payload->type = PAYLOAD_TYPE_SECURITY;
60 ((OCSecurityPayload*)response.payload)->securityData = (char *)rspPayload;
61 response.persistentBufferFlag = 0;
63 return OCDoResponse(&response);
65 return OC_STACK_ERROR;
68 OCStackResult SendSRMCBORResponse(const OCEntityHandlerRequest *ehRequest,
69 OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size)
71 OIC_LOG(DEBUG, TAG, "SRM sending SRM response");
72 OCEntityHandlerResponse response = {.requestHandle = NULL};
73 OCStackResult ret = OC_STACK_ERROR;
77 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
79 response.requestHandle = ehRequest->requestHandle;
80 response.resourceHandle = ehRequest->resource;
81 response.ehResult = ehRet;
82 response.payload = (OCPayload *)(&ocPayload);
83 response.payload->type = PAYLOAD_TYPE_SECURITY;
84 ((OCSecurityPayload *)response.payload)->securityData1 = cborPayload;
85 ((OCSecurityPayload *)response.payload)->payloadSize = size;
86 response.persistentBufferFlag = 0;
88 ret = OCDoResponse(&response);
93 OCStackResult InitSecureResources( )
98 * doxm resource should be initialized first as it contains the DeviceID
99 * which MAY be used during initialization of other resources.
102 ret = InitDoxmResource();
104 if(OC_STACK_OK == ret)
106 ret = InitPstatResource();
108 if(OC_STACK_OK == ret)
110 ret = InitACLResource();
112 if(OC_STACK_OK == ret)
114 ret = InitCredResource();
117 if(OC_STACK_OK == ret)
119 ret = InitCRLResource();
121 #endif // __WITH_X509__
122 if(OC_STACK_OK == ret)
124 ret = InitSVCResource();
126 if(OC_STACK_OK == ret)
128 ret = InitAmaclResource();
130 //#ifdef DIRECT_PAIRING
131 if(OC_STACK_OK == ret)
133 ret = InitPconfResource();
135 if(OC_STACK_OK == ret)
137 ret = InitDpairingResource();
139 //#endif // DIRECT_PAIRING
140 if(OC_STACK_OK != ret)
142 //TODO: Update the default behavior if one of the SVR fails
143 DestroySecureResources();
148 OCStackResult DestroySecureResources( )
151 DeInitCredResource();
152 DeInitDoxmResource();
153 DeInitPstatResource();
156 #endif // __WITH_X509__
158 DeInitAmaclResource();
159 //#ifdef DIRECT_PAIRING
160 DeInitPconfResource();
161 DeInitDpairingResource();
162 //#endif // DIRECT_PAIRING