mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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