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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
MeshInterfaceNanostack.h
00001 /* 00002 * Copyright (c) 2016-2019 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 00017 #ifndef MESHINTERFACENANOSTACK_H 00018 #define MESHINTERFACENANOSTACK_H 00019 00020 #include "Semaphore.h" 00021 #include "MeshInterface.h" 00022 #include "NanostackRfPhy.h" 00023 #include "Nanostack.h" 00024 #include "mesh_interface_types.h" 00025 00026 class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> { 00027 public: 00028 virtual nsapi_error_t get_ip_address(SocketAddress *address); 00029 MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated") 00030 virtual char *get_ip_address(char *buf, nsapi_size_t buflen); 00031 virtual char *get_mac_address(char *buf, nsapi_size_t buflen); 00032 virtual nsapi_error_t get_netmask(SocketAddress *address); 00033 MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated") 00034 virtual char *get_netmask(char *buf, nsapi_size_t buflen); 00035 virtual nsapi_error_t get_gateway(SocketAddress *address); 00036 MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated") 00037 virtual char *get_gateway(char *buf, nsapi_size_t buflen); 00038 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00039 virtual nsapi_connection_status_t get_connection_status() const; 00040 00041 void get_mac_address(uint8_t *buf) const 00042 { 00043 NanostackMACPhy *phy = interface_phy.nanostack_mac_phy(); 00044 if (phy) { 00045 phy->get_mac_address(buf); 00046 } 00047 } 00048 00049 /** 00050 * \brief Callback from C-layer 00051 * \param status state of the network 00052 * */ 00053 void network_handler(mesh_connection_status_t status); 00054 00055 int8_t get_interface_id() const 00056 { 00057 return interface_id; 00058 } 00059 int8_t get_driver_id() const 00060 { 00061 return _device_id; 00062 } 00063 00064 private: 00065 NanostackPhy &interface_phy; 00066 protected: 00067 Interface(NanostackPhy &phy); 00068 virtual nsapi_error_t register_phy(); 00069 NanostackPhy &get_phy() const 00070 { 00071 return interface_phy; 00072 } 00073 int8_t interface_id; 00074 int8_t _device_id; 00075 rtos::Semaphore connect_semaphore; 00076 rtos::Semaphore disconnect_semaphore; 00077 00078 mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00079 nsapi_connection_status_t _connect_status; 00080 nsapi_connection_status_t _previous_connection_status; 00081 bool _blocking; 00082 }; 00083 00084 class Nanostack::MeshInterface : public Nanostack::Interface { 00085 protected: 00086 MeshInterface(NanostackRfPhy &phy) : Interface(phy) { } 00087 NanostackRfPhy &get_phy() const 00088 { 00089 return static_cast<NanostackRfPhy &>(Interface::get_phy()); 00090 } 00091 }; 00092 00093 00094 class InterfaceNanostack : public virtual NetworkInterface { 00095 public: 00096 /** Start the interface 00097 * 00098 * @return 0 on success, negative error code on failure 00099 */ 00100 virtual nsapi_error_t connect(); 00101 00102 /** Stop the interface 00103 * 00104 * @return 0 on success, negative error code on failure 00105 */ 00106 virtual nsapi_error_t disconnect(); 00107 00108 /** @copydoc NetworkInterface::get_ip_address */ 00109 virtual nsapi_error_t get_ip_address(SocketAddress *address); 00110 00111 MBED_DEPRECATED_SINCE ("mbed-os-5.15", "String-based APIs are deprecated") 00112 virtual const char *get_ip_address(); 00113 00114 /** Get the internally stored MAC address 00115 /return MAC address of the interface 00116 */ 00117 virtual const char *get_mac_address(); 00118 00119 /** Register callback for status reporting 00120 * 00121 * The specified status callback function will be called on status changes 00122 * on the network. The parameters on the callback are the event type and 00123 * event-type dependent reason parameter. 00124 * 00125 * @param status_cb The callback for status changes 00126 */ 00127 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00128 00129 /** Get the connection status 00130 * 00131 * @return The connection status according to ConnectionStatusType 00132 */ 00133 virtual nsapi_connection_status_t get_connection_status() const; 00134 00135 /** Set blocking status of connect() which by default should be blocking 00136 * 00137 * @param blocking true if connect is blocking 00138 * @return 0 on success, negative error code on failure 00139 */ 00140 virtual nsapi_error_t set_blocking(bool blocking); 00141 00142 /** Set file system root path. 00143 * 00144 * Set file system root path that stack will use to write and read its data. 00145 * Setting root_path to NULL will disable file system usage. 00146 * 00147 * @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage. 00148 * @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error. 00149 */ 00150 virtual nsapi_error_t set_file_system_root_path(const char *root_path); 00151 00152 /** Get the interface ID 00153 * @return Interface identifier 00154 */ 00155 int8_t get_interface_id() const 00156 { 00157 return _interface->get_interface_id(); 00158 } 00159 00160 protected: 00161 InterfaceNanostack(); 00162 virtual Nanostack *get_stack(void); 00163 Nanostack::Interface *get_interface() const 00164 { 00165 return _interface; 00166 } 00167 virtual nsapi_error_t do_initialize() = 0; 00168 00169 Nanostack::Interface *_interface; 00170 00171 SocketAddress ip_addr; 00172 char mac_addr_str[24]; 00173 mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00174 bool _blocking; 00175 }; 00176 00177 class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> { 00178 public: 00179 00180 /** Attach phy and initialize the mesh 00181 * 00182 * Initializes a mesh interface on the given phy. Not needed if 00183 * the phy is passed to the mesh's constructor. 00184 * 00185 * @return 0 on success, negative on failure 00186 */ 00187 nsapi_error_t initialize(NanostackRfPhy *phy); 00188 00189 protected: 00190 MeshInterfaceNanostack() : _phy(NULL) { } 00191 MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { } 00192 Nanostack::MeshInterface *get_interface() const 00193 { 00194 return static_cast<Nanostack::MeshInterface *>(_interface); 00195 } 00196 NanostackRfPhy *_phy; 00197 }; 00198 00199 #endif /* MESHINTERFACENANOSTACK_H */
Generated on Tue Jul 12 2022 13:54:35 by
