A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 /*
ram54288 0:a7a43371b306 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:a7a43371b306 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:a7a43371b306 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:a7a43371b306 5 * not use this file except in compliance with the License.
ram54288 0:a7a43371b306 6 * You may obtain a copy of the License at
ram54288 0:a7a43371b306 7 *
ram54288 0:a7a43371b306 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:a7a43371b306 9 *
ram54288 0:a7a43371b306 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:a7a43371b306 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:a7a43371b306 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:a7a43371b306 13 * See the License for the specific language governing permissions and
ram54288 0:a7a43371b306 14 * limitations under the License.
ram54288 0:a7a43371b306 15 */
ram54288 0:a7a43371b306 16 #include "mbed-client/m2msecurity.h"
ram54288 0:a7a43371b306 17 #include "mbed-client/m2mconstants.h"
ram54288 0:a7a43371b306 18 #include "mbed-client/m2mobject.h"
ram54288 0:a7a43371b306 19 #include "mbed-client/m2mobjectinstance.h"
ram54288 0:a7a43371b306 20 #include "mbed-client/m2mresource.h"
ram54288 0:a7a43371b306 21 #include "mbed-client/m2mstring.h"
ram54288 0:a7a43371b306 22 #include "mbed-trace/mbed_trace.h"
ram54288 0:a7a43371b306 23
ram54288 0:a7a43371b306 24 #include <stdlib.h>
ram54288 0:a7a43371b306 25
ram54288 0:a7a43371b306 26 #define TRACE_GROUP "mClt"
ram54288 0:a7a43371b306 27
ram54288 0:a7a43371b306 28 #define BUFFER_SIZE 21
ram54288 0:a7a43371b306 29
ram54288 0:a7a43371b306 30 M2MSecurity::M2MSecurity(ServerType ser_type)
ram54288 0:a7a43371b306 31 : M2MObject(M2M_SECURITY_ID, stringdup(M2M_SECURITY_ID)),
ram54288 0:a7a43371b306 32 _server_instance(NULL),
ram54288 0:a7a43371b306 33 _server_type(ser_type)
ram54288 0:a7a43371b306 34 {
ram54288 0:a7a43371b306 35 _server_instance = M2MObject::create_object_instance();
ram54288 0:a7a43371b306 36
ram54288 0:a7a43371b306 37 if(_server_instance) {
ram54288 0:a7a43371b306 38 M2MResource* res = _server_instance->create_dynamic_resource(SECURITY_M2M_SERVER_URI,
ram54288 0:a7a43371b306 39 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 40 M2MResourceInstance::STRING,
ram54288 0:a7a43371b306 41 false);
ram54288 0:a7a43371b306 42 if(res) {
ram54288 0:a7a43371b306 43 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 44 }
ram54288 0:a7a43371b306 45 res = _server_instance->create_dynamic_resource(SECURITY_BOOTSTRAP_SERVER,
ram54288 0:a7a43371b306 46 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 47 M2MResourceInstance::BOOLEAN,
ram54288 0:a7a43371b306 48 false);
ram54288 0:a7a43371b306 49 if(res) {
ram54288 0:a7a43371b306 50 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 51 }
ram54288 0:a7a43371b306 52 res = _server_instance->create_dynamic_resource(SECURITY_SECURITY_MODE,
ram54288 0:a7a43371b306 53 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 54 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 55 false);
ram54288 0:a7a43371b306 56 if(res) {
ram54288 0:a7a43371b306 57 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 58 }
ram54288 0:a7a43371b306 59 res = _server_instance->create_dynamic_resource(SECURITY_PUBLIC_KEY,
ram54288 0:a7a43371b306 60 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 61 M2MResourceInstance::OPAQUE,
ram54288 0:a7a43371b306 62 false);
ram54288 0:a7a43371b306 63 if(res) {
ram54288 0:a7a43371b306 64 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 65 }
ram54288 0:a7a43371b306 66 res = _server_instance->create_dynamic_resource(SECURITY_SERVER_PUBLIC_KEY,
ram54288 0:a7a43371b306 67 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 68 M2MResourceInstance::OPAQUE,
ram54288 0:a7a43371b306 69 false);
ram54288 0:a7a43371b306 70 if(res) {
ram54288 0:a7a43371b306 71 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 72 }
ram54288 0:a7a43371b306 73 res = _server_instance->create_dynamic_resource(SECURITY_SECRET_KEY,
ram54288 0:a7a43371b306 74 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 75 M2MResourceInstance::OPAQUE,
ram54288 0:a7a43371b306 76 false);
ram54288 0:a7a43371b306 77 if(res) {
ram54288 0:a7a43371b306 78 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 79 }
ram54288 0:a7a43371b306 80 if(M2MSecurity::M2MServer == ser_type) {
ram54288 0:a7a43371b306 81 res = _server_instance->create_dynamic_resource(SECURITY_SHORT_SERVER_ID,
ram54288 0:a7a43371b306 82 OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 83 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 84 false);
ram54288 0:a7a43371b306 85 if(res) {
ram54288 0:a7a43371b306 86 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 87 }
ram54288 0:a7a43371b306 88 }
ram54288 0:a7a43371b306 89 }
ram54288 0:a7a43371b306 90 }
ram54288 0:a7a43371b306 91
ram54288 0:a7a43371b306 92 M2MSecurity::~M2MSecurity()
ram54288 0:a7a43371b306 93 {
ram54288 0:a7a43371b306 94 }
ram54288 0:a7a43371b306 95
ram54288 0:a7a43371b306 96 M2MResource* M2MSecurity::create_resource(SecurityResource resource, uint32_t value)
ram54288 0:a7a43371b306 97 {
ram54288 0:a7a43371b306 98 M2MResource* res = NULL;
ram54288 0:a7a43371b306 99 const char* security_id_ptr = "";
ram54288 0:a7a43371b306 100 if(!is_resource_present(resource)) {
ram54288 0:a7a43371b306 101 switch(resource) {
ram54288 0:a7a43371b306 102 case SMSSecurityMode:
ram54288 0:a7a43371b306 103 security_id_ptr = SECURITY_SMS_SECURITY_MODE;
ram54288 0:a7a43371b306 104 break;
ram54288 0:a7a43371b306 105 case M2MServerSMSNumber:
ram54288 0:a7a43371b306 106 security_id_ptr = SECURITY_M2M_SERVER_SMS_NUMBER;
ram54288 0:a7a43371b306 107 break;
ram54288 0:a7a43371b306 108 case ShortServerID:
ram54288 0:a7a43371b306 109 security_id_ptr = SECURITY_SHORT_SERVER_ID;
ram54288 0:a7a43371b306 110 break;
ram54288 0:a7a43371b306 111 case ClientHoldOffTime:
ram54288 0:a7a43371b306 112 security_id_ptr = SECURITY_CLIENT_HOLD_OFF_TIME;
ram54288 0:a7a43371b306 113 break;
ram54288 0:a7a43371b306 114 default:
ram54288 0:a7a43371b306 115 break;
ram54288 0:a7a43371b306 116 }
ram54288 0:a7a43371b306 117 }
ram54288 0:a7a43371b306 118
ram54288 0:a7a43371b306 119 const String security_id(security_id_ptr);
ram54288 0:a7a43371b306 120
ram54288 0:a7a43371b306 121 if(!security_id.empty()) {
ram54288 0:a7a43371b306 122 if(_server_instance) {
ram54288 0:a7a43371b306 123 res = _server_instance->create_dynamic_resource(security_id,OMA_RESOURCE_TYPE,
ram54288 0:a7a43371b306 124 M2MResourceInstance::INTEGER,
ram54288 0:a7a43371b306 125 false);
ram54288 0:a7a43371b306 126
ram54288 0:a7a43371b306 127 if(res) {
ram54288 0:a7a43371b306 128 res->set_operation(M2MBase::NOT_ALLOWED);
ram54288 0:a7a43371b306 129 res->set_value(value);
ram54288 0:a7a43371b306 130 }
ram54288 0:a7a43371b306 131 }
ram54288 0:a7a43371b306 132 }
ram54288 0:a7a43371b306 133 return res;
ram54288 0:a7a43371b306 134 }
ram54288 0:a7a43371b306 135
ram54288 0:a7a43371b306 136 bool M2MSecurity::delete_resource(SecurityResource resource)
ram54288 0:a7a43371b306 137 {
ram54288 0:a7a43371b306 138 bool success = false;
ram54288 0:a7a43371b306 139 const char* security_id_ptr;
ram54288 0:a7a43371b306 140 switch(resource) {
ram54288 0:a7a43371b306 141 case SMSSecurityMode:
ram54288 0:a7a43371b306 142 security_id_ptr = SECURITY_SMS_SECURITY_MODE;
ram54288 0:a7a43371b306 143 break;
ram54288 0:a7a43371b306 144 case M2MServerSMSNumber:
ram54288 0:a7a43371b306 145 security_id_ptr = SECURITY_M2M_SERVER_SMS_NUMBER;
ram54288 0:a7a43371b306 146 break;
ram54288 0:a7a43371b306 147 case ShortServerID:
ram54288 0:a7a43371b306 148 if(M2MSecurity::Bootstrap == _server_type) {
ram54288 0:a7a43371b306 149 security_id_ptr = SECURITY_SHORT_SERVER_ID;
ram54288 0:a7a43371b306 150 }
ram54288 0:a7a43371b306 151 break;
ram54288 0:a7a43371b306 152 case ClientHoldOffTime:
ram54288 0:a7a43371b306 153 security_id_ptr = SECURITY_CLIENT_HOLD_OFF_TIME;
ram54288 0:a7a43371b306 154 break;
ram54288 0:a7a43371b306 155 default:
ram54288 0:a7a43371b306 156 // Others are mandatory resources hence cannot be deleted.
ram54288 0:a7a43371b306 157 security_id_ptr = NULL;
ram54288 0:a7a43371b306 158 break;
ram54288 0:a7a43371b306 159 }
ram54288 0:a7a43371b306 160
ram54288 0:a7a43371b306 161 if(security_id_ptr) {
ram54288 0:a7a43371b306 162 if(_server_instance) {
ram54288 0:a7a43371b306 163 success = _server_instance->remove_resource(security_id_ptr);
ram54288 0:a7a43371b306 164 }
ram54288 0:a7a43371b306 165 }
ram54288 0:a7a43371b306 166 return success;
ram54288 0:a7a43371b306 167 }
ram54288 0:a7a43371b306 168
ram54288 0:a7a43371b306 169 bool M2MSecurity::set_resource_value(SecurityResource resource,
ram54288 0:a7a43371b306 170 const String &value)
ram54288 0:a7a43371b306 171 {
ram54288 0:a7a43371b306 172 bool success = false;
ram54288 0:a7a43371b306 173 if(M2MSecurity::M2MServerUri == resource) {
ram54288 0:a7a43371b306 174 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 175 if(res) {
ram54288 0:a7a43371b306 176 success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length());
ram54288 0:a7a43371b306 177 }
ram54288 0:a7a43371b306 178 }
ram54288 0:a7a43371b306 179 return success;
ram54288 0:a7a43371b306 180 }
ram54288 0:a7a43371b306 181
ram54288 0:a7a43371b306 182 bool M2MSecurity::set_resource_value(SecurityResource resource,
ram54288 0:a7a43371b306 183 uint32_t value)
ram54288 0:a7a43371b306 184 {
ram54288 0:a7a43371b306 185 bool success = false;
ram54288 0:a7a43371b306 186 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 187 if(res) {
ram54288 0:a7a43371b306 188 if(M2MSecurity::SecurityMode == resource ||
ram54288 0:a7a43371b306 189 M2MSecurity::SMSSecurityMode == resource ||
ram54288 0:a7a43371b306 190 M2MSecurity::M2MServerSMSNumber == resource ||
ram54288 0:a7a43371b306 191 M2MSecurity::ShortServerID == resource ||
ram54288 0:a7a43371b306 192 M2MSecurity::ClientHoldOffTime == resource) {
ram54288 0:a7a43371b306 193 // If it is any of the above resource
ram54288 0:a7a43371b306 194 // set the value of the resource.
ram54288 0:a7a43371b306 195 uint8_t size = 0;
ram54288 0:a7a43371b306 196 uint8_t *buffer = String::convert_integer_to_array(value, size);
ram54288 0:a7a43371b306 197 success = res->set_value(buffer,size);
ram54288 0:a7a43371b306 198 free(buffer);
ram54288 0:a7a43371b306 199 }
ram54288 0:a7a43371b306 200 }
ram54288 0:a7a43371b306 201 return success;
ram54288 0:a7a43371b306 202 }
ram54288 0:a7a43371b306 203
ram54288 0:a7a43371b306 204 bool M2MSecurity::set_resource_value(SecurityResource resource,
ram54288 0:a7a43371b306 205 const uint8_t *value,
ram54288 0:a7a43371b306 206 const uint16_t length)
ram54288 0:a7a43371b306 207 {
ram54288 0:a7a43371b306 208 bool success = false;
ram54288 0:a7a43371b306 209 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 210 if(res) {
ram54288 0:a7a43371b306 211 if(M2MSecurity::PublicKey == resource ||
ram54288 0:a7a43371b306 212 M2MSecurity::ServerPublicKey == resource ||
ram54288 0:a7a43371b306 213 M2MSecurity::Secretkey == resource) {
ram54288 0:a7a43371b306 214 success = res->set_value(value,length);
ram54288 0:a7a43371b306 215 }
ram54288 0:a7a43371b306 216 }
ram54288 0:a7a43371b306 217 return success;
ram54288 0:a7a43371b306 218 }
ram54288 0:a7a43371b306 219
ram54288 0:a7a43371b306 220 String M2MSecurity::resource_value_string(SecurityResource resource) const
ram54288 0:a7a43371b306 221 {
ram54288 0:a7a43371b306 222 String value = "";
ram54288 0:a7a43371b306 223 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 224 if(res) {
ram54288 0:a7a43371b306 225 if(M2MSecurity::M2MServerUri == resource) {
ram54288 0:a7a43371b306 226 value = res->get_value_string();
ram54288 0:a7a43371b306 227 }
ram54288 0:a7a43371b306 228 }
ram54288 0:a7a43371b306 229 return value;
ram54288 0:a7a43371b306 230 }
ram54288 0:a7a43371b306 231
ram54288 0:a7a43371b306 232 uint32_t M2MSecurity::resource_value_buffer(SecurityResource resource,
ram54288 0:a7a43371b306 233 uint8_t *&data) const
ram54288 0:a7a43371b306 234 {
ram54288 0:a7a43371b306 235 uint32_t size = 0;
ram54288 0:a7a43371b306 236 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 237 if(res) {
ram54288 0:a7a43371b306 238 if(M2MSecurity::PublicKey == resource ||
ram54288 0:a7a43371b306 239 M2MSecurity::ServerPublicKey == resource ||
ram54288 0:a7a43371b306 240 M2MSecurity::Secretkey == resource) {
ram54288 0:a7a43371b306 241 res->get_value(data,size);
ram54288 0:a7a43371b306 242 }
ram54288 0:a7a43371b306 243 }
ram54288 0:a7a43371b306 244 return size;
ram54288 0:a7a43371b306 245 }
ram54288 0:a7a43371b306 246
ram54288 0:a7a43371b306 247 uint32_t M2MSecurity::resource_value_buffer(SecurityResource resource,
ram54288 0:a7a43371b306 248 const uint8_t *&data) const
ram54288 0:a7a43371b306 249 {
ram54288 0:a7a43371b306 250 uint32_t size = 0;
ram54288 0:a7a43371b306 251 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 252 if(res) {
ram54288 0:a7a43371b306 253 if(M2MSecurity::PublicKey == resource ||
ram54288 0:a7a43371b306 254 M2MSecurity::ServerPublicKey == resource ||
ram54288 0:a7a43371b306 255 M2MSecurity::Secretkey == resource) {
ram54288 0:a7a43371b306 256 data = res->value();
ram54288 0:a7a43371b306 257 size = res->value_length();
ram54288 0:a7a43371b306 258 }
ram54288 0:a7a43371b306 259 }
ram54288 0:a7a43371b306 260 return size;
ram54288 0:a7a43371b306 261 }
ram54288 0:a7a43371b306 262
ram54288 0:a7a43371b306 263
ram54288 0:a7a43371b306 264 uint32_t M2MSecurity::resource_value_int(SecurityResource resource) const
ram54288 0:a7a43371b306 265 {
ram54288 0:a7a43371b306 266 uint32_t value = 0;
ram54288 0:a7a43371b306 267 M2MResource* res = get_resource(resource);
ram54288 0:a7a43371b306 268 if(res) {
ram54288 0:a7a43371b306 269 if(M2MSecurity::SecurityMode == resource ||
ram54288 0:a7a43371b306 270 M2MSecurity::SMSSecurityMode == resource ||
ram54288 0:a7a43371b306 271 M2MSecurity::M2MServerSMSNumber == resource ||
ram54288 0:a7a43371b306 272 M2MSecurity::ShortServerID == resource ||
ram54288 0:a7a43371b306 273 M2MSecurity::ClientHoldOffTime == resource) {
ram54288 0:a7a43371b306 274 // Get the value and convert it into integer. This is not the most
ram54288 0:a7a43371b306 275 // efficient way, as it takes pointless heap copy to get the zero termination.
ram54288 0:a7a43371b306 276 uint8_t* buffer = NULL;
ram54288 0:a7a43371b306 277 uint32_t length = 0;
ram54288 0:a7a43371b306 278 res->get_value(buffer,length);
ram54288 0:a7a43371b306 279 if(buffer) {
ram54288 0:a7a43371b306 280 value = String::convert_array_to_integer(buffer,length);
ram54288 0:a7a43371b306 281 free(buffer);
ram54288 0:a7a43371b306 282 }
ram54288 0:a7a43371b306 283 }
ram54288 0:a7a43371b306 284 }
ram54288 0:a7a43371b306 285 return value;
ram54288 0:a7a43371b306 286 }
ram54288 0:a7a43371b306 287
ram54288 0:a7a43371b306 288 bool M2MSecurity::is_resource_present(SecurityResource resource) const
ram54288 0:a7a43371b306 289 {
ram54288 0:a7a43371b306 290 bool success = false;
ram54288 0:a7a43371b306 291 M2MResource *res = get_resource(resource);
ram54288 0:a7a43371b306 292 if(res) {
ram54288 0:a7a43371b306 293 success = true;
ram54288 0:a7a43371b306 294 }
ram54288 0:a7a43371b306 295 return success;
ram54288 0:a7a43371b306 296 }
ram54288 0:a7a43371b306 297
ram54288 0:a7a43371b306 298 uint16_t M2MSecurity::total_resource_count() const
ram54288 0:a7a43371b306 299 {
ram54288 0:a7a43371b306 300 uint16_t count = 0;
ram54288 0:a7a43371b306 301 if(_server_instance) {
ram54288 0:a7a43371b306 302 count = _server_instance->resources().size();
ram54288 0:a7a43371b306 303 }
ram54288 0:a7a43371b306 304 return count;
ram54288 0:a7a43371b306 305 }
ram54288 0:a7a43371b306 306
ram54288 0:a7a43371b306 307 M2MSecurity::ServerType M2MSecurity::server_type() const
ram54288 0:a7a43371b306 308 {
ram54288 0:a7a43371b306 309 return _server_type;
ram54288 0:a7a43371b306 310 }
ram54288 0:a7a43371b306 311
ram54288 0:a7a43371b306 312 M2MResource* M2MSecurity::get_resource(SecurityResource res) const
ram54288 0:a7a43371b306 313 {
ram54288 0:a7a43371b306 314 M2MResource* res_object = NULL;
ram54288 0:a7a43371b306 315 if(_server_instance) {
ram54288 0:a7a43371b306 316 const char* res_name_ptr = NULL;
ram54288 0:a7a43371b306 317 switch(res) {
ram54288 0:a7a43371b306 318 case M2MServerUri:
ram54288 0:a7a43371b306 319 res_name_ptr = SECURITY_M2M_SERVER_URI;
ram54288 0:a7a43371b306 320 break;
ram54288 0:a7a43371b306 321 case BootstrapServer:
ram54288 0:a7a43371b306 322 res_name_ptr = SECURITY_BOOTSTRAP_SERVER;
ram54288 0:a7a43371b306 323 break;
ram54288 0:a7a43371b306 324 case SecurityMode:
ram54288 0:a7a43371b306 325 res_name_ptr = SECURITY_SECURITY_MODE;
ram54288 0:a7a43371b306 326 break;
ram54288 0:a7a43371b306 327 case PublicKey:
ram54288 0:a7a43371b306 328 res_name_ptr = SECURITY_PUBLIC_KEY;
ram54288 0:a7a43371b306 329 break;
ram54288 0:a7a43371b306 330 case ServerPublicKey:
ram54288 0:a7a43371b306 331 res_name_ptr = SECURITY_SERVER_PUBLIC_KEY;
ram54288 0:a7a43371b306 332 break;
ram54288 0:a7a43371b306 333 case Secretkey:
ram54288 0:a7a43371b306 334 res_name_ptr = SECURITY_SECRET_KEY;
ram54288 0:a7a43371b306 335 break;
ram54288 0:a7a43371b306 336 case SMSSecurityMode:
ram54288 0:a7a43371b306 337 res_name_ptr = SECURITY_SMS_SECURITY_MODE;
ram54288 0:a7a43371b306 338 break;
ram54288 0:a7a43371b306 339 case SMSBindingKey:
ram54288 0:a7a43371b306 340 res_name_ptr = SECURITY_SMS_BINDING_KEY;
ram54288 0:a7a43371b306 341 break;
ram54288 0:a7a43371b306 342 case SMSBindingSecretKey:
ram54288 0:a7a43371b306 343 res_name_ptr = SECURITY_SMS_BINDING_SECRET_KEY;
ram54288 0:a7a43371b306 344 break;
ram54288 0:a7a43371b306 345 case M2MServerSMSNumber:
ram54288 0:a7a43371b306 346 res_name_ptr = SECURITY_M2M_SERVER_SMS_NUMBER;
ram54288 0:a7a43371b306 347 break;
ram54288 0:a7a43371b306 348 case ShortServerID:
ram54288 0:a7a43371b306 349 res_name_ptr = SECURITY_SHORT_SERVER_ID;
ram54288 0:a7a43371b306 350 break;
ram54288 0:a7a43371b306 351 case ClientHoldOffTime:
ram54288 0:a7a43371b306 352 res_name_ptr = SECURITY_CLIENT_HOLD_OFF_TIME;
ram54288 0:a7a43371b306 353 break;
ram54288 0:a7a43371b306 354 }
ram54288 0:a7a43371b306 355
ram54288 0:a7a43371b306 356 if (res_name_ptr) {
ram54288 0:a7a43371b306 357 res_object = _server_instance->resource(res_name_ptr);
ram54288 0:a7a43371b306 358 }
ram54288 0:a7a43371b306 359 }
ram54288 0:a7a43371b306 360 return res_object;
ram54288 0:a7a43371b306 361 }
ram54288 0:a7a43371b306 362
ram54288 0:a7a43371b306 363 void M2MSecurity::clear_resources()
ram54288 0:a7a43371b306 364 {
ram54288 0:a7a43371b306 365 for(int i = 0; i <= M2MSecurity::ClientHoldOffTime; i++) {
ram54288 0:a7a43371b306 366 M2MResource *res = get_resource((SecurityResource) i);
ram54288 0:a7a43371b306 367 if (res) {
ram54288 0:a7a43371b306 368 res->clear_value();
ram54288 0:a7a43371b306 369 }
ram54288 0:a7a43371b306 370 }
ram54288 0:a7a43371b306 371 }