Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
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 protected: 00104 /** Provide access to the underlying stack 00105 * 00106 * @return The underlying network stack 00107 */ 00108 virtual NetworkStack *get_stack(); 00109 00110 bool _dhcp; 00111 char _ip_address[IPADDR_STRLEN_MAX]; 00112 char _netmask[NSAPI_IPv4_SIZE]; 00113 char _gateway[NSAPI_IPv4_SIZE]; 00114 }; 00115 00116 00117 #endif
Generated on Sun Jul 17 2022 08:25:22 by 1.7.2