Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/source/include/ConnectorClient.h@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 2 | // Copyright 2016-2017 ARM Ltd. |
leothedragon | 0:8f0bb79ddd48 | 3 | // |
leothedragon | 0:8f0bb79ddd48 | 4 | // SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 5 | // |
leothedragon | 0:8f0bb79ddd48 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
leothedragon | 0:8f0bb79ddd48 | 7 | // you may not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 8 | // You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 9 | // |
leothedragon | 0:8f0bb79ddd48 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 11 | // |
leothedragon | 0:8f0bb79ddd48 | 12 | // Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
leothedragon | 0:8f0bb79ddd48 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 15 | // See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 16 | // limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 17 | // ---------------------------------------------------------------------------- |
leothedragon | 0:8f0bb79ddd48 | 18 | |
leothedragon | 0:8f0bb79ddd48 | 19 | #ifndef __CONNECTOR_CLIENT_H__ |
leothedragon | 0:8f0bb79ddd48 | 20 | #define __CONNECTOR_CLIENT_H__ |
leothedragon | 0:8f0bb79ddd48 | 21 | |
leothedragon | 0:8f0bb79ddd48 | 22 | #include "mbed-client/functionpointer.h" |
leothedragon | 0:8f0bb79ddd48 | 23 | #include "mbed-client/m2minterfacefactory.h" |
leothedragon | 0:8f0bb79ddd48 | 24 | #include "mbed-client/m2mdevice.h" |
leothedragon | 0:8f0bb79ddd48 | 25 | #include "mbed-client/m2minterfaceobserver.h" |
leothedragon | 0:8f0bb79ddd48 | 26 | #include "mbed-client/m2minterface.h" |
leothedragon | 0:8f0bb79ddd48 | 27 | #include "mbed-client/m2mobjectinstance.h" |
leothedragon | 0:8f0bb79ddd48 | 28 | #include "mbed-client/m2mresource.h" |
leothedragon | 0:8f0bb79ddd48 | 29 | #include "mbed-client/m2mtimerobserver.h" |
leothedragon | 0:8f0bb79ddd48 | 30 | #include "mbed-client/m2mtimer.h" |
leothedragon | 0:8f0bb79ddd48 | 31 | #include "include/CloudClientStorage.h" |
leothedragon | 0:8f0bb79ddd48 | 32 | |
leothedragon | 0:8f0bb79ddd48 | 33 | #ifndef MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 34 | #include "include/EstClient.h" |
leothedragon | 0:8f0bb79ddd48 | 35 | #endif // !MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 36 | |
leothedragon | 0:8f0bb79ddd48 | 37 | class ConnectorClientCallback; |
leothedragon | 0:8f0bb79ddd48 | 38 | |
leothedragon | 0:8f0bb79ddd48 | 39 | #if MBED_CLOUD_CLIENT_STD_NAMESPACE_POLLUTION |
leothedragon | 0:8f0bb79ddd48 | 40 | // We should not really pollute application's namespace with std by having this in |
leothedragon | 0:8f0bb79ddd48 | 41 | // a public header file. |
leothedragon | 0:8f0bb79ddd48 | 42 | // But as as removal of the next line may break existing applications, which build due to this |
leothedragon | 0:8f0bb79ddd48 | 43 | // leakage, we need to maintain the old behavior for a while and just allow one to remove it. |
leothedragon | 0:8f0bb79ddd48 | 44 | using namespace std; |
leothedragon | 0:8f0bb79ddd48 | 45 | #endif |
leothedragon | 0:8f0bb79ddd48 | 46 | |
leothedragon | 0:8f0bb79ddd48 | 47 | |
leothedragon | 0:8f0bb79ddd48 | 48 | /** |
leothedragon | 0:8f0bb79ddd48 | 49 | * \brief ConnectorClientEndpointInfo |
leothedragon | 0:8f0bb79ddd48 | 50 | * A structure that contains the needed endpoint information to register with the Cloud service. |
leothedragon | 0:8f0bb79ddd48 | 51 | * Note: this should be changed to a class instead of struct and/or members changed to "const char*". |
leothedragon | 0:8f0bb79ddd48 | 52 | */ |
leothedragon | 0:8f0bb79ddd48 | 53 | struct ConnectorClientEndpointInfo { |
leothedragon | 0:8f0bb79ddd48 | 54 | |
leothedragon | 0:8f0bb79ddd48 | 55 | public: |
leothedragon | 0:8f0bb79ddd48 | 56 | ConnectorClientEndpointInfo(M2MSecurity::SecurityModeType m) : mode(m) {}; |
leothedragon | 0:8f0bb79ddd48 | 57 | ~ConnectorClientEndpointInfo() {}; |
leothedragon | 0:8f0bb79ddd48 | 58 | |
leothedragon | 0:8f0bb79ddd48 | 59 | public: |
leothedragon | 0:8f0bb79ddd48 | 60 | |
leothedragon | 0:8f0bb79ddd48 | 61 | String endpoint_name; |
leothedragon | 0:8f0bb79ddd48 | 62 | String account_id; |
leothedragon | 0:8f0bb79ddd48 | 63 | String internal_endpoint_name; |
leothedragon | 0:8f0bb79ddd48 | 64 | M2MSecurity::SecurityModeType mode; |
leothedragon | 0:8f0bb79ddd48 | 65 | #ifdef MBED_CLOUD_CLIENT_EDGE_EXTENSION |
leothedragon | 0:8f0bb79ddd48 | 66 | String lwm2m_server_uri; |
leothedragon | 0:8f0bb79ddd48 | 67 | #endif |
leothedragon | 0:8f0bb79ddd48 | 68 | }; |
leothedragon | 0:8f0bb79ddd48 | 69 | |
leothedragon | 0:8f0bb79ddd48 | 70 | /** |
leothedragon | 0:8f0bb79ddd48 | 71 | * \brief ConnectorClient |
leothedragon | 0:8f0bb79ddd48 | 72 | * This class is an interface towards the M2MInterface client to handle all |
leothedragon | 0:8f0bb79ddd48 | 73 | * data flow towards Connector through this client. |
leothedragon | 0:8f0bb79ddd48 | 74 | * This class is intended to be used via ServiceClient, not directly. |
leothedragon | 0:8f0bb79ddd48 | 75 | * This class contains also the bootstrap functionality. |
leothedragon | 0:8f0bb79ddd48 | 76 | */ |
leothedragon | 0:8f0bb79ddd48 | 77 | class ConnectorClient : public M2MInterfaceObserver, public M2MTimerObserver { |
leothedragon | 0:8f0bb79ddd48 | 78 | |
leothedragon | 0:8f0bb79ddd48 | 79 | public: |
leothedragon | 0:8f0bb79ddd48 | 80 | /** |
leothedragon | 0:8f0bb79ddd48 | 81 | * \brief An enum defining the different states of |
leothedragon | 0:8f0bb79ddd48 | 82 | * ConnectorClient during the client flow. |
leothedragon | 0:8f0bb79ddd48 | 83 | */ |
leothedragon | 0:8f0bb79ddd48 | 84 | enum StartupSubStateRegistration { |
leothedragon | 0:8f0bb79ddd48 | 85 | State_Bootstrap_Start, |
leothedragon | 0:8f0bb79ddd48 | 86 | State_Bootstrap_Started, |
leothedragon | 0:8f0bb79ddd48 | 87 | State_Bootstrap_Success, |
leothedragon | 0:8f0bb79ddd48 | 88 | State_Bootstrap_Failure, |
leothedragon | 0:8f0bb79ddd48 | 89 | #ifndef MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 90 | State_EST_Start, |
leothedragon | 0:8f0bb79ddd48 | 91 | State_EST_Started, |
leothedragon | 0:8f0bb79ddd48 | 92 | State_EST_Success, |
leothedragon | 0:8f0bb79ddd48 | 93 | State_EST_Failure, |
leothedragon | 0:8f0bb79ddd48 | 94 | #endif // !MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 95 | State_Registration_Start, |
leothedragon | 0:8f0bb79ddd48 | 96 | State_Registration_Started, |
leothedragon | 0:8f0bb79ddd48 | 97 | State_Registration_Success, |
leothedragon | 0:8f0bb79ddd48 | 98 | State_Registration_Failure, |
leothedragon | 0:8f0bb79ddd48 | 99 | State_Registration_Updated, |
leothedragon | 0:8f0bb79ddd48 | 100 | State_Unregistered |
leothedragon | 0:8f0bb79ddd48 | 101 | }; |
leothedragon | 0:8f0bb79ddd48 | 102 | |
leothedragon | 0:8f0bb79ddd48 | 103 | public: |
leothedragon | 0:8f0bb79ddd48 | 104 | |
leothedragon | 0:8f0bb79ddd48 | 105 | /** |
leothedragon | 0:8f0bb79ddd48 | 106 | * \brief Constructor. |
leothedragon | 0:8f0bb79ddd48 | 107 | * \param callback, A callback for the status from ConnectorClient. |
leothedragon | 0:8f0bb79ddd48 | 108 | */ |
leothedragon | 0:8f0bb79ddd48 | 109 | ConnectorClient(ConnectorClientCallback* callback); |
leothedragon | 0:8f0bb79ddd48 | 110 | |
leothedragon | 0:8f0bb79ddd48 | 111 | /** |
leothedragon | 0:8f0bb79ddd48 | 112 | * \brief Destructor. |
leothedragon | 0:8f0bb79ddd48 | 113 | */ |
leothedragon | 0:8f0bb79ddd48 | 114 | ~ConnectorClient(); |
leothedragon | 0:8f0bb79ddd48 | 115 | |
leothedragon | 0:8f0bb79ddd48 | 116 | /** |
leothedragon | 0:8f0bb79ddd48 | 117 | * \brief Perform the second phase set up which is not possible from constructor. |
leothedragon | 0:8f0bb79ddd48 | 118 | * This must be called successfully after constructor and before |
leothedragon | 0:8f0bb79ddd48 | 119 | * continuing to state machine. |
leothedragon | 0:8f0bb79ddd48 | 120 | * \return true, if success and instance is ready to use |
leothedragon | 0:8f0bb79ddd48 | 121 | */ |
leothedragon | 0:8f0bb79ddd48 | 122 | bool setup(); |
leothedragon | 0:8f0bb79ddd48 | 123 | |
leothedragon | 0:8f0bb79ddd48 | 124 | /** |
leothedragon | 0:8f0bb79ddd48 | 125 | * \brief Starts the bootstrap sequence from the Service Client. |
leothedragon | 0:8f0bb79ddd48 | 126 | */ |
leothedragon | 0:8f0bb79ddd48 | 127 | void start_bootstrap(); |
leothedragon | 0:8f0bb79ddd48 | 128 | |
leothedragon | 0:8f0bb79ddd48 | 129 | /** |
leothedragon | 0:8f0bb79ddd48 | 130 | * \brief Starts the registration sequence from the Service Client. |
leothedragon | 0:8f0bb79ddd48 | 131 | * \param client_objs, A list of objects implementing the M2MBase interface to be registered with Cloud. |
leothedragon | 0:8f0bb79ddd48 | 132 | */ |
leothedragon | 0:8f0bb79ddd48 | 133 | void start_registration(M2MBaseList* client_objs); |
leothedragon | 0:8f0bb79ddd48 | 134 | |
leothedragon | 0:8f0bb79ddd48 | 135 | /** |
leothedragon | 0:8f0bb79ddd48 | 136 | * \brief Sends an update registration message to the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 137 | */ |
leothedragon | 0:8f0bb79ddd48 | 138 | void update_registration(); |
leothedragon | 0:8f0bb79ddd48 | 139 | |
leothedragon | 0:8f0bb79ddd48 | 140 | /** |
leothedragon | 0:8f0bb79ddd48 | 141 | * \brief Returns the M2MInterface handler. |
leothedragon | 0:8f0bb79ddd48 | 142 | * \return M2MInterface, Handled for M2MInterface. |
leothedragon | 0:8f0bb79ddd48 | 143 | */ |
leothedragon | 0:8f0bb79ddd48 | 144 | M2MInterface * m2m_interface(); |
leothedragon | 0:8f0bb79ddd48 | 145 | |
leothedragon | 0:8f0bb79ddd48 | 146 | /** |
leothedragon | 0:8f0bb79ddd48 | 147 | * \brief Checks whether to use Bootstrap or direct Connector mode. |
leothedragon | 0:8f0bb79ddd48 | 148 | * \return True if bootstrap mode, False if direct Connector flow |
leothedragon | 0:8f0bb79ddd48 | 149 | */ |
leothedragon | 0:8f0bb79ddd48 | 150 | bool use_bootstrap(); |
leothedragon | 0:8f0bb79ddd48 | 151 | |
leothedragon | 0:8f0bb79ddd48 | 152 | /** |
leothedragon | 0:8f0bb79ddd48 | 153 | * \brief Checks whether to go connector registration flow |
leothedragon | 0:8f0bb79ddd48 | 154 | * \return True if connector credentials available otherwise false. |
leothedragon | 0:8f0bb79ddd48 | 155 | */ |
leothedragon | 0:8f0bb79ddd48 | 156 | bool connector_credentials_available(); |
leothedragon | 0:8f0bb79ddd48 | 157 | |
leothedragon | 0:8f0bb79ddd48 | 158 | /** |
leothedragon | 0:8f0bb79ddd48 | 159 | * \brief A utility function to generate the key name. |
leothedragon | 0:8f0bb79ddd48 | 160 | * \param key, The key to get the value for. |
leothedragon | 0:8f0bb79ddd48 | 161 | * \param endpoint, The name of the endpoint to be appended |
leothedragon | 0:8f0bb79ddd48 | 162 | * to the key. |
leothedragon | 0:8f0bb79ddd48 | 163 | * \param key_name, The [OUT] final key name. |
leothedragon | 0:8f0bb79ddd48 | 164 | * \return True if available, else false. |
leothedragon | 0:8f0bb79ddd48 | 165 | */ |
leothedragon | 0:8f0bb79ddd48 | 166 | bool get_key(const char *key, const char *endpoint, char *&key_name); |
leothedragon | 0:8f0bb79ddd48 | 167 | |
leothedragon | 0:8f0bb79ddd48 | 168 | /** |
leothedragon | 0:8f0bb79ddd48 | 169 | * \brief Returns pointer to the ConnectorClientEndpointInfo object. |
leothedragon | 0:8f0bb79ddd48 | 170 | * \return ConnectorClientEndpointInfo pointer. |
leothedragon | 0:8f0bb79ddd48 | 171 | */ |
leothedragon | 0:8f0bb79ddd48 | 172 | const ConnectorClientEndpointInfo *endpoint_info() const; |
leothedragon | 0:8f0bb79ddd48 | 173 | |
leothedragon | 0:8f0bb79ddd48 | 174 | /** |
leothedragon | 0:8f0bb79ddd48 | 175 | * \brief Returns KCM Certificate chain handle pointer. |
leothedragon | 0:8f0bb79ddd48 | 176 | * \return KCM Certificate chain handle pointer. |
leothedragon | 0:8f0bb79ddd48 | 177 | */ |
leothedragon | 0:8f0bb79ddd48 | 178 | void *certificate_chain_handle() const; |
leothedragon | 0:8f0bb79ddd48 | 179 | |
leothedragon | 0:8f0bb79ddd48 | 180 | /** |
leothedragon | 0:8f0bb79ddd48 | 181 | * \brief Sets the KCM certificate chain handle pointer. |
leothedragon | 0:8f0bb79ddd48 | 182 | * \param cert_handle KCM Certificate chain handle. |
leothedragon | 0:8f0bb79ddd48 | 183 | */ |
leothedragon | 0:8f0bb79ddd48 | 184 | void set_certificate_chain_handle(void *cert_handle); |
leothedragon | 0:8f0bb79ddd48 | 185 | |
leothedragon | 0:8f0bb79ddd48 | 186 | #ifndef MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 187 | static void est_enrollment_result(est_enrollment_result_e result, |
leothedragon | 0:8f0bb79ddd48 | 188 | cert_chain_context_s *cert_chain, |
leothedragon | 0:8f0bb79ddd48 | 189 | void *context); |
leothedragon | 0:8f0bb79ddd48 | 190 | |
leothedragon | 0:8f0bb79ddd48 | 191 | /** |
leothedragon | 0:8f0bb79ddd48 | 192 | * \brief Get reference to the EST client instance. |
leothedragon | 0:8f0bb79ddd48 | 193 | */ |
leothedragon | 0:8f0bb79ddd48 | 194 | const EstClient &est_client(); |
leothedragon | 0:8f0bb79ddd48 | 195 | #endif /* MBED_CLIENT_DISABLE_EST_FEATURE */ |
leothedragon | 0:8f0bb79ddd48 | 196 | |
leothedragon | 0:8f0bb79ddd48 | 197 | /** |
leothedragon | 0:8f0bb79ddd48 | 198 | * \brief Starts bootstrap sequence again. |
leothedragon | 0:8f0bb79ddd48 | 199 | * This will clean the old LwM2M credentials. |
leothedragon | 0:8f0bb79ddd48 | 200 | * |
leothedragon | 0:8f0bb79ddd48 | 201 | */ |
leothedragon | 0:8f0bb79ddd48 | 202 | void bootstrap_again(); |
leothedragon | 0:8f0bb79ddd48 | 203 | |
leothedragon | 0:8f0bb79ddd48 | 204 | public: |
leothedragon | 0:8f0bb79ddd48 | 205 | // implementation of M2MInterfaceObserver: |
leothedragon | 0:8f0bb79ddd48 | 206 | |
leothedragon | 0:8f0bb79ddd48 | 207 | /** |
leothedragon | 0:8f0bb79ddd48 | 208 | * \brief A callback indicating that the bootstap has been performed successfully. |
leothedragon | 0:8f0bb79ddd48 | 209 | * \param server_object, The server object that contains the information fetched |
leothedragon | 0:8f0bb79ddd48 | 210 | * about the LWM2M server from the bootstrap server. This object can be used |
leothedragon | 0:8f0bb79ddd48 | 211 | * to register with the LWM2M server. The object ownership is passed. |
leothedragon | 0:8f0bb79ddd48 | 212 | */ |
leothedragon | 0:8f0bb79ddd48 | 213 | virtual void bootstrap_done(M2MSecurity *server_object); |
leothedragon | 0:8f0bb79ddd48 | 214 | |
leothedragon | 0:8f0bb79ddd48 | 215 | /** |
leothedragon | 0:8f0bb79ddd48 | 216 | * \brief A callback indicating when all bootstrap data has been received. |
leothedragon | 0:8f0bb79ddd48 | 217 | * \param security_object, The security object that contains the security information. |
leothedragon | 0:8f0bb79ddd48 | 218 | */ |
leothedragon | 0:8f0bb79ddd48 | 219 | virtual void bootstrap_data_ready(M2MSecurity *security_object); |
leothedragon | 0:8f0bb79ddd48 | 220 | |
leothedragon | 0:8f0bb79ddd48 | 221 | /** |
leothedragon | 0:8f0bb79ddd48 | 222 | * \brief A callback indicating that the device object has been registered |
leothedragon | 0:8f0bb79ddd48 | 223 | * successfully with the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 224 | * \param security_object, The server object on which the device object is |
leothedragon | 0:8f0bb79ddd48 | 225 | * registered. The object ownership is passed. |
leothedragon | 0:8f0bb79ddd48 | 226 | * \param server_object, An object containing information about the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 227 | * The client maintains the object. |
leothedragon | 0:8f0bb79ddd48 | 228 | */ |
leothedragon | 0:8f0bb79ddd48 | 229 | virtual void object_registered(M2MSecurity *security_object, const M2MServer &server_object); |
leothedragon | 0:8f0bb79ddd48 | 230 | |
leothedragon | 0:8f0bb79ddd48 | 231 | /** |
leothedragon | 0:8f0bb79ddd48 | 232 | * \brief A callback indicating that the device object has been successfully unregistered |
leothedragon | 0:8f0bb79ddd48 | 233 | * from the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 234 | * \param server_object, The server object from which the device object is |
leothedragon | 0:8f0bb79ddd48 | 235 | * unregistered. The object ownership is passed. |
leothedragon | 0:8f0bb79ddd48 | 236 | */ |
leothedragon | 0:8f0bb79ddd48 | 237 | virtual void object_unregistered(M2MSecurity *server_object); |
leothedragon | 0:8f0bb79ddd48 | 238 | |
leothedragon | 0:8f0bb79ddd48 | 239 | /** |
leothedragon | 0:8f0bb79ddd48 | 240 | * \brief A callback indicating that the device object registration has been successfully |
leothedragon | 0:8f0bb79ddd48 | 241 | * updated on the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 242 | * \param security_object, The server object on which the device object registration is |
leothedragon | 0:8f0bb79ddd48 | 243 | * updated. The object ownership is passed. |
leothedragon | 0:8f0bb79ddd48 | 244 | * \param server_object, An object containing information about the LWM2M server. |
leothedragon | 0:8f0bb79ddd48 | 245 | * The client maintains the object. |
leothedragon | 0:8f0bb79ddd48 | 246 | */ |
leothedragon | 0:8f0bb79ddd48 | 247 | virtual void registration_updated(M2MSecurity *security_object, const M2MServer & server_object); |
leothedragon | 0:8f0bb79ddd48 | 248 | |
leothedragon | 0:8f0bb79ddd48 | 249 | /** |
leothedragon | 0:8f0bb79ddd48 | 250 | * \brief A callback indicating that there was an error during the operation. |
leothedragon | 0:8f0bb79ddd48 | 251 | * \param error, An error code for the occurred error. |
leothedragon | 0:8f0bb79ddd48 | 252 | */ |
leothedragon | 0:8f0bb79ddd48 | 253 | virtual void error(M2MInterface::Error error); |
leothedragon | 0:8f0bb79ddd48 | 254 | |
leothedragon | 0:8f0bb79ddd48 | 255 | /** |
leothedragon | 0:8f0bb79ddd48 | 256 | * \brief A callback indicating that the value of the resource object is updated by the server. |
leothedragon | 0:8f0bb79ddd48 | 257 | * \param base, The object whose value is updated. |
leothedragon | 0:8f0bb79ddd48 | 258 | * \param type, The type of the object. |
leothedragon | 0:8f0bb79ddd48 | 259 | */ |
leothedragon | 0:8f0bb79ddd48 | 260 | virtual void value_updated(M2MBase *base, M2MBase::BaseType type); |
leothedragon | 0:8f0bb79ddd48 | 261 | |
leothedragon | 0:8f0bb79ddd48 | 262 | protected: // from M2MTimerObserver |
leothedragon | 0:8f0bb79ddd48 | 263 | |
leothedragon | 0:8f0bb79ddd48 | 264 | virtual void timer_expired(M2MTimerObserver::Type type); |
leothedragon | 0:8f0bb79ddd48 | 265 | |
leothedragon | 0:8f0bb79ddd48 | 266 | private: |
leothedragon | 0:8f0bb79ddd48 | 267 | /** |
leothedragon | 0:8f0bb79ddd48 | 268 | * \brief Redirects the state machine to right function. |
leothedragon | 0:8f0bb79ddd48 | 269 | * \param current_state, The current state to be set. |
leothedragon | 0:8f0bb79ddd48 | 270 | * \param data, The data to be passed to the state function. |
leothedragon | 0:8f0bb79ddd48 | 271 | */ |
leothedragon | 0:8f0bb79ddd48 | 272 | void state_function(StartupSubStateRegistration current_state); |
leothedragon | 0:8f0bb79ddd48 | 273 | |
leothedragon | 0:8f0bb79ddd48 | 274 | /** |
leothedragon | 0:8f0bb79ddd48 | 275 | * \brief The state engine maintaining the state machine logic. |
leothedragon | 0:8f0bb79ddd48 | 276 | */ |
leothedragon | 0:8f0bb79ddd48 | 277 | void state_engine(void); |
leothedragon | 0:8f0bb79ddd48 | 278 | |
leothedragon | 0:8f0bb79ddd48 | 279 | /** |
leothedragon | 0:8f0bb79ddd48 | 280 | * \brief An internal event generated by the state machine. |
leothedragon | 0:8f0bb79ddd48 | 281 | * \param new_state, The new state to which the state machine should go. |
leothedragon | 0:8f0bb79ddd48 | 282 | * \param data, The data to be passed to the state machine. |
leothedragon | 0:8f0bb79ddd48 | 283 | */ |
leothedragon | 0:8f0bb79ddd48 | 284 | void internal_event(StartupSubStateRegistration new_state); |
leothedragon | 0:8f0bb79ddd48 | 285 | |
leothedragon | 0:8f0bb79ddd48 | 286 | /** |
leothedragon | 0:8f0bb79ddd48 | 287 | * When the bootstrap starts. |
leothedragon | 0:8f0bb79ddd48 | 288 | */ |
leothedragon | 0:8f0bb79ddd48 | 289 | void state_bootstrap_start(); |
leothedragon | 0:8f0bb79ddd48 | 290 | |
leothedragon | 0:8f0bb79ddd48 | 291 | /** |
leothedragon | 0:8f0bb79ddd48 | 292 | * When the bootstrap is started. |
leothedragon | 0:8f0bb79ddd48 | 293 | */ |
leothedragon | 0:8f0bb79ddd48 | 294 | void state_bootstrap_started(); |
leothedragon | 0:8f0bb79ddd48 | 295 | |
leothedragon | 0:8f0bb79ddd48 | 296 | /** |
leothedragon | 0:8f0bb79ddd48 | 297 | * When the bootstrap is successful. |
leothedragon | 0:8f0bb79ddd48 | 298 | */ |
leothedragon | 0:8f0bb79ddd48 | 299 | void state_bootstrap_success(); |
leothedragon | 0:8f0bb79ddd48 | 300 | |
leothedragon | 0:8f0bb79ddd48 | 301 | /** |
leothedragon | 0:8f0bb79ddd48 | 302 | * When the bootstrap failed. |
leothedragon | 0:8f0bb79ddd48 | 303 | */ |
leothedragon | 0:8f0bb79ddd48 | 304 | void state_bootstrap_failure(); |
leothedragon | 0:8f0bb79ddd48 | 305 | |
leothedragon | 0:8f0bb79ddd48 | 306 | #ifndef MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 307 | /** |
leothedragon | 0:8f0bb79ddd48 | 308 | * When the EST (enrollment-over-secure-transport) enrollment starts. |
leothedragon | 0:8f0bb79ddd48 | 309 | */ |
leothedragon | 0:8f0bb79ddd48 | 310 | void state_est_start(); |
leothedragon | 0:8f0bb79ddd48 | 311 | |
leothedragon | 0:8f0bb79ddd48 | 312 | /** |
leothedragon | 0:8f0bb79ddd48 | 313 | * When the EST (enrollment-over-secure-transport) enrollment has been started. |
leothedragon | 0:8f0bb79ddd48 | 314 | */ |
leothedragon | 0:8f0bb79ddd48 | 315 | void state_est_started(); |
leothedragon | 0:8f0bb79ddd48 | 316 | |
leothedragon | 0:8f0bb79ddd48 | 317 | /** |
leothedragon | 0:8f0bb79ddd48 | 318 | * When the EST (enrollment-over-secure-transport) enrollment is successful. |
leothedragon | 0:8f0bb79ddd48 | 319 | */ |
leothedragon | 0:8f0bb79ddd48 | 320 | void state_est_success(); |
leothedragon | 0:8f0bb79ddd48 | 321 | |
leothedragon | 0:8f0bb79ddd48 | 322 | /** |
leothedragon | 0:8f0bb79ddd48 | 323 | * When the EST (enrollment-over-secure-transport) enrollment failed. |
leothedragon | 0:8f0bb79ddd48 | 324 | */ |
leothedragon | 0:8f0bb79ddd48 | 325 | void state_est_failure(); |
leothedragon | 0:8f0bb79ddd48 | 326 | #endif // !MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 327 | |
leothedragon | 0:8f0bb79ddd48 | 328 | /** |
leothedragon | 0:8f0bb79ddd48 | 329 | * When the registration starts. |
leothedragon | 0:8f0bb79ddd48 | 330 | */ |
leothedragon | 0:8f0bb79ddd48 | 331 | void state_registration_start(); |
leothedragon | 0:8f0bb79ddd48 | 332 | |
leothedragon | 0:8f0bb79ddd48 | 333 | /** |
leothedragon | 0:8f0bb79ddd48 | 334 | * When the registration started. |
leothedragon | 0:8f0bb79ddd48 | 335 | */ |
leothedragon | 0:8f0bb79ddd48 | 336 | void state_registration_started(); |
leothedragon | 0:8f0bb79ddd48 | 337 | |
leothedragon | 0:8f0bb79ddd48 | 338 | /** |
leothedragon | 0:8f0bb79ddd48 | 339 | * When the registration is successful. |
leothedragon | 0:8f0bb79ddd48 | 340 | */ |
leothedragon | 0:8f0bb79ddd48 | 341 | void state_registration_success(); |
leothedragon | 0:8f0bb79ddd48 | 342 | |
leothedragon | 0:8f0bb79ddd48 | 343 | /** |
leothedragon | 0:8f0bb79ddd48 | 344 | * When the registration failed. |
leothedragon | 0:8f0bb79ddd48 | 345 | */ |
leothedragon | 0:8f0bb79ddd48 | 346 | void state_registration_failure(); |
leothedragon | 0:8f0bb79ddd48 | 347 | |
leothedragon | 0:8f0bb79ddd48 | 348 | /** |
leothedragon | 0:8f0bb79ddd48 | 349 | * When the client is unregistered. |
leothedragon | 0:8f0bb79ddd48 | 350 | */ |
leothedragon | 0:8f0bb79ddd48 | 351 | void state_unregistered(); |
leothedragon | 0:8f0bb79ddd48 | 352 | |
leothedragon | 0:8f0bb79ddd48 | 353 | /** |
leothedragon | 0:8f0bb79ddd48 | 354 | * \brief A utility function to create an M2MSecurity object |
leothedragon | 0:8f0bb79ddd48 | 355 | * for registration. |
leothedragon | 0:8f0bb79ddd48 | 356 | */ |
leothedragon | 0:8f0bb79ddd48 | 357 | bool create_register_object(); |
leothedragon | 0:8f0bb79ddd48 | 358 | |
leothedragon | 0:8f0bb79ddd48 | 359 | /** |
leothedragon | 0:8f0bb79ddd48 | 360 | * \brief A utility function to create an M2MSecurity object |
leothedragon | 0:8f0bb79ddd48 | 361 | * for bootstrap. |
leothedragon | 0:8f0bb79ddd48 | 362 | */ |
leothedragon | 0:8f0bb79ddd48 | 363 | bool create_bootstrap_object(); |
leothedragon | 0:8f0bb79ddd48 | 364 | |
leothedragon | 0:8f0bb79ddd48 | 365 | /** |
leothedragon | 0:8f0bb79ddd48 | 366 | * \brief A utility function to set the connector credentials |
leothedragon | 0:8f0bb79ddd48 | 367 | * in storage. This includes endpoint, domain, connector URI |
leothedragon | 0:8f0bb79ddd48 | 368 | * and certificates. |
leothedragon | 0:8f0bb79ddd48 | 369 | * \param security, The Connector certificates. |
leothedragon | 0:8f0bb79ddd48 | 370 | */ |
leothedragon | 0:8f0bb79ddd48 | 371 | ccs_status_e set_connector_credentials(M2MSecurity *security); |
leothedragon | 0:8f0bb79ddd48 | 372 | |
leothedragon | 0:8f0bb79ddd48 | 373 | /** |
leothedragon | 0:8f0bb79ddd48 | 374 | * \brief A utility function to set the bootstrap credentials |
leothedragon | 0:8f0bb79ddd48 | 375 | * in storage. This includes Bootstrap URI and certificates. |
leothedragon | 0:8f0bb79ddd48 | 376 | * \param security, The Bootstrap certificates. |
leothedragon | 0:8f0bb79ddd48 | 377 | */ |
leothedragon | 0:8f0bb79ddd48 | 378 | ccs_status_e set_bootstrap_credentials(M2MSecurity *security); |
leothedragon | 0:8f0bb79ddd48 | 379 | |
leothedragon | 0:8f0bb79ddd48 | 380 | /** |
leothedragon | 0:8f0bb79ddd48 | 381 | * \brief A utility function to check whether bootstrap credentials are stored in KCM. |
leothedragon | 0:8f0bb79ddd48 | 382 | */ |
leothedragon | 0:8f0bb79ddd48 | 383 | bool bootstrap_credentials_stored_in_kcm(); |
leothedragon | 0:8f0bb79ddd48 | 384 | |
leothedragon | 0:8f0bb79ddd48 | 385 | /** |
leothedragon | 0:8f0bb79ddd48 | 386 | * \brief A utility function to check whether first to claim feature is configured. |
leothedragon | 0:8f0bb79ddd48 | 387 | */ |
leothedragon | 0:8f0bb79ddd48 | 388 | bool is_first_to_claim(); |
leothedragon | 0:8f0bb79ddd48 | 389 | |
leothedragon | 0:8f0bb79ddd48 | 390 | /** |
leothedragon | 0:8f0bb79ddd48 | 391 | * \brief A utility function to clear the first to claim parameter in storage. |
leothedragon | 0:8f0bb79ddd48 | 392 | */ |
leothedragon | 0:8f0bb79ddd48 | 393 | ccs_status_e clear_first_to_claim(); |
leothedragon | 0:8f0bb79ddd48 | 394 | |
leothedragon | 0:8f0bb79ddd48 | 395 | /** |
leothedragon | 0:8f0bb79ddd48 | 396 | * \brief Returns the binding mode selected by the client |
leothedragon | 0:8f0bb79ddd48 | 397 | * through the configuration. |
leothedragon | 0:8f0bb79ddd48 | 398 | * \return Binding mode of the client. |
leothedragon | 0:8f0bb79ddd48 | 399 | */ |
leothedragon | 0:8f0bb79ddd48 | 400 | static M2MInterface::BindingMode transport_mode(); |
leothedragon | 0:8f0bb79ddd48 | 401 | |
leothedragon | 0:8f0bb79ddd48 | 402 | /** |
leothedragon | 0:8f0bb79ddd48 | 403 | * \brief Initializes the security object and callbacks. |
leothedragon | 0:8f0bb79ddd48 | 404 | * |
leothedragon | 0:8f0bb79ddd48 | 405 | */ |
leothedragon | 0:8f0bb79ddd48 | 406 | void init_security_object(); |
leothedragon | 0:8f0bb79ddd48 | 407 | |
leothedragon | 0:8f0bb79ddd48 | 408 | private: |
leothedragon | 0:8f0bb79ddd48 | 409 | // A callback to be called after the sequence is complete. |
leothedragon | 0:8f0bb79ddd48 | 410 | ConnectorClientCallback* _callback; |
leothedragon | 0:8f0bb79ddd48 | 411 | StartupSubStateRegistration _current_state; |
leothedragon | 0:8f0bb79ddd48 | 412 | bool _event_generated; |
leothedragon | 0:8f0bb79ddd48 | 413 | bool _state_engine_running; |
leothedragon | 0:8f0bb79ddd48 | 414 | bool _setup_complete; |
leothedragon | 0:8f0bb79ddd48 | 415 | M2MInterface *_interface; |
leothedragon | 0:8f0bb79ddd48 | 416 | M2MSecurity *_security; |
leothedragon | 0:8f0bb79ddd48 | 417 | ConnectorClientEndpointInfo _endpoint_info; |
leothedragon | 0:8f0bb79ddd48 | 418 | M2MBaseList *_client_objs; |
leothedragon | 0:8f0bb79ddd48 | 419 | M2MTimer _rebootstrap_timer; |
leothedragon | 0:8f0bb79ddd48 | 420 | uint16_t _bootstrap_security_instance; |
leothedragon | 0:8f0bb79ddd48 | 421 | uint16_t _lwm2m_security_instance; |
leothedragon | 0:8f0bb79ddd48 | 422 | uint16_t _rebootstrap_time; |
leothedragon | 0:8f0bb79ddd48 | 423 | void *_certificate_chain_handle; |
leothedragon | 0:8f0bb79ddd48 | 424 | #ifndef MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 425 | EstClient _est_client; |
leothedragon | 0:8f0bb79ddd48 | 426 | #endif // !MBED_CLIENT_DISABLE_EST_FEATURE |
leothedragon | 0:8f0bb79ddd48 | 427 | }; |
leothedragon | 0:8f0bb79ddd48 | 428 | |
leothedragon | 0:8f0bb79ddd48 | 429 | /** |
leothedragon | 0:8f0bb79ddd48 | 430 | * \brief ConnectorClientCallback |
leothedragon | 0:8f0bb79ddd48 | 431 | * A callback class for passing the client progress and error condition to the |
leothedragon | 0:8f0bb79ddd48 | 432 | * ServiceClient class object. |
leothedragon | 0:8f0bb79ddd48 | 433 | */ |
leothedragon | 0:8f0bb79ddd48 | 434 | class ConnectorClientCallback { |
leothedragon | 0:8f0bb79ddd48 | 435 | public: |
leothedragon | 0:8f0bb79ddd48 | 436 | |
leothedragon | 0:8f0bb79ddd48 | 437 | /** |
leothedragon | 0:8f0bb79ddd48 | 438 | * \brief Indicates that the registration or unregistration operation is complete |
leothedragon | 0:8f0bb79ddd48 | 439 | * with success or failure. |
leothedragon | 0:8f0bb79ddd48 | 440 | * \param status, Indicates success or failure in terms of status code. |
leothedragon | 0:8f0bb79ddd48 | 441 | */ |
leothedragon | 0:8f0bb79ddd48 | 442 | virtual void registration_process_result(ConnectorClient::StartupSubStateRegistration status) = 0; |
leothedragon | 0:8f0bb79ddd48 | 443 | |
leothedragon | 0:8f0bb79ddd48 | 444 | /** |
leothedragon | 0:8f0bb79ddd48 | 445 | * \brief Indicates the Connector error condition of an underlying M2MInterface client. |
leothedragon | 0:8f0bb79ddd48 | 446 | * \param error, Indicates an error code translated from M2MInterface::Error. |
leothedragon | 0:8f0bb79ddd48 | 447 | * \param reason, Indicates human readable text for error description. |
leothedragon | 0:8f0bb79ddd48 | 448 | */ |
leothedragon | 0:8f0bb79ddd48 | 449 | virtual void connector_error(M2MInterface::Error error, const char *reason) = 0; |
leothedragon | 0:8f0bb79ddd48 | 450 | |
leothedragon | 0:8f0bb79ddd48 | 451 | /** |
leothedragon | 0:8f0bb79ddd48 | 452 | * \brief A callback indicating that the value of the resource object is updated |
leothedragon | 0:8f0bb79ddd48 | 453 | * by the LWM2M Cloud server. |
leothedragon | 0:8f0bb79ddd48 | 454 | * \param base, The object whose value is updated. |
leothedragon | 0:8f0bb79ddd48 | 455 | * \param type, The type of the object. |
leothedragon | 0:8f0bb79ddd48 | 456 | */ |
leothedragon | 0:8f0bb79ddd48 | 457 | virtual void value_updated(M2MBase *base, M2MBase::BaseType type) = 0; |
leothedragon | 0:8f0bb79ddd48 | 458 | }; |
leothedragon | 0:8f0bb79ddd48 | 459 | |
leothedragon | 0:8f0bb79ddd48 | 460 | #endif // !__CONNECTOR_CLIENT_H__ |