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.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
lwm2mtest.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include <unistd.h> 00017 #include "mbed-client/m2minterfacefactory.h" 00018 #include "mbed-client/m2minterface.h" 00019 #include "mbed-client/m2mdevice.h" 00020 #include "mbed-client/m2minterfaceobserver.h" 00021 #include "mbed-client/m2mobjectinstance.h" 00022 #include "mbed-client/m2mresource.h" 00023 #include "mbed-client/m2mfirmware.h" 00024 00025 class M2MLWClient: public M2MInterfaceObserver { 00026 public: 00027 M2MLWClient(); 00028 00029 ~M2MLWClient(); 00030 00031 bool create_interface(int32_t param_count, 00032 const char *endpoint, 00033 const char *resource_type, 00034 const int32_t lifetime, 00035 const uint16_t listen_port, 00036 const char *domain, 00037 const uint8_t binding_mode, 00038 const uint8_t network_interface); 00039 00040 bool create_bootstrap_object(const char *coap_bootstrap_address); 00041 00042 bool create_register_object(const char *coap_register_address, bool useSecureConn); 00043 00044 bool test_bootstrap(); 00045 00046 bool create_device_object(); 00047 00048 bool create_device_object(M2MDevice::DeviceResource resource, 00049 const char *value); 00050 00051 bool create_device_object(M2MDevice::DeviceResource resource, 00052 int64_t value, 00053 uint16_t instance_id); 00054 00055 bool create_device_object(M2MDevice::DeviceResource resource, 00056 int64_t value); 00057 00058 bool create_firmware_object(); 00059 00060 bool create_firmware_object(M2MFirmware::FirmwareResource resource, 00061 const char *value); 00062 00063 bool create_firmware_object(M2MFirmware::FirmwareResource resource, 00064 int64_t value); 00065 00066 bool create_firmware_object(M2MFirmware::FirmwareResource resource, 00067 const uint8_t *value, 00068 const uint32_t length); 00069 00070 void firmware_resource_int(int resource); 00071 void firmware_resource_string(int resource); 00072 00073 void firmware_resource_buffer(); 00074 00075 bool create_object(const char *name, 00076 bool new_instance, 00077 uint8_t object_operation, 00078 uint8_t object_instance_operation, 00079 uint16_t object_instance_id, 00080 bool object_observable, 00081 bool object_instance_observable); 00082 00083 bool create_static_resource_string(const char *name, 00084 const char *value, 00085 bool multiple_instance, 00086 uint16_t object_instance = 0); 00087 00088 bool create_static_resource_int(const char *name, 00089 int64_t value, 00090 bool multiple_instance, 00091 uint16_t object_instance = 0); 00092 00093 bool create_dynamic_resource_int(const char *name, 00094 bool observable, 00095 bool multiple_instance, 00096 uint16_t object_instance = 0, 00097 uint8_t resource_operation = 1); 00098 bool create_dynamic_resource_string(const char *name, 00099 bool observable, 00100 bool multiple_instance, 00101 uint16_t object_instance = 0, 00102 uint8_t resource_operation = 1); 00103 00104 bool set_resource_value(const char *name, 00105 int32_t value, 00106 uint16_t object_instance = 0); 00107 00108 bool set_resource_value(const char *name, 00109 const char *value, 00110 uint16_t object_instance = 0); 00111 00112 bool create_static_resource_instance_string(const char *name, 00113 const char *value, 00114 bool multiple_instance, 00115 uint16_t object_instance = 0, 00116 uint16_t resource_instance = 0); 00117 00118 bool create_static_resource_instance_int(const char *name, 00119 int32_t value, 00120 bool multiple_instance, 00121 uint16_t object_instance = 0, 00122 uint16_t resource_instance = 0); 00123 00124 bool create_dynamic_resource_instance_int(const char *name, 00125 bool observable, 00126 bool multiple_instance, 00127 uint16_t object_instance = 0, 00128 uint16_t resource_instance = 0, 00129 uint8_t resource_instance_operation = 1); 00130 bool create_dynamic_resource_instance_string(const char *name, 00131 bool observable, 00132 bool multiple_instance, 00133 uint16_t object_instance = 0, 00134 uint16_t resource_instance = 0, 00135 uint8_t resource_instance_operation = 1); 00136 00137 bool set_resource_instance_value(const char *name, 00138 int32_t value, 00139 uint16_t object_instance = 0, 00140 uint16_t resource_instance = 0); 00141 00142 bool set_resource_instance_value(const char *name, 00143 const char *value, 00144 uint16_t object_instance = 0, 00145 uint16_t resource_instance = 0); 00146 00147 bool create_object_instance(); 00148 00149 bool test_register(); 00150 00151 bool test_update_register(const uint32_t lifetime); 00152 00153 bool test_unregister(); 00154 00155 void bootstrap_done(M2MSecurity *server_object); 00156 00157 void object_registered(M2MSecurity *security_object, const M2MServer &server_object); 00158 00159 void object_unregistered(M2MSecurity *server_object); 00160 00161 void registration_updated(M2MSecurity *security_object, const M2MServer &server_object); 00162 00163 void error(M2MInterface::Error error); 00164 00165 void value_updated(M2MBase *base, M2MBase::BaseType type); 00166 00167 void set_fw_execute_function(); 00168 00169 private: 00170 00171 M2MBase::Operation int_to_operation(uint8_t operation); 00172 void fw_execute_function(void *argument); 00173 00174 00175 private: 00176 00177 M2MInterface *_interface; 00178 M2MSecurity *_security; 00179 M2MSecurity *_register_security; 00180 M2MDevice *_device; 00181 M2MFirmware *_firmware; 00182 M2MObject *_object; 00183 bool _bootstrapped; 00184 bool _error; 00185 bool _registered; 00186 bool _unregistered; 00187 bool _registration_updated; 00188 }; 00189 00190 00191 const unsigned char psk[] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x30,0x31,0x32,0x33,0x34,0x35,0x36}; 00192 const size_t psk_len = sizeof( psk ); 00193 const unsigned char psk_identity[] = {0x0F,0x0F}; 00194 const size_t psk_identity_len = sizeof( psk_identity ); 00195 00196 const uint8_t server_cert[] = "-----BEGIN CERTIFICATE-----\r\n" 00197 "MIIBmDCCAT6gAwIBAgIEVUCA0jAKBggqhkjOPQQDAjBLMQswCQYDVQQGEwJGSTEN\r\n" 00198 "MAsGA1UEBwwET3VsdTEMMAoGA1UECgwDQVJNMQwwCgYDVQQLDANJb1QxETAPBgNV\r\n" 00199 "BAMMCEFSTSBtYmVkMB4XDTE1MDQyOTA2NTc0OFoXDTE4MDQyOTA2NTc0OFowSzEL\r\n" 00200 "MAkGA1UEBhMCRkkxDTALBgNVBAcMBE91bHUxDDAKBgNVBAoMA0FSTTEMMAoGA1UE\r\n" 00201 "CwwDSW9UMREwDwYDVQQDDAhBUk0gbWJlZDBZMBMGByqGSM49AgEGCCqGSM49AwEH\r\n" 00202 "A0IABLuAyLSk0mA3awgFR5mw2RHth47tRUO44q/RdzFZnLsAsd18Esxd5LCpcT9w\r\n" 00203 "0tvNfBv4xJxGw0wcYrPDDb8/rjujEDAOMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0E\r\n" 00204 "AwIDSAAwRQIhAPAonEAkwixlJiyYRQQWpXtkMZax+VlEiS201BG0PpAzAiBh2RsD\r\n" 00205 "NxLKWwf4O7D6JasGBYf9+ZLwl0iaRjTjytO+Kw==\r\n" 00206 "-----END CERTIFICATE-----\r\n"; 00207 00208 const uint8_t cert[] = "-----BEGIN CERTIFICATE-----\r\n" 00209 "MIICTDCCAbWgAwIBAgIJAKI3S+LGklSGMA0GCSqGSIb3DQEBCwUAMD8xCzAJBgNV\r\n" 00210 "BAYTAkZJMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQHDARPdWx1MQwwCgYD\r\n" 00211 "VQQKDANBUk0wHhcNMTUwNjExMTI0NTU1WhcNMTYwNjEwMTI0NTU1WjA/MQswCQYD\r\n" 00212 "VQQGEwJGSTETMBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UEBwwET3VsdTEMMAoG\r\n" 00213 "A1UECgwDQVJNMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBt8ag12ILm2pn\r\n" 00214 "RHUc2yMBXpdzspDwVV3VDaNTRXypVUOq/nxJc6zr8yG/Pvga2/XVijWQDLABHVhV\r\n" 00215 "PoeulzXVSEHRR2bR2lhqulLzdUzPYJ+yJd4+082akoxdzoom8ms2LFlgiXO7lyBg\r\n" 00216 "1t74xjEQapCkr7Tdl2pD9OTUrcfoEwIDAQABo1AwTjAdBgNVHQ4EFgQUHK0O4iK7\r\n" 00217 "Rv8AsxAqRDlY3TSHWtUwHwYDVR0jBBgwFoAUHK0O4iK7Rv8AsxAqRDlY3TSHWtUw\r\n" 00218 "DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQAPVLihYN65DEeYdf7gDAdP\r\n" 00219 "MNH5RxsQlHdktQkYWcUewe3hvOf8yZUBbmO5OeEQmy5Ca2H1QhUuw+kWHo1l/K9g\r\n" 00220 "DpR1xoDACeycBd/6tAHfaFzTEEDC9Ug839EAHDrbI4ihrPEbP6hyRIaUIM4IojXf\r\n" 00221 "zuqwOcobS3idv8a9Npuohw==\r\n" 00222 "-----END CERTIFICATE-----\r\n"; 00223 00224 const uint8_t key[] = "-----BEGIN PRIVATE KEY-----\r\n" 00225 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMG3xqDXYgubamdE\r\n" 00226 "dRzbIwFel3OykPBVXdUNo1NFfKlVQ6r+fElzrOvzIb8++Brb9dWKNZAMsAEdWFU+\r\n" 00227 "h66XNdVIQdFHZtHaWGq6UvN1TM9gn7Il3j7TzZqSjF3OiibyazYsWWCJc7uXIGDW\r\n" 00228 "3vjGMRBqkKSvtN2XakP05NStx+gTAgMBAAECgYEAlRimNxsu6jIXJh4paSk8ewxb\r\n" 00229 "0v+n0GJT0uwpPakotofaihxOepYejIfX/IMxoDKVtmImsZUiTelRGGMFORpGomS7\r\n" 00230 "3Pb9awfn1yWiYja9MF7+pgFtXj6LxcB5rcxrP8s9rCs+kEq8yl/khGXmlwlpacUm\r\n" 00231 "Pdg1rEHriykk/5dlyKkCQQD9zpgQKN87bQNOVSgFSNsrwCjEN2MvVUC6ycqVYqQd\r\n" 00232 "oQZrO2lJuf57Jn7kRKJgfqqImwLYaohn5A9gKiqszo+fAkEAw2REr8L9aLoRPe5Q\r\n" 00233 "4+lYCmNmxJjBbJoRviSlxx+p5dxK+8H4J+bnFUWzORFJP0+Bjhii2UHGBoMjuP2s\r\n" 00234 "e8xDDQJADm0IrZp1Hb6TeodSkAJVGsaASq7PP2h8FmHT1uvVYi293Khy0pL0yPEm\r\n" 00235 "MzlHdW6dqMgOwFhFyonm6dNbu5i+BwJBALSPKfIKDMcEev5yBgo3Dga7iLJQPx4u\r\n" 00236 "2gqOLyvtlME3a4tu2fV1qUG9ITuxP7DjteMr3QFLiMVn1lETCpt0TNkCQGIvyjdV\r\n" 00237 "RzYnzLDMulXCsuRBjs0C75KoZrcPPQ416SZFtYASsOl3P0Ih5jgt/1aPmth3Yson\r\n" 00238 "GdnBOWyKzadLmz8=\r\n" 00239 "-----END PRIVATE KEY-----\r\n"; 00240 00241 const size_t server_cert_len = sizeof( server_cert ); 00242 const size_t cert_len = sizeof( cert ); 00243 const size_t key_len = sizeof( key ); 00244
Generated on Tue Jul 12 2022 12:28:36 by
 1.7.2
 1.7.2 
    