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)
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 response.persistentBufferFlag = 0;
87 ret = OCDoResponse(&response);
92 OCStackResult InitSecureResources( )
97 * doxm resource should be initialized first as it contains the DeviceID
98 * which MAY be used during initialization of other resources.
101 ret = InitDoxmResource();
103 if(OC_STACK_OK == ret)
105 ret = InitPstatResource();
107 if(OC_STACK_OK == ret)
109 ret = InitACLResource();
111 if(OC_STACK_OK == ret)
113 ret = InitCredResource();
116 if(OC_STACK_OK == ret)
118 ret = InitCRLResource();
120 #endif // __WITH_X509__
121 if(OC_STACK_OK == ret)
123 ret = InitSVCResource();
125 if(OC_STACK_OK == ret)
127 ret = InitAmaclResource();
129 //#ifdef DIRECT_PAIRING
130 if(OC_STACK_OK == ret)
132 ret = InitPconfResource();
134 if(OC_STACK_OK == ret)
136 ret = InitDpairingResource();
138 //#endif // DIRECT_PAIRING
139 if(OC_STACK_OK != ret)
141 //TODO: Update the default behavior if one of the SVR fails
142 DestroySecureResources();
147 OCStackResult DestroySecureResources( )
150 DeInitCredResource();
151 DeInitDoxmResource();
152 DeInitPstatResource();
155 #endif // __WITH_X509__
157 DeInitAmaclResource();
158 //#ifdef DIRECT_PAIRING
159 DeInitPconfResource();
160 DeInitDpairingResource();
161 //#endif // DIRECT_PAIRING