Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/source/include/m2mnsdlinterface.h@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New 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 | #ifndef M2MNSDLINTERFACE_H |
ram54288 | 0:a7a43371b306 | 17 | #define M2MNSDLINTERFACE_H |
ram54288 | 0:a7a43371b306 | 18 | |
ram54288 | 0:a7a43371b306 | 19 | #include "mbed-client/m2mvector.h" |
ram54288 | 0:a7a43371b306 | 20 | #include "mbed-client/m2mconfig.h" |
ram54288 | 0:a7a43371b306 | 21 | #include "mbed-client/m2minterface.h" |
ram54288 | 0:a7a43371b306 | 22 | #include "mbed-client/m2mtimerobserver.h" |
ram54288 | 0:a7a43371b306 | 23 | #include "mbed-client/m2mobservationhandler.h" |
ram54288 | 0:a7a43371b306 | 24 | #include "mbed-client/m2mbase.h" |
ram54288 | 0:a7a43371b306 | 25 | #include "mbed-client/m2mserver.h" |
ram54288 | 0:a7a43371b306 | 26 | #include "include/nsdllinker.h" |
ram54288 | 0:a7a43371b306 | 27 | |
ram54288 | 0:a7a43371b306 | 28 | //FORWARD DECLARARTION |
ram54288 | 0:a7a43371b306 | 29 | class M2MSecurity; |
ram54288 | 0:a7a43371b306 | 30 | class M2MObject; |
ram54288 | 0:a7a43371b306 | 31 | class M2MObjectInstance; |
ram54288 | 0:a7a43371b306 | 32 | class M2MResource; |
ram54288 | 0:a7a43371b306 | 33 | class M2MResourceInstance; |
ram54288 | 0:a7a43371b306 | 34 | class M2MNsdlObserver; |
ram54288 | 0:a7a43371b306 | 35 | class M2MServer; |
ram54288 | 0:a7a43371b306 | 36 | class M2MTimer; |
ram54288 | 0:a7a43371b306 | 37 | |
ram54288 | 0:a7a43371b306 | 38 | typedef Vector<M2MObject *> M2MObjectList; |
ram54288 | 0:a7a43371b306 | 39 | |
ram54288 | 0:a7a43371b306 | 40 | /** |
ram54288 | 0:a7a43371b306 | 41 | * @brief M2MNsdlInterface |
ram54288 | 0:a7a43371b306 | 42 | * Class which interacts between mbed Client C++ Library and mbed-client-c library. |
ram54288 | 0:a7a43371b306 | 43 | */ |
ram54288 | 0:a7a43371b306 | 44 | class M2MNsdlInterface : public M2MTimerObserver, |
ram54288 | 0:a7a43371b306 | 45 | public M2MObservationHandler |
ram54288 | 0:a7a43371b306 | 46 | { |
ram54288 | 0:a7a43371b306 | 47 | private: |
ram54288 | 0:a7a43371b306 | 48 | // Prevents the use of assignment operator by accident. |
ram54288 | 0:a7a43371b306 | 49 | M2MNsdlInterface& operator=( const M2MNsdlInterface& /*other*/ ); |
ram54288 | 0:a7a43371b306 | 50 | |
ram54288 | 0:a7a43371b306 | 51 | // Prevents the use of copy constructor by accident |
ram54288 | 0:a7a43371b306 | 52 | M2MNsdlInterface( const M2MNsdlInterface& /*other*/ ); |
ram54288 | 0:a7a43371b306 | 53 | |
ram54288 | 0:a7a43371b306 | 54 | public: |
ram54288 | 0:a7a43371b306 | 55 | /** |
ram54288 | 0:a7a43371b306 | 56 | * @brief Constructor |
ram54288 | 0:a7a43371b306 | 57 | * @param observer, Observer to pass the event callbacks from nsdl library. |
ram54288 | 0:a7a43371b306 | 58 | */ |
ram54288 | 0:a7a43371b306 | 59 | M2MNsdlInterface(M2MNsdlObserver &observer); |
ram54288 | 0:a7a43371b306 | 60 | |
ram54288 | 0:a7a43371b306 | 61 | /** |
ram54288 | 0:a7a43371b306 | 62 | * @brief Destructor |
ram54288 | 0:a7a43371b306 | 63 | */ |
ram54288 | 0:a7a43371b306 | 64 | virtual ~M2MNsdlInterface(); |
ram54288 | 0:a7a43371b306 | 65 | |
ram54288 | 0:a7a43371b306 | 66 | /** |
ram54288 | 0:a7a43371b306 | 67 | * @brief Creates endpoint object for the nsdl stack. |
ram54288 | 0:a7a43371b306 | 68 | * @param endpoint_name, Endpoint name of the client. |
ram54288 | 0:a7a43371b306 | 69 | * @param endpoint_type, Endpoint type of the client. |
ram54288 | 0:a7a43371b306 | 70 | * @param life_time, Life time of the client in seconds |
ram54288 | 0:a7a43371b306 | 71 | * @param domain, Domain of the client. |
ram54288 | 0:a7a43371b306 | 72 | * @param mode, Binding mode of the client, default is UDP |
ram54288 | 0:a7a43371b306 | 73 | * @param context_address, Context address default is empty. |
ram54288 | 0:a7a43371b306 | 74 | */ |
ram54288 | 0:a7a43371b306 | 75 | void create_endpoint(const String &endpoint_name, |
ram54288 | 0:a7a43371b306 | 76 | const String &endpoint_type, |
ram54288 | 0:a7a43371b306 | 77 | const int32_t life_time, |
ram54288 | 0:a7a43371b306 | 78 | const String &domain, |
ram54288 | 0:a7a43371b306 | 79 | const uint8_t mode, |
ram54288 | 0:a7a43371b306 | 80 | const String &context_address); |
ram54288 | 0:a7a43371b306 | 81 | |
ram54288 | 0:a7a43371b306 | 82 | /** |
ram54288 | 0:a7a43371b306 | 83 | * @brief Deletes the endpoint. |
ram54288 | 0:a7a43371b306 | 84 | */ |
ram54288 | 0:a7a43371b306 | 85 | void delete_endpoint(); |
ram54288 | 0:a7a43371b306 | 86 | |
ram54288 | 0:a7a43371b306 | 87 | /** |
ram54288 | 0:a7a43371b306 | 88 | * @brief Creates the NSDL structure for the registered objectlist. |
ram54288 | 0:a7a43371b306 | 89 | * @param object_list, List of objects to be registered. |
ram54288 | 0:a7a43371b306 | 90 | * @return true if structure created successfully else false. |
ram54288 | 0:a7a43371b306 | 91 | */ |
ram54288 | 0:a7a43371b306 | 92 | bool create_nsdl_list_structure(const M2MObjectList &object_list); |
ram54288 | 0:a7a43371b306 | 93 | |
ram54288 | 0:a7a43371b306 | 94 | /** |
ram54288 | 0:a7a43371b306 | 95 | * @brief Removed the NSDL resource for the given resource. |
ram54288 | 0:a7a43371b306 | 96 | * @param base, Resource to be removed. |
ram54288 | 0:a7a43371b306 | 97 | * @return true if removed successfully else false. |
ram54288 | 0:a7a43371b306 | 98 | */ |
ram54288 | 0:a7a43371b306 | 99 | bool remove_nsdl_resource(M2MBase *base); |
ram54288 | 0:a7a43371b306 | 100 | |
ram54288 | 0:a7a43371b306 | 101 | /** |
ram54288 | 0:a7a43371b306 | 102 | * @brief Creates the bootstrap object. |
ram54288 | 0:a7a43371b306 | 103 | * @param address Bootstrap address. |
ram54288 | 0:a7a43371b306 | 104 | * @return true if created and sent successfully else false. |
ram54288 | 0:a7a43371b306 | 105 | */ |
ram54288 | 0:a7a43371b306 | 106 | bool create_bootstrap_resource(sn_nsdl_addr_s *address, const String &bootstrap_endpoint_name); |
ram54288 | 0:a7a43371b306 | 107 | |
ram54288 | 0:a7a43371b306 | 108 | /** |
ram54288 | 0:a7a43371b306 | 109 | * @brief Sends the register message to the server. |
ram54288 | 0:a7a43371b306 | 110 | * @param address M2MServer address. |
ram54288 | 0:a7a43371b306 | 111 | * @param address_length M2MServer address length. |
ram54288 | 0:a7a43371b306 | 112 | * @param port M2MServer port. |
ram54288 | 0:a7a43371b306 | 113 | * @param address_type IP Address type. |
ram54288 | 0:a7a43371b306 | 114 | * @return true if register sent successfully else false. |
ram54288 | 0:a7a43371b306 | 115 | */ |
ram54288 | 0:a7a43371b306 | 116 | bool send_register_message(uint8_t* address, |
ram54288 | 0:a7a43371b306 | 117 | uint8_t address_length, |
ram54288 | 0:a7a43371b306 | 118 | const uint16_t port, |
ram54288 | 0:a7a43371b306 | 119 | sn_nsdl_addr_type_e address_type); |
ram54288 | 0:a7a43371b306 | 120 | |
ram54288 | 0:a7a43371b306 | 121 | /** |
ram54288 | 0:a7a43371b306 | 122 | * @brief Sends the update registration message to the server. |
ram54288 | 0:a7a43371b306 | 123 | * @param lifetime, Updated lifetime value in seconds. |
ram54288 | 0:a7a43371b306 | 124 | * @return true if sent successfully else false. |
ram54288 | 0:a7a43371b306 | 125 | * |
ram54288 | 0:a7a43371b306 | 126 | */ |
ram54288 | 0:a7a43371b306 | 127 | bool send_update_registration(const uint32_t lifetime = 0); |
ram54288 | 0:a7a43371b306 | 128 | |
ram54288 | 0:a7a43371b306 | 129 | /** |
ram54288 | 0:a7a43371b306 | 130 | * @brief Sends unregister message to the server. |
ram54288 | 0:a7a43371b306 | 131 | * @return true if unregister sent successfully else false. |
ram54288 | 0:a7a43371b306 | 132 | */ |
ram54288 | 0:a7a43371b306 | 133 | bool send_unregister_message(); |
ram54288 | 0:a7a43371b306 | 134 | |
ram54288 | 0:a7a43371b306 | 135 | /** |
ram54288 | 0:a7a43371b306 | 136 | * @brief Memory Allocation required for libCoap. |
ram54288 | 0:a7a43371b306 | 137 | * @param size, Size of memory to be reserved. |
ram54288 | 0:a7a43371b306 | 138 | */ |
ram54288 | 0:a7a43371b306 | 139 | static void* memory_alloc(uint16_t size); |
ram54288 | 0:a7a43371b306 | 140 | |
ram54288 | 0:a7a43371b306 | 141 | /** |
ram54288 | 0:a7a43371b306 | 142 | * @brief Memory free functions required for libCoap |
ram54288 | 0:a7a43371b306 | 143 | * @param ptr, Object whose memory needs to be freed. |
ram54288 | 0:a7a43371b306 | 144 | */ |
ram54288 | 0:a7a43371b306 | 145 | static void memory_free(void *ptr); |
ram54288 | 0:a7a43371b306 | 146 | |
ram54288 | 0:a7a43371b306 | 147 | /** |
ram54288 | 0:a7a43371b306 | 148 | * @brief Callback from nsdl library to inform the data is ready |
ram54288 | 0:a7a43371b306 | 149 | * to be sent to server. |
ram54288 | 0:a7a43371b306 | 150 | * @param nsdl_handle, Handler for the nsdl structure for this endpoint |
ram54288 | 0:a7a43371b306 | 151 | * @param protocol, Protocol format of the data |
ram54288 | 0:a7a43371b306 | 152 | * @param data, Data to be sent. |
ram54288 | 0:a7a43371b306 | 153 | * @param data_len, Size of the data to be sent |
ram54288 | 0:a7a43371b306 | 154 | * @param address, server address where data has to be sent. |
ram54288 | 0:a7a43371b306 | 155 | * @return 1 if successful else 0. |
ram54288 | 0:a7a43371b306 | 156 | */ |
ram54288 | 0:a7a43371b306 | 157 | uint8_t send_to_server_callback(struct nsdl_s * nsdl_handle, |
ram54288 | 0:a7a43371b306 | 158 | sn_nsdl_capab_e protocol, |
ram54288 | 0:a7a43371b306 | 159 | uint8_t *data, |
ram54288 | 0:a7a43371b306 | 160 | uint16_t data_len, |
ram54288 | 0:a7a43371b306 | 161 | sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 162 | |
ram54288 | 0:a7a43371b306 | 163 | /** |
ram54288 | 0:a7a43371b306 | 164 | * @brief Callback from nsdl library to inform the data which is |
ram54288 | 0:a7a43371b306 | 165 | * received from server for the client has been converted to coap message. |
ram54288 | 0:a7a43371b306 | 166 | * @param nsdl_handle, Handler for the nsdl structure for this endpoint |
ram54288 | 0:a7a43371b306 | 167 | * @param coap_header, Coap message formed from data. |
ram54288 | 0:a7a43371b306 | 168 | * @param address, Server address from where the data is received. |
ram54288 | 0:a7a43371b306 | 169 | * @return 1 if successful else 0. |
ram54288 | 0:a7a43371b306 | 170 | */ |
ram54288 | 0:a7a43371b306 | 171 | uint8_t received_from_server_callback(struct nsdl_s * nsdl_handle, |
ram54288 | 0:a7a43371b306 | 172 | sn_coap_hdr_s *coap_header, |
ram54288 | 0:a7a43371b306 | 173 | sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 174 | |
ram54288 | 0:a7a43371b306 | 175 | /** |
ram54288 | 0:a7a43371b306 | 176 | * @brief Callback from nsdl library to inform the data which is |
ram54288 | 0:a7a43371b306 | 177 | * received from server for the resources has been converted to coap message. |
ram54288 | 0:a7a43371b306 | 178 | * @param nsdl_handle, Handler for the nsdl resource structure for this endpoint.. |
ram54288 | 0:a7a43371b306 | 179 | * @param coap_header, Coap message formed from data. |
ram54288 | 0:a7a43371b306 | 180 | * @param address, Server address from where the data is received. |
ram54288 | 0:a7a43371b306 | 181 | * @param nsdl_capab, Protocol for the message, currently only coap is supported. |
ram54288 | 0:a7a43371b306 | 182 | * @return 1 if successful else 0. |
ram54288 | 0:a7a43371b306 | 183 | */ |
ram54288 | 0:a7a43371b306 | 184 | uint8_t resource_callback(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap, |
ram54288 | 0:a7a43371b306 | 185 | sn_nsdl_addr_s *address, |
ram54288 | 0:a7a43371b306 | 186 | sn_nsdl_capab_e nsdl_capab); |
ram54288 | 0:a7a43371b306 | 187 | |
ram54288 | 0:a7a43371b306 | 188 | /** |
ram54288 | 0:a7a43371b306 | 189 | * @brief Callback when there is data received from server and needs to be processed. |
ram54288 | 0:a7a43371b306 | 190 | * @param data, data received from server. |
ram54288 | 0:a7a43371b306 | 191 | * @param data_size, data size received from server. |
ram54288 | 0:a7a43371b306 | 192 | * @param addres, address structure of the server. |
ram54288 | 0:a7a43371b306 | 193 | * @return true if successfully processed else false. |
ram54288 | 0:a7a43371b306 | 194 | */ |
ram54288 | 0:a7a43371b306 | 195 | bool process_received_data(uint8_t *data, |
ram54288 | 0:a7a43371b306 | 196 | uint16_t data_size, |
ram54288 | 0:a7a43371b306 | 197 | sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 198 | |
ram54288 | 0:a7a43371b306 | 199 | /** |
ram54288 | 0:a7a43371b306 | 200 | * @brief Stops all the timers in case there is any errors. |
ram54288 | 0:a7a43371b306 | 201 | */ |
ram54288 | 0:a7a43371b306 | 202 | void stop_timers(); |
ram54288 | 0:a7a43371b306 | 203 | |
ram54288 | 0:a7a43371b306 | 204 | /** |
ram54288 | 0:a7a43371b306 | 205 | * @brief Returns nsdl handle. |
ram54288 | 0:a7a43371b306 | 206 | * @return ndsl handle |
ram54288 | 0:a7a43371b306 | 207 | */ |
ram54288 | 0:a7a43371b306 | 208 | nsdl_s* get_nsdl_handle(); |
ram54288 | 0:a7a43371b306 | 209 | |
ram54288 | 0:a7a43371b306 | 210 | /** |
ram54288 | 0:a7a43371b306 | 211 | * @brief Get endpoint name |
ram54288 | 0:a7a43371b306 | 212 | * @return endpoint name |
ram54288 | 0:a7a43371b306 | 213 | */ |
ram54288 | 0:a7a43371b306 | 214 | const String& endpoint_name() const; |
ram54288 | 0:a7a43371b306 | 215 | |
ram54288 | 0:a7a43371b306 | 216 | protected: // from M2MTimerObserver |
ram54288 | 0:a7a43371b306 | 217 | |
ram54288 | 0:a7a43371b306 | 218 | virtual void timer_expired(M2MTimerObserver::Type type); |
ram54288 | 0:a7a43371b306 | 219 | |
ram54288 | 0:a7a43371b306 | 220 | protected: // from M2MObservationHandler |
ram54288 | 0:a7a43371b306 | 221 | |
ram54288 | 0:a7a43371b306 | 222 | virtual void observation_to_be_sent(M2MBase *object, |
ram54288 | 0:a7a43371b306 | 223 | uint16_t obs_number, |
ram54288 | 0:a7a43371b306 | 224 | m2m::Vector<uint16_t> changed_instance_ids, |
ram54288 | 0:a7a43371b306 | 225 | bool send_object = false); |
ram54288 | 0:a7a43371b306 | 226 | |
ram54288 | 0:a7a43371b306 | 227 | virtual void resource_to_be_deleted(M2MBase* base); |
ram54288 | 0:a7a43371b306 | 228 | |
ram54288 | 0:a7a43371b306 | 229 | virtual void value_updated(M2MBase *base, const String &object_name); |
ram54288 | 0:a7a43371b306 | 230 | |
ram54288 | 0:a7a43371b306 | 231 | virtual void remove_object(M2MBase *object); |
ram54288 | 0:a7a43371b306 | 232 | |
ram54288 | 0:a7a43371b306 | 233 | virtual void send_delayed_response(M2MBase *base); |
ram54288 | 0:a7a43371b306 | 234 | |
ram54288 | 0:a7a43371b306 | 235 | private: |
ram54288 | 0:a7a43371b306 | 236 | |
ram54288 | 0:a7a43371b306 | 237 | /** |
ram54288 | 0:a7a43371b306 | 238 | * @brief Initializes all the nsdl library component to be usable. |
ram54288 | 0:a7a43371b306 | 239 | * @return true if initialization is successful else false. |
ram54288 | 0:a7a43371b306 | 240 | */ |
ram54288 | 0:a7a43371b306 | 241 | bool initialize(); |
ram54288 | 0:a7a43371b306 | 242 | |
ram54288 | 0:a7a43371b306 | 243 | bool add_object_to_list(M2MObject *object); |
ram54288 | 0:a7a43371b306 | 244 | |
ram54288 | 0:a7a43371b306 | 245 | bool create_nsdl_object_structure(M2MObject *object); |
ram54288 | 0:a7a43371b306 | 246 | |
ram54288 | 0:a7a43371b306 | 247 | bool create_nsdl_object_instance_structure(M2MObjectInstance *object_instance); |
ram54288 | 0:a7a43371b306 | 248 | |
ram54288 | 0:a7a43371b306 | 249 | bool create_nsdl_resource_structure(M2MResource *resource, |
ram54288 | 0:a7a43371b306 | 250 | bool multiple_instances = false); |
ram54288 | 0:a7a43371b306 | 251 | |
ram54288 | 0:a7a43371b306 | 252 | bool create_nsdl_resource(M2MBase *base); |
ram54288 | 0:a7a43371b306 | 253 | |
ram54288 | 0:a7a43371b306 | 254 | String coap_to_string(uint8_t *coap_data_ptr, |
ram54288 | 0:a7a43371b306 | 255 | int coap_data_ptr_length); |
ram54288 | 0:a7a43371b306 | 256 | |
ram54288 | 0:a7a43371b306 | 257 | void execute_nsdl_process_loop(); |
ram54288 | 0:a7a43371b306 | 258 | |
ram54288 | 0:a7a43371b306 | 259 | uint64_t registration_time(); |
ram54288 | 0:a7a43371b306 | 260 | |
ram54288 | 0:a7a43371b306 | 261 | M2MBase* find_resource(const String &object, |
ram54288 | 0:a7a43371b306 | 262 | uint8_t *token = NULL, |
ram54288 | 0:a7a43371b306 | 263 | uint8_t token_len = 0); |
ram54288 | 0:a7a43371b306 | 264 | |
ram54288 | 0:a7a43371b306 | 265 | M2MBase* find_resource(const M2MObject *object, |
ram54288 | 0:a7a43371b306 | 266 | const String &object_instance, |
ram54288 | 0:a7a43371b306 | 267 | uint8_t *token = NULL, |
ram54288 | 0:a7a43371b306 | 268 | uint8_t token_len = 0); |
ram54288 | 0:a7a43371b306 | 269 | |
ram54288 | 0:a7a43371b306 | 270 | M2MBase* find_resource(const M2MObjectInstance *object_instance, |
ram54288 | 0:a7a43371b306 | 271 | const String &resource_instance, |
ram54288 | 0:a7a43371b306 | 272 | uint8_t *token = NULL, |
ram54288 | 0:a7a43371b306 | 273 | uint8_t token_len = 0); |
ram54288 | 0:a7a43371b306 | 274 | |
ram54288 | 0:a7a43371b306 | 275 | M2MBase* find_resource(const M2MResource *resource, |
ram54288 | 0:a7a43371b306 | 276 | const String &object_name, |
ram54288 | 0:a7a43371b306 | 277 | const String &resource_instance, |
ram54288 | 0:a7a43371b306 | 278 | uint8_t *token = NULL, |
ram54288 | 0:a7a43371b306 | 279 | uint8_t token_len = 0); |
ram54288 | 0:a7a43371b306 | 280 | |
ram54288 | 0:a7a43371b306 | 281 | bool object_present(M2MObject * object) const; |
ram54288 | 0:a7a43371b306 | 282 | |
ram54288 | 0:a7a43371b306 | 283 | M2MInterface::Error interface_error(sn_coap_hdr_s *coap_header); |
ram54288 | 0:a7a43371b306 | 284 | |
ram54288 | 0:a7a43371b306 | 285 | void send_object_observation(M2MObject *object, |
ram54288 | 0:a7a43371b306 | 286 | uint16_t obs_number, |
ram54288 | 0:a7a43371b306 | 287 | m2m::Vector<uint16_t> changed_instance_ids, |
ram54288 | 0:a7a43371b306 | 288 | bool send_object); |
ram54288 | 0:a7a43371b306 | 289 | |
ram54288 | 0:a7a43371b306 | 290 | void send_object_instance_observation(M2MObjectInstance *object_instance, |
ram54288 | 0:a7a43371b306 | 291 | uint16_t obs_number); |
ram54288 | 0:a7a43371b306 | 292 | |
ram54288 | 0:a7a43371b306 | 293 | void send_resource_observation(M2MResource *resource, uint16_t obs_number); |
ram54288 | 0:a7a43371b306 | 294 | |
ram54288 | 0:a7a43371b306 | 295 | void send_notification(uint8_t *token, |
ram54288 | 0:a7a43371b306 | 296 | uint8_t token_length, |
ram54288 | 0:a7a43371b306 | 297 | uint8_t *value, |
ram54288 | 0:a7a43371b306 | 298 | uint32_t value_length, |
ram54288 | 0:a7a43371b306 | 299 | uint16_t observation, |
ram54288 | 0:a7a43371b306 | 300 | uint32_t max_age, |
ram54288 | 0:a7a43371b306 | 301 | uint8_t coap_content_type); |
ram54288 | 0:a7a43371b306 | 302 | |
ram54288 | 0:a7a43371b306 | 303 | /** |
ram54288 | 0:a7a43371b306 | 304 | * @brief Allocate (size + 1) amount of memory, copy size bytes into |
ram54288 | 0:a7a43371b306 | 305 | * it and add zero termination. |
ram54288 | 0:a7a43371b306 | 306 | * @param source Source string to copy, may not be NULL. |
ram54288 | 0:a7a43371b306 | 307 | * @param size The size of memory to be reserved. |
ram54288 | 0:a7a43371b306 | 308 | */ |
ram54288 | 0:a7a43371b306 | 309 | static uint8_t* alloc_string_copy(const uint8_t* source, uint16_t size); |
ram54288 | 0:a7a43371b306 | 310 | |
ram54288 | 0:a7a43371b306 | 311 | /** |
ram54288 | 0:a7a43371b306 | 312 | * @brief Utility method to convert given lifetime int to ascii |
ram54288 | 0:a7a43371b306 | 313 | * and allocate a buffer for it and set it to _endpoint->lifetime_ptr. |
ram54288 | 0:a7a43371b306 | 314 | * @param lifetime A new value for lifetime. |
ram54288 | 0:a7a43371b306 | 315 | */ |
ram54288 | 0:a7a43371b306 | 316 | void set_endpoint_lifetime_buffer(int lifetime); |
ram54288 | 0:a7a43371b306 | 317 | |
ram54288 | 0:a7a43371b306 | 318 | /** |
ram54288 | 0:a7a43371b306 | 319 | * @brief Handle incoming bootstrap PUT message. |
ram54288 | 0:a7a43371b306 | 320 | * @param coap_header, Received CoAP message |
ram54288 | 0:a7a43371b306 | 321 | * @param address, Server address |
ram54288 | 0:a7a43371b306 | 322 | */ |
ram54288 | 0:a7a43371b306 | 323 | void handle_bootstrap_put_message(sn_coap_hdr_s *coap_header, sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 324 | |
ram54288 | 0:a7a43371b306 | 325 | /** |
ram54288 | 0:a7a43371b306 | 326 | * @brief Handle bootstrap finished message. |
ram54288 | 0:a7a43371b306 | 327 | * @param coap_header, Received CoAP message |
ram54288 | 0:a7a43371b306 | 328 | * @param address, Server address |
ram54288 | 0:a7a43371b306 | 329 | */ |
ram54288 | 0:a7a43371b306 | 330 | void handle_bootstrap_finished(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 331 | |
ram54288 | 0:a7a43371b306 | 332 | /** |
ram54288 | 0:a7a43371b306 | 333 | * @brief Handle bootstrap delete message. |
ram54288 | 0:a7a43371b306 | 334 | * @param coap_header, Received CoAP message |
ram54288 | 0:a7a43371b306 | 335 | * @param address, Server address |
ram54288 | 0:a7a43371b306 | 336 | */ |
ram54288 | 0:a7a43371b306 | 337 | void handle_bootstrap_delete(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address); |
ram54288 | 0:a7a43371b306 | 338 | |
ram54288 | 0:a7a43371b306 | 339 | /** |
ram54288 | 0:a7a43371b306 | 340 | * @brief Parse bootstrap TLV message. |
ram54288 | 0:a7a43371b306 | 341 | * @param coap_header, Received CoAP message |
ram54288 | 0:a7a43371b306 | 342 | * @return True if parsing was succesful else false |
ram54288 | 0:a7a43371b306 | 343 | */ |
ram54288 | 0:a7a43371b306 | 344 | bool parse_bootstrap_message(sn_coap_hdr_s *coap_header, bool is_security_object); |
ram54288 | 0:a7a43371b306 | 345 | |
ram54288 | 0:a7a43371b306 | 346 | /** |
ram54288 | 0:a7a43371b306 | 347 | * @brief Parse bootstrap TLV message. |
ram54288 | 0:a7a43371b306 | 348 | * @param coap_header, Received CoAP message |
ram54288 | 0:a7a43371b306 | 349 | * @return True if parsing was succesful else false |
ram54288 | 0:a7a43371b306 | 350 | */ |
ram54288 | 0:a7a43371b306 | 351 | bool validate_security_object(); |
ram54288 | 0:a7a43371b306 | 352 | |
ram54288 | 0:a7a43371b306 | 353 | /** |
ram54288 | 0:a7a43371b306 | 354 | * @brief Handle bootstrap errors. |
ram54288 | 0:a7a43371b306 | 355 | */ |
ram54288 | 0:a7a43371b306 | 356 | void handle_bootstrap_error(); |
ram54288 | 0:a7a43371b306 | 357 | |
ram54288 | 0:a7a43371b306 | 358 | private: |
ram54288 | 0:a7a43371b306 | 359 | |
ram54288 | 0:a7a43371b306 | 360 | M2MNsdlObserver &_observer; |
ram54288 | 0:a7a43371b306 | 361 | M2MObjectList _object_list; |
ram54288 | 0:a7a43371b306 | 362 | sn_nsdl_ep_parameters_s *_endpoint; |
ram54288 | 0:a7a43371b306 | 363 | nsdl_s *_nsdl_handle; |
ram54288 | 0:a7a43371b306 | 364 | M2MSecurity *_security; // Not owned |
ram54288 | 0:a7a43371b306 | 365 | M2MServer _server; |
ram54288 | 0:a7a43371b306 | 366 | M2MTimer *_nsdl_exceution_timer; |
ram54288 | 0:a7a43371b306 | 367 | M2MTimer *_registration_timer; |
ram54288 | 0:a7a43371b306 | 368 | sn_nsdl_addr_s _sn_nsdl_address; |
ram54288 | 0:a7a43371b306 | 369 | String _endpoint_name; |
ram54288 | 0:a7a43371b306 | 370 | uint32_t _counter_for_nsdl; |
ram54288 | 0:a7a43371b306 | 371 | uint16_t _bootstrap_id; |
ram54288 | 0:a7a43371b306 | 372 | bool _unregister_ongoing; |
ram54288 | 0:a7a43371b306 | 373 | bool _identity_accepted; |
ram54288 | 0:a7a43371b306 | 374 | |
ram54288 | 0:a7a43371b306 | 375 | friend class Test_M2MNsdlInterface; |
ram54288 | 0:a7a43371b306 | 376 | |
ram54288 | 0:a7a43371b306 | 377 | }; |
ram54288 | 0:a7a43371b306 | 378 | |
ram54288 | 0:a7a43371b306 | 379 | #endif // M2MNSDLINTERFACE_H |
ram54288 | 0:a7a43371b306 | 380 |