mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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