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 "amaclresource.h"
29 #include "oic_malloc.h"
30 #include "oic_string.h"
34 //#ifdef DIRECT_PAIRING
35 #include "pconfresource.h"
36 #include "dpairingresource.h"
37 //#endif // DIRECT_PAIRING
38 #include "verresource.h"
39 #include "psinterface.h"
41 #define TAG "OIC_SRM_RM"
43 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
44 #include "crlresource.h"
45 #endif // __WITH_DTLS__ || __WITH_TLS__
47 OCStackResult SendSRMResponse(const OCEntityHandlerRequest *ehRequest,
48 OCEntityHandlerResult ehRet, uint8_t *cborPayload, size_t size)
50 OIC_LOG(DEBUG, TAG, "SRM sending SRM response");
51 OCStackResult ret = OC_STACK_ERROR;
55 OCEntityHandlerResponse response = {.requestHandle = 0};
56 OCSecurityPayload ocPayload = {.base = {.type = PAYLOAD_TYPE_INVALID}};
58 response.requestHandle = ehRequest->requestHandle;
59 response.resourceHandle = ehRequest->resource;
60 response.ehResult = ehRet;
61 response.payload = (OCPayload *)(&ocPayload);
62 response.payload->type = PAYLOAD_TYPE_SECURITY;
63 ((OCSecurityPayload *)response.payload)->securityData = cborPayload;
64 ((OCSecurityPayload *)response.payload)->payloadSize = size;
65 response.persistentBufferFlag = 0;
67 ret = OCDoResponse(&response);
72 OCStackResult InitSecureResources( )
76 ret = InitPersistentStorageInterface();
79 * doxm resource should be initialized first as it contains the DeviceID
80 * which MAY be used during initialization of other resources.
83 if(OC_STACK_OK == ret)
85 ret = InitDoxmResource();
87 if(OC_STACK_OK == ret)
89 ret = InitPstatResource();
91 if(OC_STACK_OK == ret)
93 ret = InitACLResource();
95 if(OC_STACK_OK == ret)
97 ret = InitCredResource();
99 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
100 if(OC_STACK_OK == ret)
102 ret = InitCRLResource();
104 #endif // __WITH_DTLS__ || __WITH_TLS__
105 if(OC_STACK_OK == ret)
107 ret = InitAmaclResource();
109 //#ifdef DIRECT_PAIRING
110 if(OC_STACK_OK == ret)
112 ret = InitPconfResource();
114 if(OC_STACK_OK == ret)
116 ret = InitDpairingResource();
118 //#endif // DIRECT_PAIRING
119 if(OC_STACK_OK == ret)
121 ret = InitVerResource();
123 if(OC_STACK_OK != ret)
125 //TODO: Update the default behavior if one of the SVR fails
126 DestroySecureResources();
131 OCStackResult DestroySecureResources( )
134 DeInitCredResource();
135 DeInitDoxmResource();
136 DeInitPstatResource();
137 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
139 #endif // __WITH_DTLS__ || __WITH_TLS__
140 DeInitAmaclResource();
141 //#ifdef DIRECT_PAIRING
142 DeInitPconfResource();
143 DeInitDpairingResource();
144 //#endif // DIRECT_PAIRING
146 DeinitPersistentStorageInterface();