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.
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 specialised 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 char *ip_address, const char *netmask, const char *gateway); 00068 00069 /** Enable or disable DHCP on the network 00070 * 00071 * Requires that the network is disconnected 00072 * 00073 * @param dhcp False to disable dhcp (defaults to enabled) 00074 * @return 0 on success, negative error code on failure 00075 */ 00076 virtual nsapi_error_t set_dhcp(bool dhcp); 00077 00078 /** Start the interface 00079 * @return 0 on success, negative on failure 00080 */ 00081 virtual nsapi_error_t connect(); 00082 00083 /** Stop the interface 00084 * @return 0 on success, negative on failure 00085 */ 00086 virtual nsapi_error_t disconnect(); 00087 00088 /** Get the local MAC address 00089 * 00090 * Provided MAC address is intended for info or debug purposes and 00091 * may not be provided if the underlying network interface does not 00092 * provide a MAC address 00093 * 00094 * @return Null-terminated representation of the local MAC address 00095 * or null if no MAC address is available 00096 */ 00097 virtual const char *get_mac_address(); 00098 00099 /** Get the local IP address 00100 * 00101 * @return Null-terminated representation of the local IP address 00102 * or null if no IP address has been recieved 00103 */ 00104 virtual const char *get_ip_address(); 00105 00106 /** Get the local network mask 00107 * 00108 * @return Null-terminated representation of the local network mask 00109 * or null if no network mask has been recieved 00110 */ 00111 virtual const char *get_netmask(); 00112 00113 /** Get the local gateways 00114 * 00115 * @return Null-terminated representation of the local gateway 00116 * or null if no network mask has been recieved 00117 */ 00118 virtual const char *get_gateway(); 00119 00120 /** Register callback for status reporting 00121 * 00122 * @param status_cb The callback for status changes 00123 */ 00124 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00125 00126 /** Get the connection status 00127 * 00128 * @return The connection status according to nsapi_connection_status_t 00129 */ 00130 virtual nsapi_connection_status_t get_connection_status() const; 00131 00132 /** Set blocking status of connect() which by default should be blocking 00133 * 00134 * @param blocking true if connect is blocking 00135 * @return 0 on success, negative error code on failure 00136 */ 00137 virtual nsapi_error_t set_blocking(bool blocking); 00138 00139 /** Provide access to the EMAC 00140 * 00141 * This should be used with care - normally the network stack would 00142 * control the EMAC, so manipulating the EMAC while the stack 00143 * is also using it (ie after connect) will likely cause problems. 00144 * 00145 * @return Reference to the EMAC in use 00146 */ 00147 EMAC &get_emac() const 00148 { 00149 return _emac; 00150 } 00151 00152 virtual EMACInterface *emacInterface() 00153 { 00154 return this; 00155 } 00156 00157 protected: 00158 /** Provide access to the underlying stack 00159 * 00160 * @return The underlying network stack 00161 */ 00162 virtual NetworkStack *get_stack(); 00163 00164 EMAC &_emac; 00165 OnboardNetworkStack &_stack; 00166 OnboardNetworkStack::Interface *_interface; 00167 bool _dhcp; 00168 bool _blocking; 00169 char _mac_address[NSAPI_MAC_SIZE]; 00170 char _ip_address[NSAPI_IPv6_SIZE]; 00171 char _netmask[NSAPI_IPv4_SIZE]; 00172 char _gateway[NSAPI_IPv4_SIZE]; 00173 mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00174 }; 00175 00176 #endif
Generated on Tue Jul 12 2022 20:52:41 by
 1.7.2
 1.7.2