Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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