Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* LWIP implementation of NetworkInterfaceAPI
switches 0:5c4d7b2438d3 2 * Copyright (c) 2015 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16
switches 0:5c4d7b2438d3 17 #ifndef ETHERNET_INTERFACE_H
switches 0:5c4d7b2438d3 18 #define ETHERNET_INTERFACE_H
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 #include "nsapi.h"
switches 0:5c4d7b2438d3 21 #include "rtos.h"
switches 0:5c4d7b2438d3 22 #include "lwip/netif.h"
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 // Forward declaration
switches 0:5c4d7b2438d3 25 class NetworkStack;
switches 0:5c4d7b2438d3 26
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 /** EthernetInterface class
switches 0:5c4d7b2438d3 29 * Implementation of the NetworkStack for LWIP
switches 0:5c4d7b2438d3 30 */
switches 0:5c4d7b2438d3 31 class EthernetInterface : public EthInterface
switches 0:5c4d7b2438d3 32 {
switches 0:5c4d7b2438d3 33 public:
switches 0:5c4d7b2438d3 34 /** EthernetInterface lifetime
switches 0:5c4d7b2438d3 35 */
switches 0:5c4d7b2438d3 36 EthernetInterface();
switches 0:5c4d7b2438d3 37
switches 0:5c4d7b2438d3 38 /** Set a static IP address
switches 0:5c4d7b2438d3 39 *
switches 0:5c4d7b2438d3 40 * Configures this network interface to use a static IP address.
switches 0:5c4d7b2438d3 41 * Implicitly disables DHCP, which can be enabled in set_dhcp.
switches 0:5c4d7b2438d3 42 * Requires that the network is disconnected.
switches 0:5c4d7b2438d3 43 *
switches 0:5c4d7b2438d3 44 * @param address Null-terminated representation of the local IP address
switches 0:5c4d7b2438d3 45 * @param netmask Null-terminated representation of the local network mask
switches 0:5c4d7b2438d3 46 * @param gateway Null-terminated representation of the local gateway
switches 0:5c4d7b2438d3 47 * @return 0 on success, negative error code on failure
switches 0:5c4d7b2438d3 48 */
switches 0:5c4d7b2438d3 49 virtual nsapi_error_t set_network(
switches 0:5c4d7b2438d3 50 const char *ip_address, const char *netmask, const char *gateway);
switches 0:5c4d7b2438d3 51
switches 0:5c4d7b2438d3 52 /** Enable or disable DHCP on the network
switches 0:5c4d7b2438d3 53 *
switches 0:5c4d7b2438d3 54 * Requires that the network is disconnected
switches 0:5c4d7b2438d3 55 *
switches 0:5c4d7b2438d3 56 * @param dhcp False to disable dhcp (defaults to enabled)
switches 0:5c4d7b2438d3 57 * @return 0 on success, negative error code on failure
switches 0:5c4d7b2438d3 58 */
switches 0:5c4d7b2438d3 59 virtual nsapi_error_t set_dhcp(bool dhcp);
switches 0:5c4d7b2438d3 60
switches 0:5c4d7b2438d3 61 /** Start the interface
switches 0:5c4d7b2438d3 62 * @return 0 on success, negative on failure
switches 0:5c4d7b2438d3 63 */
switches 0:5c4d7b2438d3 64 virtual nsapi_error_t connect();
switches 0:5c4d7b2438d3 65
switches 0:5c4d7b2438d3 66 /** Stop the interface
switches 0:5c4d7b2438d3 67 * @return 0 on success, negative on failure
switches 0:5c4d7b2438d3 68 */
switches 0:5c4d7b2438d3 69 virtual nsapi_error_t disconnect();
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 /** Get the local MAC address
switches 0:5c4d7b2438d3 72 *
switches 0:5c4d7b2438d3 73 * Provided MAC address is intended for info or debug purposes and
switches 0:5c4d7b2438d3 74 * may not be provided if the underlying network interface does not
switches 0:5c4d7b2438d3 75 * provide a MAC address
switches 0:5c4d7b2438d3 76 *
switches 0:5c4d7b2438d3 77 * @return Null-terminated representation of the local MAC address
switches 0:5c4d7b2438d3 78 * or null if no MAC address is available
switches 0:5c4d7b2438d3 79 */
switches 0:5c4d7b2438d3 80 virtual const char *get_mac_address();
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 /** Get the local IP address
switches 0:5c4d7b2438d3 83 *
switches 0:5c4d7b2438d3 84 * @return Null-terminated representation of the local IP address
switches 0:5c4d7b2438d3 85 * or null if no IP address has been recieved
switches 0:5c4d7b2438d3 86 */
switches 0:5c4d7b2438d3 87 virtual const char *get_ip_address();
switches 0:5c4d7b2438d3 88
switches 0:5c4d7b2438d3 89 /** Get the local network mask
switches 0:5c4d7b2438d3 90 *
switches 0:5c4d7b2438d3 91 * @return Null-terminated representation of the local network mask
switches 0:5c4d7b2438d3 92 * or null if no network mask has been recieved
switches 0:5c4d7b2438d3 93 */
switches 0:5c4d7b2438d3 94 virtual const char *get_netmask();
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 /** Get the local gateways
switches 0:5c4d7b2438d3 97 *
switches 0:5c4d7b2438d3 98 * @return Null-terminated representation of the local gateway
switches 0:5c4d7b2438d3 99 * or null if no network mask has been recieved
switches 0:5c4d7b2438d3 100 */
switches 0:5c4d7b2438d3 101 virtual const char *get_gateway();
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 protected:
switches 0:5c4d7b2438d3 104 /** Provide access to the underlying stack
switches 0:5c4d7b2438d3 105 *
switches 0:5c4d7b2438d3 106 * @return The underlying network stack
switches 0:5c4d7b2438d3 107 */
switches 0:5c4d7b2438d3 108 virtual NetworkStack *get_stack();
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 bool _dhcp;
switches 0:5c4d7b2438d3 111 char _ip_address[IPADDR_STRLEN_MAX];
switches 0:5c4d7b2438d3 112 char _netmask[NSAPI_IPv4_SIZE];
switches 0:5c4d7b2438d3 113 char _gateway[NSAPI_IPv4_SIZE];
switches 0:5c4d7b2438d3 114 };
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116
switches 0:5c4d7b2438d3 117 #endif