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
EMACInterface.h
00001 /* LWIP implementation of NetworkInterfaceAPI 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may 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, 00012 * WITHOUT 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 EMAC_INTERFACE_H 00018 #define EMAC_INTERFACE_H 00019 00020 #include "nsapi.h" 00021 #include "EMAC.h" 00022 #include "OnboardNetworkStack.h" 00023 00024 00025 /** EMACInterface class 00026 * Implementation of the NetworkInterface for an EMAC-based driver 00027 * 00028 * This class provides the necessary glue logic to create a NetworkInterface 00029 * based on an EMAC and an OnboardNetworkStack. EthernetInterface and 00030 * EMAC-based Wi-Fi drivers derive from it. 00031 * 00032 * Drivers derived from EMACInterface should be constructed so that their 00033 * EMAC is functional without the need to call `connect()`. For example 00034 * a Wi-Fi driver should permit `WiFi::get_emac().power_up()` as soon as 00035 * the credentials have been set. This is necessary to support specialized 00036 * applications such as 6LoWPAN mesh border routers. 00037 */ 00038 class EMACInterface : public virtual NetworkInterface { 00039 public: 00040 /** Create an EMAC-based network interface. 00041 * 00042 * The default arguments obtain the default EMAC, which will be target- 00043 * dependent (and the target may have some JSON option to choose which 00044 * is the default, if there are multiple). The default stack is configured 00045 * by JSON option nsapi.default-stack. 00046 * 00047 * Due to inability to return errors from the constructor, no real 00048 * work is done until the first call to connect(). 00049 * 00050 * @param emac Reference to EMAC to use 00051 * @param stack Reference to onboard-network stack to use 00052 */ 00053 EMACInterface(EMAC &emac = EMAC::get_default_instance(), 00054 OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance()); 00055 00056 /** Set a static IP address 00057 * 00058 * Configures this network interface to use a static IP address. 00059 * Implicitly disables DHCP, which can be enabled in set_dhcp. 00060 * Requires that the network is disconnected. 00061 * 00062 * @param ip_address Null-terminated representation of the local IP address 00063 * @param netmask Null-terminated representation of the local network mask 00064 * @param gateway Null-terminated representation of the local gateway 00065 * @return 0 on success, negative error code on failure 00066 */ 00067 virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway); 00068 00069 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") 00070 virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway); 00071 00072 /** Enable or disable DHCP on the network 00073 * 00074 * Requires that the network is disconnected 00075 * 00076 * @param dhcp False to disable dhcp (defaults to enabled) 00077 * @retval NSAPI_ERROR_OK on success. 00078 * @retval NSAPI_ERROR_UNSUPPORTED if operation is not supported. 00079 */ 00080 virtual nsapi_error_t set_dhcp(bool dhcp); 00081 00082 /** @copydoc NetworkInterface::connect */ 00083 virtual nsapi_error_t connect (); 00084 00085 /** @copydoc NetworkInterface::disconnect */ 00086 virtual nsapi_error_t disconnect (); 00087 00088 /** @copydoc NetworkInterface::get_mac_address */ 00089 virtual const char *get_mac_address (); 00090 00091 /** @copydoc NetworkInterface::get_ip_address */ 00092 virtual nsapi_error_t get_ip_address (SocketAddress *address); 00093 00094 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") 00095 virtual const char *get_ip_address (); 00096 00097 /** @copydoc NetworkInterface::get_ipv6_link_local_address */ 00098 virtual nsapi_error_t get_ipv6_link_local_address (SocketAddress *address); 00099 00100 /** @copydoc NetworkInterface::get_netmask */ 00101 virtual nsapi_error_t get_netmask (SocketAddress *address); 00102 00103 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") 00104 virtual const char *get_netmask (); 00105 00106 /** @copydoc NetworkInterface::get_gateway */ 00107 virtual nsapi_error_t get_gateway (SocketAddress *address); 00108 00109 /** @copydoc NetworkInterface::get_gateway */ 00110 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated") 00111 virtual const char *get_gateway (); 00112 00113 /** @copydoc NetworkInterface::get_interface_name */ 00114 virtual char *get_interface_name (char *interface_name); 00115 00116 /** @copydoc NetworkInterface::set_as_default */ 00117 virtual void set_as_default (); 00118 00119 /** @copydoc NetworkInterface::attach */ 00120 virtual void attach (mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00121 00122 /** @copydoc NetworkInterface::get_connection_status */ 00123 virtual nsapi_connection_status_t get_connection_status () const; 00124 00125 /** @copydoc NetworkInterface::set_blocking */ 00126 virtual nsapi_error_t set_blocking (bool blocking); 00127 00128 /** Provide access to the EMAC 00129 * 00130 * This should be used with care - normally the network stack would 00131 * control the EMAC, so manipulating the EMAC while the stack 00132 * is also using it (ie after connect) will likely cause problems. 00133 * 00134 * @return Reference to the EMAC in use 00135 */ 00136 EMAC &get_emac() const 00137 { 00138 return _emac; 00139 } 00140 00141 virtual EMACInterface *emacInterface() 00142 { 00143 return this; 00144 } 00145 00146 protected: 00147 /** Provide access to the underlying stack 00148 * 00149 * @return The underlying network stack 00150 */ 00151 virtual NetworkStack *get_stack(); 00152 00153 EMAC &_emac; 00154 OnboardNetworkStack &_stack; 00155 OnboardNetworkStack::Interface *_interface; 00156 bool _dhcp; 00157 bool _blocking; 00158 char _mac_address[NSAPI_MAC_SIZE]; 00159 char _ip_address[NSAPI_IPv6_SIZE]; 00160 char _netmask[NSAPI_IPv4_SIZE]; 00161 char _gateway[NSAPI_IPv4_SIZE]; 00162 mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00163 }; 00164 00165 #endif
Generated on Tue Jul 12 2022 13:54:18 by
