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.
EthernetInterface.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 ETHERNET_INTERFACE_H 00018 #define ETHERNET_INTERFACE_H 00019 00020 #include "nsapi.h" 00021 #include "rtos.h" 00022 #include "lwip/netif.h" 00023 00024 // Forward declaration 00025 class NetworkStack; 00026 00027 00028 /** EthernetInterface class 00029 * Implementation of the NetworkStack for LWIP 00030 */ 00031 class EthernetInterface : public EthInterface 00032 { 00033 public: 00034 /** EthernetInterface lifetime 00035 */ 00036 EthernetInterface(); 00037 00038 /** Set a static IP address 00039 * 00040 * Configures this network interface to use a static IP address. 00041 * Implicitly disables DHCP, which can be enabled in set_dhcp. 00042 * Requires that the network is disconnected. 00043 * 00044 * @param address Null-terminated representation of the local IP address 00045 * @param netmask Null-terminated representation of the local network mask 00046 * @param gateway Null-terminated representation of the local gateway 00047 * @return 0 on success, negative error code on failure 00048 */ 00049 virtual nsapi_error_t set_network( 00050 const char *ip_address, const char *netmask, const char *gateway); 00051 00052 /** Enable or disable DHCP on the network 00053 * 00054 * Requires that the network is disconnected 00055 * 00056 * @param dhcp False to disable dhcp (defaults to enabled) 00057 * @return 0 on success, negative error code on failure 00058 */ 00059 virtual nsapi_error_t set_dhcp(bool dhcp); 00060 00061 /** Start the interface 00062 * @return 0 on success, negative on failure 00063 */ 00064 virtual nsapi_error_t connect(); 00065 00066 /** Stop the interface 00067 * @return 0 on success, negative on failure 00068 */ 00069 virtual nsapi_error_t disconnect(); 00070 00071 /** Get the local MAC address 00072 * 00073 * Provided MAC address is intended for info or debug purposes and 00074 * may not be provided if the underlying network interface does not 00075 * provide a MAC address 00076 * 00077 * @return Null-terminated representation of the local MAC address 00078 * or null if no MAC address is available 00079 */ 00080 virtual const char *get_mac_address(); 00081 00082 /** Get the local IP address 00083 * 00084 * @return Null-terminated representation of the local IP address 00085 * or null if no IP address has been recieved 00086 */ 00087 virtual const char *get_ip_address(); 00088 00089 /** Get the local network mask 00090 * 00091 * @return Null-terminated representation of the local network mask 00092 * or null if no network mask has been recieved 00093 */ 00094 virtual const char *get_netmask(); 00095 00096 /** Get the local gateways 00097 * 00098 * @return Null-terminated representation of the local gateway 00099 * or null if no network mask has been recieved 00100 */ 00101 virtual const char *get_gateway(); 00102 00103 /** Register callback for status reporting 00104 * 00105 * @param status_cb The callback for status changes 00106 */ 00107 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00108 00109 /** Get the connection status 00110 * 00111 * @return The connection status according to nsapi_connection_status_t 00112 */ 00113 virtual nsapi_connection_status_t get_connection_status() const; 00114 00115 /** Set blocking status of connect() which by default should be blocking 00116 * 00117 * @param blocking true if connect is blocking 00118 * @return 0 on success, negative error code on failure 00119 */ 00120 virtual nsapi_error_t set_blocking(bool blocking); 00121 00122 00123 protected: 00124 /** Provide access to the underlying stack 00125 * 00126 * @return The underlying network stack 00127 */ 00128 virtual NetworkStack *get_stack(); 00129 00130 bool _dhcp; 00131 char _ip_address[IPADDR_STRLEN_MAX]; 00132 char _netmask[NSAPI_IPv4_SIZE]; 00133 char _gateway[NSAPI_IPv4_SIZE]; 00134 00135 00136 Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00137 nsapi_connection_status_t _connect_status; 00138 static void netif_status_cb(void *, nsapi_event_t, intptr_t); 00139 }; 00140 00141 00142 #endif
Generated on Tue Jul 12 2022 14:23:38 by
