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
elessair 0:f269e3021894 2 /** \addtogroup netsocket */
elessair 0:f269e3021894 3 /** @{*/
elessair 0:f269e3021894 4 /* NetworkStack
elessair 0:f269e3021894 5 * Copyright (c) 2015 ARM Limited
elessair 0:f269e3021894 6 *
elessair 0:f269e3021894 7 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 8 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 9 * You may obtain a copy of the License at
elessair 0:f269e3021894 10 *
elessair 0:f269e3021894 11 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 12 *
elessair 0:f269e3021894 13 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 14 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 16 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 17 * limitations under the License.
elessair 0:f269e3021894 18 */
elessair 0:f269e3021894 19
elessair 0:f269e3021894 20 #ifndef NETWORK_INTERFACE_H
elessair 0:f269e3021894 21 #define NETWORK_INTERFACE_H
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #include "netsocket/nsapi_types.h"
elessair 0:f269e3021894 24 #include "netsocket/SocketAddress.h"
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 // Predeclared class
elessair 0:f269e3021894 27 class NetworkStack;
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30 /** NetworkInterface class
elessair 0:f269e3021894 31 *
elessair 0:f269e3021894 32 * Common interface that is shared between network devices
elessair 0:f269e3021894 33 */
elessair 0:f269e3021894 34 class NetworkInterface {
elessair 0:f269e3021894 35 public:
elessair 0:f269e3021894 36 virtual ~NetworkInterface() {};
elessair 0:f269e3021894 37
elessair 0:f269e3021894 38 /** Get the local MAC address
elessair 0:f269e3021894 39 *
elessair 0:f269e3021894 40 * Provided MAC address is intended for info or debug purposes and
elessair 0:f269e3021894 41 * may not be provided if the underlying network interface does not
elessair 0:f269e3021894 42 * provide a MAC address
elessair 0:f269e3021894 43 *
elessair 0:f269e3021894 44 * @return Null-terminated representation of the local MAC address
elessair 0:f269e3021894 45 * or null if no MAC address is available
elessair 0:f269e3021894 46 */
elessair 0:f269e3021894 47 virtual const char *get_mac_address();
elessair 0:f269e3021894 48
elessair 0:f269e3021894 49 /** Get the local IP address
elessair 0:f269e3021894 50 *
elessair 0:f269e3021894 51 * @return Null-terminated representation of the local IP address
elessair 0:f269e3021894 52 * or null if no IP address has been recieved
elessair 0:f269e3021894 53 */
elessair 0:f269e3021894 54 virtual const char *get_ip_address();
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 /** Get the local network mask
elessair 0:f269e3021894 57 *
elessair 0:f269e3021894 58 * @return Null-terminated representation of the local network mask
elessair 0:f269e3021894 59 * or null if no network mask has been recieved
elessair 0:f269e3021894 60 */
elessair 0:f269e3021894 61 virtual const char *get_netmask();
elessair 0:f269e3021894 62
elessair 0:f269e3021894 63 /** Get the local gateway
elessair 0:f269e3021894 64 *
elessair 0:f269e3021894 65 * @return Null-terminated representation of the local gateway
elessair 0:f269e3021894 66 * or null if no network mask has been recieved
elessair 0:f269e3021894 67 */
elessair 0:f269e3021894 68 virtual const char *get_gateway();
elessair 0:f269e3021894 69
elessair 0:f269e3021894 70 /** Set a static IP address
elessair 0:f269e3021894 71 *
elessair 0:f269e3021894 72 * Configures this network interface to use a static IP address.
elessair 0:f269e3021894 73 * Implicitly disables DHCP, which can be enabled in set_dhcp.
elessair 0:f269e3021894 74 * Requires that the network is disconnected.
elessair 0:f269e3021894 75 *
elessair 0:f269e3021894 76 * @param address Null-terminated representation of the local IP address
elessair 0:f269e3021894 77 * @param netmask Null-terminated representation of the local network mask
elessair 0:f269e3021894 78 * @param gateway Null-terminated representation of the local gateway
elessair 0:f269e3021894 79 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 80 */
elessair 0:f269e3021894 81 virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 /** Enable or disable DHCP on the network
elessair 0:f269e3021894 84 *
elessair 0:f269e3021894 85 * Enables DHCP on connecting the network. Defaults to enabled unless
elessair 0:f269e3021894 86 * a static IP address has been assigned. Requires that the network is
elessair 0:f269e3021894 87 * disconnected.
elessair 0:f269e3021894 88 *
elessair 0:f269e3021894 89 * @param dhcp True to enable DHCP
elessair 0:f269e3021894 90 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 91 */
elessair 0:f269e3021894 92 virtual int set_dhcp(bool dhcp);
elessair 0:f269e3021894 93
elessair 0:f269e3021894 94 /** Start the interface
elessair 0:f269e3021894 95 *
elessair 0:f269e3021894 96 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 97 */
elessair 0:f269e3021894 98 virtual int connect() = 0;
elessair 0:f269e3021894 99
elessair 0:f269e3021894 100 /** Stop the interface
elessair 0:f269e3021894 101 *
elessair 0:f269e3021894 102 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 103 */
elessair 0:f269e3021894 104 virtual int disconnect() = 0;
elessair 0:f269e3021894 105
elessair 0:f269e3021894 106 /** Translates a hostname to an IP address
elessair 0:f269e3021894 107 *
elessair 0:f269e3021894 108 * The hostname may be either a domain name or an IP address. If the
elessair 0:f269e3021894 109 * hostname is an IP address, no network transactions will be performed.
elessair 0:f269e3021894 110 *
elessair 0:f269e3021894 111 * If no stack-specific DNS resolution is provided, the hostname
elessair 0:f269e3021894 112 * will be resolve using a UDP socket on the stack.
elessair 0:f269e3021894 113 *
elessair 0:f269e3021894 114 * @param address Destination for the host SocketAddress
elessair 0:f269e3021894 115 * @param host Hostname to resolve
elessair 0:f269e3021894 116 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 117 */
elessair 0:f269e3021894 118 virtual int gethostbyname(const char *host, SocketAddress *address);
elessair 0:f269e3021894 119
elessair 0:f269e3021894 120 /** Translates a hostname to an IP address with specific version
elessair 0:f269e3021894 121 *
elessair 0:f269e3021894 122 * The hostname may be either a domain name or an IP address. If the
elessair 0:f269e3021894 123 * hostname is an IP address, no network transactions will be performed.
elessair 0:f269e3021894 124 *
elessair 0:f269e3021894 125 * If no stack-specific DNS resolution is provided, the hostname
elessair 0:f269e3021894 126 * will be resolve using a UDP socket on the stack.
elessair 0:f269e3021894 127 *
elessair 0:f269e3021894 128 * @param address Destination for the host SocketAddress
elessair 0:f269e3021894 129 * @param host Hostname to resolve
elessair 0:f269e3021894 130 * @param version IP version of address to resolve
elessair 0:f269e3021894 131 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 132 */
elessair 0:f269e3021894 133 virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version);
elessair 0:f269e3021894 134
elessair 0:f269e3021894 135 /** Add a domain name server to list of servers to query
elessair 0:f269e3021894 136 *
elessair 0:f269e3021894 137 * @param addr Destination for the host address
elessair 0:f269e3021894 138 * @return 0 on success, negative error code on failure
elessair 0:f269e3021894 139 */
elessair 0:f269e3021894 140 virtual int add_dns_server(const SocketAddress &address);
elessair 0:f269e3021894 141
elessair 0:f269e3021894 142 protected:
elessair 0:f269e3021894 143 friend class Socket;
elessair 0:f269e3021894 144 friend class UDPSocket;
elessair 0:f269e3021894 145 friend class TCPSocket;
elessair 0:f269e3021894 146 friend class TCPServer;
elessair 0:f269e3021894 147 friend class SocketAddress;
elessair 0:f269e3021894 148 template <typename IF>
elessair 0:f269e3021894 149 friend NetworkStack *nsapi_create_stack(IF *iface);
elessair 0:f269e3021894 150
elessair 0:f269e3021894 151 /** Provide access to the NetworkStack object
elessair 0:f269e3021894 152 *
elessair 0:f269e3021894 153 * @return The underlying NetworkStack object
elessair 0:f269e3021894 154 */
elessair 0:f269e3021894 155 virtual NetworkStack *get_stack() = 0;
elessair 0:f269e3021894 156 };
elessair 0:f269e3021894 157
elessair 0:f269e3021894 158
elessair 0:f269e3021894 159 #endif
elessair 0:f269e3021894 160
elessair 0:f269e3021894 161 /** @}*/