mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Embed:
(wiki syntax)
Show/hide line numbers
DeviceManagementResponder.cpp
Go to the documentation of this file.
00001 /** 00002 * @file DeviceManagementResponder.cpp 00003 * @brief mbed CoAP Endpoint Device Management Responder class 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2016 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 // Class support 00024 #include "mbed-connector-interface/DeviceManagementResponder.h" 00025 00026 // Endpoint support 00027 #include "mbed-connector-interface/ConnectorEndpoint.h" 00028 00029 // constructor 00030 DeviceManagementResponder::DeviceManagementResponder(const Logger *logger,const Authenticator *authenticator) { 00031 this->m_logger = (Logger *)logger; 00032 this->m_authenticator = (Authenticator *)authenticator; 00033 this->m_endpoint = NULL; 00034 this->m_reboot_responder_fn = NULL; 00035 this->m_reset_responder_fn = NULL; 00036 this->m_fota_invocation_fn = NULL; 00037 this->m_fota_manifest = NULL; 00038 this->m_firmware_composite_resource = NULL; 00039 } 00040 00041 // copy constructor 00042 DeviceManagementResponder::DeviceManagementResponder(const DeviceManagementResponder &responder) { 00043 this->m_logger = responder.m_logger; 00044 this->m_authenticator = responder.m_authenticator; 00045 this->m_endpoint = responder.m_endpoint; 00046 this->m_reboot_responder_fn = responder.m_reboot_responder_fn; 00047 this->m_reset_responder_fn = responder.m_reset_responder_fn; 00048 this->m_fota_invocation_fn = responder.m_fota_invocation_fn; 00049 this->m_fota_manifest = responder.m_fota_manifest; 00050 this->m_firmware_composite_resource = responder.m_firmware_composite_resource; 00051 } 00052 00053 // destructor 00054 DeviceManagementResponder::~DeviceManagementResponder() { 00055 } 00056 00057 // set the Endpoint 00058 void DeviceManagementResponder::setEndpoint(const void *ep) { 00059 this->m_endpoint = (void *)ep; 00060 } 00061 00062 // authenticate 00063 bool DeviceManagementResponder::authenticate(const void *challenge) { 00064 if (this->m_authenticator != NULL) { 00065 return this->m_authenticator->authenticate((void *)challenge); 00066 } 00067 return false; 00068 } 00069 00070 // set the Reboot Responder handler 00071 void DeviceManagementResponder::setRebootResponderHandler(responder_fn reboot_responder_fn) { 00072 this->m_reboot_responder_fn = reboot_responder_fn; 00073 } 00074 00075 // set the Reset Responder handler 00076 void DeviceManagementResponder::setResetResponderHandler(responder_fn reset_responder_fn) { 00077 this->m_reset_responder_fn = reset_responder_fn; 00078 } 00079 00080 // set the FOTA invocation handler 00081 void DeviceManagementResponder::setFOTAInvocationHandler(responder_fn fota_invocation_fn) { 00082 this->m_fota_invocation_fn = fota_invocation_fn; 00083 } 00084 00085 // set the FOTA manifest 00086 void DeviceManagementResponder::setFOTAManifest(const char *fota_manifest) { 00087 // DEBUG 00088 this->m_logger->log("DeviceManagementResponder(Set FOTA Manifiest): Setting FOTA Manifest: %s",fota_manifest); 00089 00090 // set the FOTA manifest for action later 00091 this->m_fota_manifest = (char *)fota_manifest; 00092 } 00093 00094 // get the FOTA manifest 00095 char *DeviceManagementResponder::getFOTAManifest() { return this->m_fota_manifest; } 00096 00097 // ACTION: deregister device 00098 void DeviceManagementResponder::deregisterDevice(const void *challenge) { 00099 // check endpoint 00100 if (this->m_endpoint != NULL) { 00101 // authenticate 00102 if (this->authenticate(challenge)) { 00103 // DEBUG 00104 this->m_logger->log("DeviceManagementResponder(deregister): de-registering device..."); 00105 00106 // act 00107 ((Connector::Endpoint *)this->m_endpoint)->de_register_endpoint(); 00108 } 00109 else { 00110 // authentication failure 00111 this->m_logger->log("DeviceManagementResponder(deregister): authentication failed. No action taken."); 00112 } 00113 } 00114 else { 00115 // no endpoint 00116 this->m_logger->log("DeviceManagementResponder(deregister): No endpoint instance. No action taken."); 00117 } 00118 } 00119 00120 // ACTION: reboot device 00121 void DeviceManagementResponder::rebootDevice(const void *challenge) { 00122 // check our Reboot Responder handler pointer 00123 if (this->m_reboot_responder_fn != NULL) { 00124 // check endpoint 00125 if (this->m_endpoint != NULL) { 00126 // authenticate 00127 if (this->authenticate(challenge)) { 00128 // act 00129 (*this->m_reboot_responder_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,NULL); 00130 } 00131 else { 00132 // authentication failure 00133 this->m_logger->log("DeviceManagementResponder(reboot): authentication failed. No action taken."); 00134 } 00135 } 00136 else { 00137 // no endpoint 00138 this->m_logger->log("DeviceManagementResponder(reboot): No endpoint instance. No action taken."); 00139 } 00140 } 00141 else { 00142 // no reset responder handler 00143 this->m_logger->log("DeviceManagementResponder(reboot): No reboot responder handler pointer. No action taken."); 00144 } 00145 } 00146 00147 // ACTION: reset device 00148 void DeviceManagementResponder::resetDevice(const void *challenge) { 00149 // check our Reset Responder handler pointer 00150 if (this->m_reset_responder_fn != NULL) { 00151 // check endpoint 00152 if (this->m_endpoint != NULL) { 00153 // authenticate 00154 if (this->authenticate(challenge)) { 00155 // act 00156 (*this->m_reset_responder_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,NULL); 00157 } 00158 else { 00159 // authentication failure 00160 this->m_logger->log("DeviceManagementResponder(reset): authentication failed. No action taken."); 00161 } 00162 } 00163 else { 00164 // no endpoint 00165 this->m_logger->log("DeviceManagementResponder(reset): No endpoint instance. No action taken."); 00166 } 00167 } 00168 else { 00169 // no reset responder handler 00170 this->m_logger->log("DeviceManagementResponder(reset): No reset responder handler pointer. No action taken."); 00171 } 00172 } 00173 00174 // ACTION: invoke FOTA 00175 void DeviceManagementResponder::invokeFOTA(const void *challenge) { 00176 // check our FOTA invocation handler pointer 00177 if (this->m_fota_invocation_fn != NULL) { 00178 // check endpoint 00179 if (this->m_endpoint != NULL) { 00180 // authenticate 00181 if (this->authenticate(challenge)) { 00182 // act 00183 (*this->m_fota_invocation_fn)((const void *)this->m_endpoint,(const void *)this->m_logger,this->m_fota_manifest); 00184 00185 // reset the FOTA manifest 00186 this->m_fota_manifest = NULL; 00187 } 00188 else { 00189 // authentication failure 00190 this->m_logger->log("DeviceManagementResponder(FOTA): authentication failed. No action taken."); 00191 } 00192 } 00193 else { 00194 // no endpoint 00195 this->m_logger->log("DeviceManagementResponder(FOTA): No endpoint instance. No action taken."); 00196 } 00197 } 00198 else { 00199 // no FOTA invocation handler 00200 this->m_logger->log("DeviceManagementResponder(FOTA): No FOTA invocation handler pointer. No action taken."); 00201 } 00202 } 00203 00204 // set the firmware composite resource 00205 void DeviceManagementResponder::setFirmwareCompositeResource(const void *firmware_composite_resource) { 00206 this->m_firmware_composite_resource = (void *)firmware_composite_resource; 00207 } 00208 00209 // get the firmware composie resource 00210 void *DeviceManagementResponder::getFirmwareCompositeResource() { return this->m_firmware_composite_resource; }
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2